Commit e0f596c9 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Show all pipelines from all merge_request_diffs:

This way we could also show pipelines from commits which
were discarded due to a force push.
parent fe084819
......@@ -745,10 +745,18 @@ class MergeRequest < ActiveRecord::Base
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)
return unless source_project
@all_pipelines ||= begin
if persisted?
sha = merge_request_diffs.flat_map(&:commits_sha).uniq
else
sha = diff_head_sha
end
source_project.pipelines.order(id: :desc).
where(sha: sha, ref: source_branch)
end
end
def merge_commit
......
......@@ -117,6 +117,14 @@ class MergeRequestDiff < ActiveRecord::Base
project.commit(head_commit_sha)
end
def commits_sha
if @commits
commits.map(&:sha)
else
st_commits.map { |commit| commit[:id] }
end
end
def diff_refs
return unless start_commit_sha || base_commit_sha
......
......@@ -495,15 +495,34 @@ describe MergeRequest, models: true do
end
describe '#all_pipelines' do
let!(:pipelines) do
subject.merge_request_diff.commits.map do |commit|
create(:ci_empty_pipeline, project: subject.source_project, sha: commit.id, ref: subject.source_branch)
shared_examples 'returning pipelines with proper ordering' do
let!(:pipelines) do
subject.merge_request_diffs.flat_map do |diff|
diff.commits.map do |commit|
create(:ci_empty_pipeline,
project: subject.source_project,
sha: commit.id,
ref: subject.source_branch)
end
end
end
it 'returns all pipelines' do
expect(subject.all_pipelines).not_to be_empty
expect(subject.all_pipelines).to eq(pipelines.reverse)
end
end
it 'returns a pipelines from source projects with proper ordering' do
expect(subject.all_pipelines).not_to be_empty
expect(subject.all_pipelines).to eq(pipelines.reverse)
context 'with single merge_request_diffs' do
it_behaves_like 'returning pipelines with proper ordering'
end
context 'with multiple irrelevant merge_request_diffs' do
before do
subject.update(target_branch: 'markdown')
end
it_behaves_like 'returning pipelines with proper ordering'
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment