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
Léo-Paul Géneau
gitlab-ce
Commits
a49e9949
Commit
a49e9949
authored
Nov 28, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename `MergeRequest#pipeline` to `head_pipeline`
parent
b8f9949a
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
56 additions
and
39 deletions
+56
-39
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+8
-7
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+1
-1
app/models/merge_request.rb
app/models/merge_request.rb
+3
-3
app/services/merge_requests/base_service.rb
app/services/merge_requests/base_service.rb
+2
-2
app/views/projects/issues/_merge_requests.html.haml
app/views/projects/issues/_merge_requests.html.haml
+3
-3
app/views/projects/merge_requests/_merge_request.html.haml
app/views/projects/merge_requests/_merge_request.html.haml
+2
-2
app/views/projects/merge_requests/widget/_show.html.haml
app/views/projects/merge_requests/widget/_show.html.haml
+1
-1
lib/api/merge_requests.rb
lib/api/merge_requests.rb
+1
-1
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+9
-9
spec/requests/api/merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+1
-1
spec/services/merge_requests/add_todo_when_build_fails_service_spec.rb
.../merge_requests/add_todo_when_build_fails_service_spec.rb
+9
-3
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
.../merge_requests/merge_when_build_succeeds_service_spec.rb
+16
-6
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
a49e9949
...
...
@@ -325,16 +325,16 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_request
.
update
(
merge_error:
nil
)
if
params
[
:merge_when_build_succeeds
].
present?
unless
@merge_request
.
pipeline
unless
@merge_request
.
head_
pipeline
@status
=
:failed
return
end
if
@merge_request
.
pipeline
.
active?
if
@merge_request
.
head_
pipeline
.
active?
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
@project
,
current_user
,
merge_params
)
.
execute
(
@merge_request
)
@status
=
:merge_when_build_succeeds
elsif
@merge_request
.
pipeline
.
success?
elsif
@merge_request
.
head_
pipeline
.
success?
# This can be triggered when a user clicks the auto merge button while
# the tests finish at about the same time
MergeWorker
.
perform_async
(
@merge_request
.
id
,
current_user
.
id
,
params
)
...
...
@@ -398,7 +398,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
def
ci_status
pipeline
=
@merge_request
.
pipeline
pipeline
=
@merge_request
.
head_pipeline
if
pipeline
status
=
pipeline
.
status
coverage
=
pipeline
.
try
(
:coverage
)
...
...
@@ -534,7 +535,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
def
define_widget_vars
@pipeline
=
@merge_request
.
pipeline
@pipeline
=
@merge_request
.
head_
pipeline
end
def
define_commit_vars
...
...
@@ -563,7 +564,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def
define_pipelines_vars
@pipelines
=
@merge_request
.
all_pipelines
@pipeline
=
@merge_request
.
pipeline
@pipeline
=
@merge_request
.
head_
pipeline
@statuses_count
=
@pipeline
.
present?
?
@pipeline
.
statuses
.
relevant
.
count
:
0
end
...
...
@@ -631,7 +632,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def
merge_when_build_succeeds_active?
params
[
:merge_when_build_succeeds
].
present?
&&
@merge_request
.
pipeline
&&
@merge_request
.
pipeline
.
active?
@merge_request
.
head_pipeline
&&
@merge_request
.
head_
pipeline
.
active?
end
def
build_merge_request
...
...
app/models/ci/pipeline.rb
View file @
a49e9949
...
...
@@ -317,7 +317,7 @@ module Ci
def
merge_requests
@merge_requests
||=
project
.
merge_requests
.
where
(
source_branch:
self
.
ref
)
.
select
{
|
merge_request
|
merge_request
.
pipeline
.
try
(
:id
)
==
self
.
id
}
.
select
{
|
merge_request
|
merge_request
.
head_
pipeline
.
try
(
:id
)
==
self
.
id
}
end
private
...
...
app/models/merge_request.rb
View file @
a49e9949
...
...
@@ -678,7 +678,7 @@ class MergeRequest < ActiveRecord::Base
def
mergeable_ci_state?
return
true
unless
project
.
only_allow_merge_if_build_succeeds?
!
pipeline
||
pipeline
.
success?
||
pipeline
.
skipped?
!
head_pipeline
||
head_pipeline
.
success?
||
head_
pipeline
.
skipped?
end
def
environments
...
...
@@ -774,10 +774,10 @@ class MergeRequest < ActiveRecord::Base
commits
.
map
(
&
:sha
)
end
def
pipeline
def
head_
pipeline
return
unless
diff_head_sha
&&
source_project
@pipeline
||=
source_project
.
pipeline_for
(
source_branch
,
diff_head_sha
)
@
head_
pipeline
||=
source_project
.
pipeline_for
(
source_branch
,
diff_head_sha
)
end
def
all_pipelines
...
...
app/services/merge_requests/base_service.rb
View file @
a49e9949
...
...
@@ -55,7 +55,7 @@ module MergeRequests
def
pipeline_merge_requests
(
pipeline
)
merge_requests_for
(
pipeline
.
ref
).
each
do
|
merge_request
|
next
unless
pipeline
==
merge_request
.
pipeline
next
unless
pipeline
==
merge_request
.
head_
pipeline
yield
merge_request
end
...
...
@@ -63,7 +63,7 @@ module MergeRequests
def
commit_status_merge_requests
(
commit_status
)
merge_requests_for
(
commit_status
.
ref
).
each
do
|
merge_request
|
pipeline
=
merge_request
.
pipeline
pipeline
=
merge_request
.
head_
pipeline
next
unless
pipeline
next
unless
pipeline
.
sha
==
commit_status
.
sha
...
...
app/views/projects/issues/_merge_requests.html.haml
View file @
a49e9949
...
...
@@ -2,12 +2,12 @@
%h2
.merge-requests-title
=
pluralize
(
@merge_requests
.
count
,
'Related Merge Request'
)
%ul
.unstyled-list.related-merge-requests
-
has_any_ci
=
@merge_requests
.
any?
(
&
:pipeline
)
-
has_any_ci
=
@merge_requests
.
any?
(
&
:
head_
pipeline
)
-
@merge_requests
.
each
do
|
merge_request
|
%li
%span
.merge-request-ci-status
-
if
merge_request
.
pipeline
=
render_pipeline_status
(
merge_request
.
pipeline
)
-
if
merge_request
.
head_
pipeline
=
render_pipeline_status
(
merge_request
.
head_
pipeline
)
-
elsif
has_any_ci
=
icon
(
'blank fw'
)
%span
.merge-request-id
...
...
app/views/projects/merge_requests/_merge_request.html.haml
View file @
a49e9949
...
...
@@ -15,9 +15,9 @@
=
icon
(
'ban'
)
CLOSED
-
if
merge_request
.
pipeline
-
if
merge_request
.
head_
pipeline
%li
=
render_pipeline_status
(
merge_request
.
pipeline
)
=
render_pipeline_status
(
merge_request
.
head_
pipeline
)
-
if
merge_request
.
open?
&&
merge_request
.
broken?
%li
...
...
app/views/projects/merge_requests/widget/_show.html.haml
View file @
a49e9949
...
...
@@ -14,7 +14,7 @@
ci_status_url
:
"
#{
ci_status_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
)
}
"
,
ci_environments_status_url
:
"
#{
ci_environments_status_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
)
}
"
,
gitlab_icon
:
"
#{
asset_path
'gitlab_logo.png'
}
"
,
ci_status
:
"
#{
@merge_request
.
pipeline
?
@merge_request
.
pipeline
.
status
:
''
}
"
,
ci_status
:
"
#{
@merge_request
.
head_pipeline
?
@merge_request
.
head_
pipeline
.
status
:
''
}
"
,
ci_message
:
{
normal
:
"
Build {{status}} for
\"
{{title}}
\"
"
,
preparing
:
"
{{status}} build for
\"
{{title}}
\"
"
...
...
lib/api/merge_requests.rb
View file @
a49e9949
...
...
@@ -192,7 +192,7 @@ module API
should_remove_source_branch:
params
[
:should_remove_source_branch
]
}
if
params
[
:merge_when_build_succeeds
]
&&
merge_request
.
pipeline
&&
merge_request
.
pipeline
.
active?
if
params
[
:merge_when_build_succeeds
]
&&
merge_request
.
head_pipeline
&&
merge_request
.
head_
pipeline
.
active?
::
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
merge_request
.
target_project
,
current_user
,
merge_params
).
execute
(
merge_request
)
else
...
...
spec/models/merge_request_spec.rb
View file @
a49e9949
...
...
@@ -570,7 +570,7 @@ describe MergeRequest, models: true do
end
end
describe
'#pipeline'
do
describe
'#
head_
pipeline'
do
describe
'when the source project exists'
do
it
'returns the latest pipeline'
do
pipeline
=
double
(
:ci_pipeline
,
ref:
'master'
)
...
...
@@ -581,7 +581,7 @@ describe MergeRequest, models: true do
with
(
'master'
,
'123abc'
).
and_return
(
pipeline
)
expect
(
subject
.
pipeline
).
to
eq
(
pipeline
)
expect
(
subject
.
head_
pipeline
).
to
eq
(
pipeline
)
end
end
...
...
@@ -589,7 +589,7 @@ describe MergeRequest, models: true do
it
'returns nil'
do
allow
(
subject
).
to
receive
(
:source_project
).
and_return
(
nil
)
expect
(
subject
.
pipeline
).
to
be_nil
expect
(
subject
.
head_
pipeline
).
to
be_nil
end
end
end
...
...
@@ -857,7 +857,7 @@ describe MergeRequest, models: true do
context
'and a failed pipeline is associated'
do
before
do
pipeline
.
update
(
status:
'failed'
)
allow
(
subject
).
to
receive
(
:pipeline
)
{
pipeline
}
allow
(
subject
).
to
receive
(
:
head_
pipeline
)
{
pipeline
}
end
it
{
expect
(
subject
.
mergeable_ci_state?
).
to
be_falsey
}
...
...
@@ -866,7 +866,7 @@ describe MergeRequest, models: true do
context
'and a successful pipeline is associated'
do
before
do
pipeline
.
update
(
status:
'success'
)
allow
(
subject
).
to
receive
(
:pipeline
)
{
pipeline
}
allow
(
subject
).
to
receive
(
:
head_
pipeline
)
{
pipeline
}
end
it
{
expect
(
subject
.
mergeable_ci_state?
).
to
be_truthy
}
...
...
@@ -875,7 +875,7 @@ describe MergeRequest, models: true do
context
'and a skipped pipeline is associated'
do
before
do
pipeline
.
update
(
status:
'skipped'
)
allow
(
subject
).
to
receive
(
:pipeline
)
{
pipeline
}
allow
(
subject
).
to
receive
(
:
head_
pipeline
)
{
pipeline
}
end
it
{
expect
(
subject
.
mergeable_ci_state?
).
to
be_truthy
}
...
...
@@ -883,7 +883,7 @@ describe MergeRequest, models: true do
context
'when no pipeline is associated'
do
before
do
allow
(
subject
).
to
receive
(
:pipeline
)
{
nil
}
allow
(
subject
).
to
receive
(
:
head_
pipeline
)
{
nil
}
end
it
{
expect
(
subject
.
mergeable_ci_state?
).
to
be_truthy
}
...
...
@@ -896,7 +896,7 @@ describe MergeRequest, models: true do
context
'and a failed pipeline is associated'
do
before
do
pipeline
.
statuses
<<
create
(
:commit_status
,
status:
'failed'
,
project:
project
)
allow
(
subject
).
to
receive
(
:pipeline
)
{
pipeline
}
allow
(
subject
).
to
receive
(
:
head_
pipeline
)
{
pipeline
}
end
it
{
expect
(
subject
.
mergeable_ci_state?
).
to
be_truthy
}
...
...
@@ -904,7 +904,7 @@ describe MergeRequest, models: true do
context
'when no pipeline is associated'
do
before
do
allow
(
subject
).
to
receive
(
:pipeline
)
{
nil
}
allow
(
subject
).
to
receive
(
:
head_
pipeline
)
{
nil
}
end
it
{
expect
(
subject
.
mergeable_ci_state?
).
to
be_truthy
}
...
...
spec/requests/api/merge_requests_spec.rb
View file @
a49e9949
...
...
@@ -466,7 +466,7 @@ describe API::API, api: true do
end
it
"enables merge when build succeeds if the ci is active"
do
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:pipeline
).
and_return
(
pipeline
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:
head_
pipeline
).
and_return
(
pipeline
)
allow
(
pipeline
).
to
receive
(
:active?
).
and_return
(
true
)
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/merge"
,
user
),
merge_when_build_succeeds:
true
...
...
spec/services/merge_requests/add_todo_when_build_fails_service_spec.rb
View file @
a49e9949
...
...
@@ -20,13 +20,19 @@ describe MergeRequests::AddTodoWhenBuildFailsService do
let
(
:todo_service
)
{
TodoService
.
new
}
let
(
:merge_request
)
do
create
(
:merge_request
,
merge_user:
user
,
source_branch:
'master'
,
target_branch:
'feature'
,
source_project:
project
,
target_project:
project
,
create
(
:merge_request
,
merge_user:
user
,
source_branch:
'master'
,
target_branch:
'feature'
,
source_project:
project
,
target_project:
project
,
state:
'opened'
)
end
before
do
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:pipeline
).
and_return
(
pipeline
)
allow_any_instance_of
(
MergeRequest
)
.
to
receive
(
:head_pipeline
)
.
and_return
(
pipeline
)
allow
(
service
).
to
receive
(
:todo_service
).
and_return
(
todo_service
)
end
...
...
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
View file @
a49e9949
...
...
@@ -21,7 +21,10 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
context
'first time enabling'
do
before
do
allow
(
merge_request
).
to
receive
(
:pipeline
).
and_return
(
pipeline
)
allow
(
merge_request
)
.
to
receive
(
:head_pipeline
)
.
and_return
(
pipeline
)
service
.
execute
(
merge_request
)
end
...
...
@@ -43,8 +46,12 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
let
(
:build
)
{
create
(
:ci_build
,
ref:
mr_merge_if_green_enabled
.
source_branch
)
}
before
do
allow
(
mr_merge_if_green_enabled
).
to
receive
(
:pipeline
).
and_return
(
pipeline
)
allow
(
mr_merge_if_green_enabled
).
to
receive
(
:mergeable?
).
and_return
(
true
)
allow
(
mr_merge_if_green_enabled
).
to
receive
(
:head_pipeline
)
.
and_return
(
pipeline
)
allow
(
mr_merge_if_green_enabled
).
to
receive
(
:mergeable?
)
.
and_return
(
true
)
allow
(
pipeline
).
to
receive
(
:success?
).
and_return
(
true
)
end
...
...
@@ -138,7 +145,10 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
before
do
# This behavior of MergeRequest: we instantiate a new object
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:pipeline
).
and_wrap_original
do
#
allow_any_instance_of
(
MergeRequest
)
.
to
receive
(
:head_pipeline
)
.
and_wrap_original
do
Ci
::
Pipeline
.
find
(
pipeline
.
id
)
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