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
Boxiang Sun
gitlab-ce
Commits
5cf3ff27
Commit
5cf3ff27
authored
Dec 01, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use actual head pipeline on merge request serializer
parent
f586dc07
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
21 deletions
+33
-21
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+3
-3
app/models/merge_request.rb
app/models/merge_request.rb
+3
-3
app/presenters/merge_request_presenter.rb
app/presenters/merge_request_presenter.rb
+1
-1
app/serializers/merge_request_entity.rb
app/serializers/merge_request_entity.rb
+1
-1
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+4
-4
spec/serializers/merge_request_entity_spec.rb
spec/serializers/merge_request_entity_spec.rb
+21
-9
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
5cf3ff27
...
@@ -283,15 +283,15 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
...
@@ -283,15 +283,15 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
@merge_request
.
update
(
merge_error:
nil
)
@merge_request
.
update
(
merge_error:
nil
)
if
params
[
:merge_when_pipeline_succeeds
].
present?
if
params
[
:merge_when_pipeline_succeeds
].
present?
return
:failed
unless
@merge_request
.
current
_head_pipeline
return
:failed
unless
@merge_request
.
actual
_head_pipeline
if
@merge_request
.
current
_head_pipeline
.
active?
if
@merge_request
.
actual
_head_pipeline
.
active?
::
MergeRequests
::
MergeWhenPipelineSucceedsService
::
MergeRequests
::
MergeWhenPipelineSucceedsService
.
new
(
@project
,
current_user
,
merge_params
)
.
new
(
@project
,
current_user
,
merge_params
)
.
execute
(
@merge_request
)
.
execute
(
@merge_request
)
:merge_when_pipeline_succeeds
:merge_when_pipeline_succeeds
elsif
@merge_request
.
current
_head_pipeline
.
success?
elsif
@merge_request
.
actual
_head_pipeline
.
success?
# This can be triggered when a user clicks the auto merge button while
# This can be triggered when a user clicks the auto merge button while
# the tests finish at about the same time
# the tests finish at about the same time
@merge_request
.
merge_async
(
current_user
.
id
,
params
)
@merge_request
.
merge_async
(
current_user
.
id
,
params
)
...
...
app/models/merge_request.rb
View file @
5cf3ff27
...
@@ -148,7 +148,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -148,7 +148,7 @@ class MergeRequest < ActiveRecord::Base
# Use this method whenever you need to make sure the head_pipeline is synced with the
# Use this method whenever you need to make sure the head_pipeline is synced with the
# branch head commit, for example checking if a merge request can be merged.
# branch head commit, for example checking if a merge request can be merged.
# For more information check: https://gitlab.com/gitlab-org/gitlab-ce/issues/40004
# For more information check: https://gitlab.com/gitlab-org/gitlab-ce/issues/40004
def
current
_head_pipeline
def
actual
_head_pipeline
head_pipeline
&
.
sha
==
diff_head_sha
?
head_pipeline
:
nil
head_pipeline
&
.
sha
==
diff_head_sha
?
head_pipeline
:
nil
end
end
...
@@ -831,7 +831,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -831,7 +831,7 @@ class MergeRequest < ActiveRecord::Base
return
true
unless
project
.
only_allow_merge_if_pipeline_succeeds?
return
true
unless
project
.
only_allow_merge_if_pipeline_succeeds?
return
true
unless
head_pipeline
return
true
unless
head_pipeline
current_head_pipeline
&
.
success?
||
current
_head_pipeline
&
.
skipped?
actual_head_pipeline
&
.
success?
||
actual
_head_pipeline
&
.
skipped?
end
end
def
environments_for
(
current_user
)
def
environments_for
(
current_user
)
...
@@ -1005,7 +1005,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -1005,7 +1005,7 @@ class MergeRequest < ActiveRecord::Base
return
true
if
autocomplete_precheck
return
true
if
autocomplete_precheck
return
false
unless
mergeable?
(
skip_ci_check:
true
)
return
false
unless
mergeable?
(
skip_ci_check:
true
)
return
false
if
current_head_pipeline
&&
!
(
current_head_pipeline
.
success?
||
current
_head_pipeline
.
active?
)
return
false
if
actual_head_pipeline
&&
!
(
actual_head_pipeline
.
success?
||
actual
_head_pipeline
.
active?
)
return
false
if
last_diff_sha
!=
diff_head_sha
return
false
if
last_diff_sha
!=
diff_head_sha
true
true
...
...
app/presenters/merge_request_presenter.rb
View file @
5cf3ff27
...
@@ -163,7 +163,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
...
@@ -163,7 +163,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
end
end
def
pipeline
def
pipeline
@pipeline
||=
head_pipeline
@pipeline
||=
actual_
head_pipeline
end
end
def
issues_sentence
(
project
,
issues
)
def
issues_sentence
(
project
,
issues
)
...
...
app/serializers/merge_request_entity.rb
View file @
5cf3ff27
...
@@ -33,7 +33,7 @@ class MergeRequestEntity < IssuableEntity
...
@@ -33,7 +33,7 @@ class MergeRequestEntity < IssuableEntity
end
end
expose
:merge_commit_message
expose
:merge_commit_message
expose
:head_pipeline
,
with:
PipelineDetailsEntity
,
as: :pipeline
expose
:
actual_
head_pipeline
,
with:
PipelineDetailsEntity
,
as: :pipeline
# Booleans
# Booleans
expose
:merge_ongoing?
,
as: :merge_ongoing
expose
:merge_ongoing?
,
as: :merge_ongoing
...
...
spec/models/merge_request_spec.rb
View file @
5cf3ff27
...
@@ -840,20 +840,20 @@ describe MergeRequest do
...
@@ -840,20 +840,20 @@ describe MergeRequest do
end
end
end
end
describe
'#
current
_head_pipeline'
do
describe
'#
actual
_head_pipeline'
do
it
'returns nil for MR with old pipeline'
do
it
'returns nil for MR with old pipeline'
do
pipeline
=
create
(
:ci_empty_pipeline
,
sha:
'notlatestsha'
)
pipeline
=
create
(
:ci_empty_pipeline
,
sha:
'notlatestsha'
)
subject
.
update_attribute
(
:head_pipeline_id
,
pipeline
.
id
)
subject
.
update_attribute
(
:head_pipeline_id
,
pipeline
.
id
)
expect
(
subject
.
current
_head_pipeline
).
to
be_nil
expect
(
subject
.
actual
_head_pipeline
).
to
be_nil
end
end
it
'returns the pipeline for MR with recent pipeline'
do
it
'returns the pipeline for MR with recent pipeline'
do
pipeline
=
create
(
:ci_empty_pipeline
,
sha:
'lastsha'
)
pipeline
=
create
(
:ci_empty_pipeline
,
sha:
'lastsha'
)
subject
.
update_attribute
(
:head_pipeline_id
,
pipeline
.
id
)
subject
.
update_attribute
(
:head_pipeline_id
,
pipeline
.
id
)
expect
(
subject
.
current
_head_pipeline
).
to
eq
(
subject
.
head_pipeline
)
expect
(
subject
.
actual
_head_pipeline
).
to
eq
(
subject
.
head_pipeline
)
expect
(
subject
.
current
_head_pipeline
).
to
eq
(
pipeline
)
expect
(
subject
.
actual
_head_pipeline
).
to
eq
(
pipeline
)
end
end
end
end
end
end
...
...
spec/serializers/merge_request_entity_spec.rb
View file @
5cf3ff27
...
@@ -5,23 +5,35 @@ describe MergeRequestEntity do
...
@@ -5,23 +5,35 @@ describe MergeRequestEntity do
let
(
:resource
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:resource
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:request
)
{
double
(
'request'
,
current_user:
user
)
}
let
(
:request
)
{
double
(
'request'
,
current_user:
user
,
project:
project
)
}
subject
do
subject
do
described_class
.
new
(
resource
,
request:
request
).
as_json
described_class
.
new
(
resource
,
request:
request
).
as_json
end
end
it
'includes pipeline'
do
describe
'pipeline'
do
req
=
double
(
'request'
,
current_user:
user
)
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
project:
project
,
ref:
resource
.
source_branch
,
sha:
resource
.
source_branch_sha
,
head_pipeline_of:
resource
)
}
pipeline
=
build_stubbed
(
:ci_pipeline
)
allow
(
resource
).
to
receive
(
:head_pipeline
).
and_return
(
pipeline
)
context
'when is up to date'
do
let
(
:req
)
{
double
(
'request'
,
current_user:
user
,
project:
project
)
}
it
'returns pipeline'
do
pipeline_payload
=
PipelineDetailsEntity
pipeline_payload
=
PipelineDetailsEntity
.
represent
(
pipeline
,
request:
req
)
.
represent
(
pipeline
,
request:
req
)
.
as_json
.
as_json
expect
(
subject
[
:pipeline
]).
to
eq
(
pipeline_payload
)
expect
(
subject
[
:pipeline
]).
to
eq
(
pipeline_payload
)
end
end
end
context
'when is not up to date'
do
it
'returns nil'
do
pipeline
.
update
(
sha:
"not up to date"
)
expect
(
subject
[
:pipeline
]).
to
be_nil
end
end
end
it
'includes issues_links'
do
it
'includes issues_links'
do
issues_links
=
subject
[
:issues_links
]
issues_links
=
subject
[
:issues_links
]
...
...
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