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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
94be44c5
Commit
94be44c5
authored
Jun 01, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix race condition between pipeline creation and MR diff_head_sha update
parent
42c13b26
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
14 deletions
+9
-14
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+3
-6
app/services/merge_requests/create_service.rb
app/services/merge_requests/create_service.rb
+3
-6
spec/services/ci/create_pipeline_service_spec.rb
spec/services/ci/create_pipeline_service_spec.rb
+3
-2
No files found.
app/services/ci/create_pipeline_service.rb
View file @
94be44c5
...
...
@@ -63,13 +63,10 @@ module Ci
private
def
update_merge_requests_head_pipeline
merge_requests
=
MergeRequest
.
where
(
source_branch:
@pipeline
.
ref
,
source_project:
@pipeline
.
project
)
return
unless
pipeline
.
latest?
merge_requests
=
merge_requests
.
select
do
|
mr
|
mr
.
diff_head_sha
==
@pipeline
.
sha
end
MergeRequest
.
where
(
id:
merge_requests
).
update_all
(
head_pipeline_id:
@pipeline
.
id
)
MergeRequest
.
where
(
source_project:
@pipeline
.
project
,
source_branch:
@pipeline
.
ref
).
update_all
(
head_pipeline_id:
@pipeline
.
id
)
end
def
skip_ci?
...
...
app/services/merge_requests/create_service.rb
View file @
94be44c5
...
...
@@ -30,15 +30,12 @@ module MergeRequests
def
head_pipeline_for
(
merge_request
)
return
unless
merge_request
.
source_project
sha
=
merge_request
.
source_branch_head
&
.
id
sha
=
merge_request
.
source_branch_sha
return
unless
sha
pipelines
=
Ci
::
Pipeline
.
where
(
ref:
merge_request
.
source_branch
,
project_id:
merge_request
.
source_project
.
id
,
sha:
sha
).
order
(
id: :desc
)
pipelines
=
merge_request
.
source_project
.
pipelines
.
where
(
ref:
merge_request
.
source_branch
,
sha:
sha
)
pipelines
.
first
pipelines
.
order
(
id: :desc
).
first
end
end
end
spec/services/ci/create_pipeline_service_spec.rb
View file @
94be44c5
...
...
@@ -72,10 +72,11 @@ describe Ci::CreatePipelineService, services: true do
end
end
context
'when
merge request head commit sha does not match pipeline sha
'
do
context
'when
the pipeline is not the latest for the branch
'
do
it
'does not update merge request head pipeline'
do
merge_request
=
create
(
:merge_request
,
source_branch:
'master'
,
target_branch:
"branch_1"
,
source_project:
project
)
allow_any_instance_of
(
MergeRequestDiff
).
to
receive
(
:head_commit
).
and_return
(
double
(
id:
1234
))
allow_any_instance_of
(
Ci
::
Pipeline
).
to
receive
(
:latest?
).
and_return
(
false
)
pipeline
...
...
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