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
Jérome Perrin
gitlab-ce
Commits
21724407
Commit
21724407
authored
Oct 04, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move MWBS trigger from build to pipeline event
parent
0bbeff3d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
28 deletions
+26
-28
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+9
-7
app/models/commit_status.rb
app/models/commit_status.rb
+0
-4
app/services/merge_requests/add_todo_when_build_fails_service.rb
...vices/merge_requests/add_todo_when_build_fails_service.rb
+2
-2
app/services/merge_requests/base_service.rb
app/services/merge_requests/base_service.rb
+10
-11
app/services/merge_requests/merge_when_build_succeeds_service.rb
...vices/merge_requests/merge_when_build_succeeds_service.rb
+5
-4
No files found.
app/models/ci/pipeline.rb
View file @
21724407
...
@@ -56,6 +56,10 @@ module Ci
...
@@ -56,6 +56,10 @@ module Ci
pipeline
.
finished_at
=
Time
.
now
pipeline
.
finished_at
=
Time
.
now
end
end
before_transition
do
|
pipeline
|
pipeline
.
update_duration
end
after_transition
[
:created
,
:pending
]
=>
:running
do
|
pipeline
|
after_transition
[
:created
,
:pending
]
=>
:running
do
|
pipeline
|
MergeRequest
::
Metrics
.
where
(
merge_request_id:
pipeline
.
merge_requests
.
map
(
&
:id
)).
MergeRequest
::
Metrics
.
where
(
merge_request_id:
pipeline
.
merge_requests
.
map
(
&
:id
)).
update_all
(
latest_build_started_at:
pipeline
.
started_at
,
latest_build_finished_at:
nil
)
update_all
(
latest_build_started_at:
pipeline
.
started_at
,
latest_build_finished_at:
nil
)
...
@@ -66,8 +70,8 @@ module Ci
...
@@ -66,8 +70,8 @@ module Ci
update_all
(
latest_build_finished_at:
pipeline
.
finished_at
)
update_all
(
latest_build_finished_at:
pipeline
.
finished_at
)
end
end
before_transition
do
|
pipeline
|
after_transition
[
:created
,
:pending
,
:running
]
=>
:success
do
|
pipeline
|
pipeline
.
update_duration
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
pipeline
.
project
,
nil
).
trigger
(
pipeline
)
end
end
after_transition
do
|
pipeline
,
transition
|
after_transition
do
|
pipeline
,
transition
|
...
@@ -292,11 +296,9 @@ module Ci
...
@@ -292,11 +296,9 @@ module Ci
# Merge requests for which the current pipeline is running against
# Merge requests for which the current pipeline is running against
# the merge request's latest commit.
# the merge request's latest commit.
def
merge_requests
def
merge_requests
@merge_requests
||=
@merge_requests
||=
project
.
merge_requests
begin
.
where
(
source_branch:
self
.
ref
)
project
.
merge_requests
.
where
(
source_branch:
self
.
ref
).
.
select
{
|
merge_request
|
merge_request
.
pipeline
.
try
(
:id
)
==
self
.
id
}
select
{
|
merge_request
|
merge_request
.
pipeline
.
try
(
:id
)
==
self
.
id
}
end
end
end
private
private
...
...
app/models/commit_status.rb
View file @
21724407
...
@@ -98,10 +98,6 @@ class CommitStatus < ActiveRecord::Base
...
@@ -98,10 +98,6 @@ class CommitStatus < ActiveRecord::Base
true
true
end
end
after_transition
[
:created
,
:pending
,
:running
]
=>
:success
do
|
commit_status
|
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
commit_status
.
pipeline
.
project
,
nil
).
trigger
(
commit_status
)
end
after_transition
any
=>
:failed
do
|
commit_status
|
after_transition
any
=>
:failed
do
|
commit_status
|
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
commit_status
.
pipeline
.
project
,
nil
).
execute
(
commit_status
)
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
commit_status
.
pipeline
.
project
,
nil
).
execute
(
commit_status
)
end
end
...
...
app/services/merge_requests/add_todo_when_build_fails_service.rb
View file @
21724407
...
@@ -2,14 +2,14 @@ module MergeRequests
...
@@ -2,14 +2,14 @@ module MergeRequests
class
AddTodoWhenBuildFailsService
<
MergeRequests
::
BaseService
class
AddTodoWhenBuildFailsService
<
MergeRequests
::
BaseService
# Adds a todo to the parent merge_request when a CI build fails
# Adds a todo to the parent merge_request when a CI build fails
def
execute
(
commit_status
)
def
execute
(
commit_status
)
each_merge_request
(
commit_status
)
do
|
merge_request
|
commit_status_merge_requests
(
commit_status
)
do
|
merge_request
|
todo_service
.
merge_request_build_failed
(
merge_request
)
todo_service
.
merge_request_build_failed
(
merge_request
)
end
end
end
end
# Closes any pending build failed todos for the parent MRs when a build is retried
# Closes any pending build failed todos for the parent MRs when a build is retried
def
close
(
commit_status
)
def
close
(
commit_status
)
each_merge_request
(
commit_status
)
do
|
merge_request
|
commit_status_merge_requests
(
commit_status
)
do
|
merge_request
|
todo_service
.
merge_request_build_retried
(
merge_request
)
todo_service
.
merge_request_build_retried
(
merge_request
)
end
end
end
end
...
...
app/services/merge_requests/base_service.rb
View file @
21724407
...
@@ -42,11 +42,9 @@ module MergeRequests
...
@@ -42,11 +42,9 @@ module MergeRequests
super
(
:merge_request
)
super
(
:merge_request
)
end
end
def
merge_request_from
(
commit_status
)
def
merge_requests_for
(
branches
,
sha
)
branches
=
commit_status
.
ref
# This is for ref-less builds
# This is for ref-less builds
branches
||=
@project
.
repository
.
branch_names_contains
(
commit_status
.
sha
)
branches
||=
@project
.
repository
.
branch_names_contains
(
sha
)
return
[]
if
branches
.
blank?
return
[]
if
branches
.
blank?
...
@@ -56,14 +54,15 @@ module MergeRequests
...
@@ -56,14 +54,15 @@ module MergeRequests
merge_requests
.
uniq
.
select
(
&
:source_project
)
merge_requests
.
uniq
.
select
(
&
:source_project
)
end
end
def
each_merge_request
(
commit_status
)
def
pipeline_merge_requests
(
pipeline
)
merge_request_from
(
commit_status
).
each
do
|
merge_request
|
merge_requests_for
(
pipeline
.
ref
,
pipeline
.
sha
).
each
do
|
merge_request
|
pipeline
=
merge_request
.
pipeline
yield
merge_request
end
next
unless
pipeline
end
next
unless
pipeline
.
sha
==
commit_status
.
sha
yield
merge_request
,
pipeline
def
commit_status_merge_requests
(
commit_status
)
merge_requests_for
(
commit_status
.
ref
,
commit_status
.
sha
).
each
do
|
merge_request
|
yield
merge_request
end
end
end
end
end
end
...
...
app/services/merge_requests/merge_when_build_succeeds_service.rb
View file @
21724407
...
@@ -18,12 +18,13 @@ module MergeRequests
...
@@ -18,12 +18,13 @@ module MergeRequests
merge_request
.
save
merge_request
.
save
end
end
# Triggers the automatic merge of merge_request once the build succeeds
# Triggers the automatic merge of merge_request once the pipeline succeeds
def
trigger
(
commit_status
)
def
trigger
(
pipeline
)
each_merge_request
(
commit_status
)
do
|
merge_request
,
pipeline
|
return
unless
pipeline
.
success?
pipeline_merge_requests
(
pipeline
)
do
|
merge_request
|
next
unless
merge_request
.
merge_when_build_succeeds?
next
unless
merge_request
.
merge_when_build_succeeds?
next
unless
merge_request
.
mergeable?
next
unless
merge_request
.
mergeable?
next
unless
pipeline
.
success?
MergeWorker
.
perform_async
(
merge_request
.
id
,
merge_request
.
merge_user_id
,
merge_request
.
merge_params
)
MergeWorker
.
perform_async
(
merge_request
.
id
,
merge_request
.
merge_user_id
,
merge_request
.
merge_params
)
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