Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
dcbb875c
Commit
dcbb875c
authored
Apr 22, 2012
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fast automerge: base implementation
parent
ae565d24
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
11 deletions
+36
-11
app/models/project/hooks_trait.rb
app/models/project/hooks_trait.rb
+3
-0
app/models/project/repository_trait.rb
app/models/project/repository_trait.rb
+17
-0
lib/gitlab_merge.rb
lib/gitlab_merge.rb
+9
-11
lib/tasks/gitlab/enable_automerge.rake
lib/tasks/gitlab/enable_automerge.rake
+7
-0
No files found.
app/models/project/hooks_trait.rb
View file @
dcbb875c
...
...
@@ -101,6 +101,9 @@ module Project::HooksTrait
# Execute web hooks
self
.
execute_web_hooks
(
oldrev
,
newrev
,
ref
,
user
)
# Create repo satellite
self
.
create_repo_satellite
unless
self
.
satellite_exists?
end
end
end
app/models/project/repository_trait.rb
View file @
dcbb875c
...
...
@@ -37,6 +37,23 @@ module Project::RepositoryTrait
end
end
def
path_to_repo_satellite
File
.
join
(
Rails
.
root
,
"tmp"
,
"repo_satellites"
,
self
.
path
)
end
def
satellite_exists?
File
.
exist?
path_to_repo_satellite
end
def
create_repo_satellite
`git clone
#{
url_to_repo
}
#{
path_to_repo_satellite
}
`
Dir
.
chdir
(
path_to_repo_satellite
)
do
primary_branch
=
Grit
::
Repo
.
new
(
"."
).
heads
.
first
.
name
#usually it`s master
`git checkout -b __parking_branch`
`git branch -D
#{
primary_branch
}
`
end
end
def
write_hook
(
name
,
content
)
hook_file
=
File
.
join
(
path_to_repo
,
'hooks'
,
name
)
...
...
lib/gitlab_merge.rb
View file @
dcbb875c
class
GitlabMerge
attr_accessor
:project
,
:merge_
path
,
:merge_
request
,
:user
attr_accessor
:project
,
:merge_request
,
:user
def
initialize
(
merge_request
,
user
)
self
.
user
=
user
self
.
merge_request
=
merge_request
self
.
project
=
merge_request
.
project
self
.
merge_path
=
File
.
join
(
Rails
.
root
,
"tmp"
,
"merge_repo"
,
project
.
path
,
merge_request
.
id
.
to_s
)
FileUtils
.
rm_rf
(
merge_path
)
FileUtils
.
mkdir_p
merge_path
end
def
can_be_merged?
p
ull
do
|
repo
,
output
|
p
rocess
do
|
repo
,
output
|
!
(
output
=~
/Automatic merge failed/
)
end
end
def
merge
p
ull
do
|
repo
,
output
|
p
rocess
do
|
repo
,
output
|
if
output
=~
/Automatic merge failed/
false
else
...
...
@@ -27,19 +24,20 @@ class GitlabMerge
end
end
def
p
ull
def
p
rocess
Grit
::
Git
.
with_timeout
(
30
.
seconds
)
do
File
.
open
(
File
.
join
(
Rails
.
root
,
"tmp"
,
"merge_repo"
,
"
#{
project
.
path
}
.lock"
),
"w+"
)
do
|
f
|
f
.
flock
(
File
::
LOCK_EX
)
self
.
project
.
repo
.
git
.
clone
({
:branch
=>
merge_request
.
target_branch
},
project
.
url_to_repo
,
merge_path
)
unless
File
.
exist?
(
self
.
merge_path
)
raise
"Gitlab user do not have access to repo. You should run: rake gitlab_enable_automerge"
unless
project
.
satellite_exists?
raise
"You should run: rake gitlab_enable_automerge"
end
Dir
.
chdir
(
merge_path
)
do
Dir
.
chdir
(
project
.
path_to_repo_satellite
)
do
merge_repo
=
Grit
::
Repo
.
new
(
'.'
)
merge_repo
.
git
.
sh
"git fetch origin"
merge_repo
.
git
.
sh
"git config user.name
\"
#{
user
.
name
}
\"
"
merge_repo
.
git
.
sh
"git config user.email
\"
#{
user
.
email
}
\"
"
merge_repo
.
git
.
sh
"git checkout -b
#{
merge_request
.
target_branch
}
origin/
#{
merge_request
.
target_branch
}
"
output
=
merge_repo
.
git
.
pull
({},
"--no-ff"
,
"origin"
,
merge_request
.
source_branch
)
yield
(
merge_repo
,
output
)
end
...
...
lib/tasks/gitlab/enable_automerge.rake
View file @
dcbb875c
...
...
@@ -6,6 +6,13 @@ namespace :gitlab do
git
.
admin_all_repo
end
Project
.
find_each
do
|
project
|
if
project
.
repo_exists?
&&
!
project
.
satellite_exists?
puts
"Creating satellite for
#{
project
.
name
}
..."
.
green
project
.
create_repo_satellite
end
end
puts
"Done!"
.
green
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment