diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-09-19 23:51:27 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-09-19 23:51:27 +0800 |
commit | e0f596c99debe880dfcaed66220a9483d0c81e7b (patch) | |
tree | 762599ad2fc27011f95651ef9b0d735163298d82 | |
parent | fe084819b4c0aa83ec80b5915e7b3f444b693e9f (diff) | |
download | gitlab-ce-e0f596c99debe880dfcaed66220a9483d0c81e7b.tar.gz |
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.
-rw-r--r-- | app/models/merge_request.rb | 14 | ||||
-rw-r--r-- | app/models/merge_request_diff.rb | 8 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 31 |
3 files changed, 44 insertions, 9 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 75f48fd4ba5..4532e7df7b5 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -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 diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 18c583add88..7362886e9f5 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -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 diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 06feeb1bbba..fb599e1207d 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -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 |