Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
df8dd8b2f872
Commit
cae0fa7c
authored
Aug 12, 2016
by
Kamil Trzcinski
Browse files
Properly select a list of Pipelines for a Merge Requests
parent
80186b249436
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/controllers/projects/merge_requests_controller.rb
View file @
df8dd8b2
...
...
@@ -137,7 +137,7 @@ def builds
end
def
pipelines
@pipelines
=
Ci
::
Pipeline
.
where
(
ref:
@merge_request
.
source_branch
)
@pipelines
=
@merge_request
.
all_pipelines
respond_to
do
|
format
|
format
.
html
do
...
...
app/models/merge_request.rb
View file @
df8dd8b2
...
...
@@ -642,10 +642,21 @@ def diverged_from_target_branch?
diverged_commits_count
>
0
end
def
commits_sha
commits
.
map
(
&
:sha
)
end
def
pipeline
@pipeline
||=
source_project
.
pipeline
(
diff_head_sha
,
source_branch
)
if
diff_head_sha
&&
source_project
end
def
all_pipelines
@all_pipelines
||=
if
diff_head_sha
&&
source_project
source_project
.
pipelines
.
order
(
id: :desc
).
where
(
sha:
commits_sha
,
ref:
source_branch
)
end
end
def
merge_commit
@merge_commit
||=
project
.
commit
(
merge_commit_sha
)
if
merge_commit_sha
end
...
...
spec/models/merge_request_spec.rb
View file @
df8dd8b2
...
...
@@ -419,6 +419,20 @@
subject
{
create
:merge_request
,
:simple
}
end
describe
'#commits_sha'
do
let
(
:commit0
)
{
double
(
'commit0'
,
sha:
'sha1'
)
}
let
(
:commit1
)
{
double
(
'commit1'
,
sha:
'sha2'
)
}
let
(
:commit2
)
{
double
(
'commit2'
,
sha:
'sha3'
)
}
before
do
allow
(
subject
).
to
receive
(
:commits
).
and_return
([
commit0
,
commit1
,
commit2
])
end
it
'returns sha of commits'
do
expect
(
subject
.
commits_sha
).
to
contain_exactly
(
'sha1'
,
'sha2'
,
'sha3'
)
end
end
describe
'#pipeline'
do
describe
'when the source project exists'
do
it
'returns the latest pipeline'
do
...
...
@@ -443,6 +457,24 @@
end
end
describe
'#all_pipelines'
do
let
(
:commit0
)
{
double
(
'commit0'
,
sha:
'sha1'
)
}
let
(
:commit1
)
{
double
(
'commit1'
,
sha:
'sha2'
)
}
let
(
:commit2
)
{
double
(
'commit2'
,
sha:
'sha3'
)
}
let!
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
project:
subject
.
source_project
,
sha:
'sha1'
,
ref:
subject
.
source_branch
)
}
let!
(
:pipeline2
)
{
create
(
:ci_empty_pipeline
,
project:
subject
.
source_project
,
sha:
'sha1'
,
ref:
subject
.
source_branch
)
}
let!
(
:pipeline3
)
{
create
(
:ci_empty_pipeline
,
project:
subject
.
source_project
,
sha:
'sha2'
,
ref:
subject
.
source_branch
)
}
let!
(
:pipeline4
)
{
create
(
:ci_empty_pipeline
,
project:
subject
.
target_project
,
sha:
'sha1'
,
ref:
subject
.
target_branch
)
}
before
do
allow
(
subject
).
to
receive
(
:commits
).
and_return
([
commit0
,
commit1
,
commit2
])
end
it
'returns a pipelines from source projects'
do
expect
(
subject
.
all_pipelines
).
to
eq
([
pipeline3
,
pipeline2
,
pipeline
])
end
end
describe
'#participants'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
...
...
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