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,9 +745,17 @@ class MergeRequest < ActiveRecord::Base ...@@ -745,9 +745,17 @@ class MergeRequest < ActiveRecord::Base
end end
def all_pipelines def all_pipelines
@all_pipelines ||= return unless source_project
if diff_head_sha && source_project
source_project.pipelines.order(id: :desc).where(sha: commits_sha, ref: source_branch) @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
end end
......
...@@ -117,6 +117,14 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -117,6 +117,14 @@ class MergeRequestDiff < ActiveRecord::Base
project.commit(head_commit_sha) project.commit(head_commit_sha)
end end
def commits_sha
if @commits
commits.map(&:sha)
else
st_commits.map { |commit| commit[:id] }
end
end
def diff_refs def diff_refs
return unless start_commit_sha || base_commit_sha return unless start_commit_sha || base_commit_sha
......
...@@ -495,18 +495,37 @@ describe MergeRequest, models: true do ...@@ -495,18 +495,37 @@ describe MergeRequest, models: true do
end end
describe '#all_pipelines' do describe '#all_pipelines' do
shared_examples 'returning pipelines with proper ordering' do
let!(:pipelines) do let!(:pipelines) do
subject.merge_request_diff.commits.map do |commit| subject.merge_request_diffs.flat_map do |diff|
create(:ci_empty_pipeline, project: subject.source_project, sha: commit.id, ref: subject.source_branch) diff.commits.map do |commit|
create(:ci_empty_pipeline,
project: subject.source_project,
sha: commit.id,
ref: subject.source_branch)
end
end end
end end
it 'returns a pipelines from source projects with proper ordering' do it 'returns all pipelines' do
expect(subject.all_pipelines).not_to be_empty expect(subject.all_pipelines).not_to be_empty
expect(subject.all_pipelines).to eq(pipelines.reverse) expect(subject.all_pipelines).to eq(pipelines.reverse)
end end
end end
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
describe '#participants' do describe '#participants' do
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
......
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