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.
This commit is contained in:
Lin Jen-Shin 2016-09-19 23:51:27 +08:00
parent fe084819b4
commit e0f596c99d
3 changed files with 44 additions and 9 deletions

View file

@ -745,9 +745,17 @@ 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

View file

@ -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

View file

@ -495,18 +495,37 @@ describe MergeRequest, models: true do
end
describe '#all_pipelines' do
shared_examples 'returning pipelines with proper ordering' 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)
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 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).to eq(pipelines.reverse)
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
let(:project) { create(:project, :public) }