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
Kazuhiko Shiozaki
gitlab-ce
Commits
48f741ee
Commit
48f741ee
authored
Jan 24, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MergeRequests services
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
d1d13856
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
31 deletions
+90
-31
app/models/merge_request.rb
app/models/merge_request.rb
+11
-13
app/models/project.rb
app/models/project.rb
+1
-1
app/observers/merge_request_observer.rb
app/observers/merge_request_observer.rb
+0
-17
app/services/merge_requests/auto_merge_service.rb
app/services/merge_requests/auto_merge_service.rb
+30
-0
app/services/merge_requests/base_merge_service.rb
app/services/merge_requests/base_merge_service.rb
+26
-0
app/services/merge_requests/merge_service.rb
app/services/merge_requests/merge_service.rb
+22
-0
No files found.
app/models/merge_request.rb
View file @
48f741ee
...
...
@@ -50,17 +50,26 @@ class MergeRequest < ActiveRecord::Base
end
event
:merge
do
transition
[
:reopened
,
:opened
]
=>
:merged
transition
[
:reopened
,
:opened
,
:locked
]
=>
:merged
end
event
:reopen
do
transition
closed: :reopened
end
event
:lock
do
transition
[
:reopened
,
:opened
]
=>
:locked
end
event
:unlock
do
transition
locked: :reopened
end
state
:opened
state
:reopened
state
:closed
state
:merged
state
:locked
end
state_machine
:merge_status
,
initial: :unchecked
do
...
...
@@ -136,19 +145,8 @@ class MergeRequest < ActiveRecord::Base
self
.
target_project
.
events
.
where
(
target_id:
self
.
id
,
target_type:
"MergeRequest"
,
action:
Event
::
CLOSED
).
last
end
def
merge!
(
user_id
)
self
.
author_id_of_changes
=
user_id
self
.
merge
end
def
automerge!
(
current_user
,
commit_message
=
nil
)
if
Gitlab
::
Satellite
::
MergeAction
.
new
(
current_user
,
self
).
merge!
(
commit_message
)
self
.
merge!
(
current_user
.
id
)
true
end
rescue
mark_as_unmergeable
false
MergeRequests
::
AutoMergeService
.
new
.
execute
(
self
,
current_user
,
commit_message
)
end
def
mr_and_commit_notes
...
...
app/models/project.rb
View file @
48f741ee
...
...
@@ -350,7 +350,7 @@ class Project < ActiveRecord::Base
# Close merge requests
mrs
=
self
.
merge_requests
.
opened
.
where
(
target_branch:
branch_name
).
to_a
mrs
=
mrs
.
select
(
&
:last_commit
).
select
{
|
mr
|
c_ids
.
include?
(
mr
.
last_commit
.
id
)
}
mrs
.
each
{
|
merge_request
|
merge_request
.
merge!
(
user
.
id
)
}
mrs
.
each
{
|
merge_request
|
MergeRequests
::
MergeService
.
new
.
execute
(
merge_request
,
user
,
nil
)
}
true
end
...
...
app/observers/merge_request_observer.rb
View file @
48f741ee
...
...
@@ -18,23 +18,6 @@ class MergeRequestObserver < ActivityObserver
execute_hooks
(
merge_request
)
end
def
after_merge
(
merge_request
,
transition
)
notification
.
merge_mr
(
merge_request
)
# Since MR can be merged via sidekiq
# to prevent event duplication do this check
return
true
if
merge_request
.
merge_event
Event
.
create
(
project:
merge_request
.
target_project
,
target_id:
merge_request
.
id
,
target_type:
merge_request
.
class
.
name
,
action:
Event
::
MERGED
,
author_id:
merge_request
.
author_id_of_changes
)
execute_hooks
(
merge_request
)
end
def
after_reopen
(
merge_request
,
transition
)
create_event
(
merge_request
,
Event
::
REOPENED
)
create_note
(
merge_request
)
...
...
app/services/merge_requests/auto_merge_service.rb
0 → 100644
View file @
48f741ee
module
MergeRequests
# AutoMergeService class
#
# Do git merge in satellite and in case of success
# mark merge request as merged and execute all hooks and notifications
# Called when you do merge via GitLab UI
class
AutoMergeService
<
BaseMergeService
def
execute
(
merge_request
,
current_user
,
commit_message
)
merge_request
.
lock
if
Gitlab
::
Satellite
::
MergeAction
.
new
(
current_user
,
merge_request
).
merge!
(
commit_message
)
merge_request
.
author_id_of_changes
=
current_user
.
id
merge_request
.
merge
notification
.
merge_mr
(
merge_request
)
create_merge_event
(
merge_request
)
execute_project_hooks
(
merge_request
)
true
else
merge_request
.
unlock
false
end
rescue
merge_request
.
unlock
if
merge_request
.
locked?
merge_request
.
mark_as_unmergeable
false
end
end
end
app/services/merge_requests/base_merge_service.rb
0 → 100644
View file @
48f741ee
module
MergeRequests
class
BaseMergeService
private
def
notification
NotificationService
.
new
end
def
create_merge_event
(
merge_request
)
Event
.
create
(
project:
merge_request
.
target_project
,
target_id:
merge_request
.
id
,
target_type:
merge_request
.
class
.
name
,
action:
Event
::
MERGED
,
author_id:
merge_request
.
author_id_of_changes
)
end
def
execute_project_hooks
(
merge_request
)
if
merge_request
.
project
merge_request
.
project
.
execute_hooks
(
merge_request
.
to_hook_data
,
:merge_request_hooks
)
end
end
end
end
app/services/merge_requests/merge_service.rb
0 → 100644
View file @
48f741ee
module
MergeRequests
# MergeService class
#
# Mark existing merge request as merged
# and execute all hooks and notifications
# Called when you do merge via command line and push code
# to target branch
class
MergeService
<
BaseMergeService
def
execute
(
merge_request
,
current_user
,
commit_message
)
merge_request
.
author_id_of_changes
=
current_user
.
id
merge_request
.
merge
notification
.
merge_mr
(
merge_request
)
create_merge_event
(
merge_request
)
execute_project_hooks
(
merge_request
)
true
rescue
false
end
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