Commit cae0fa7c authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Properly select a list of Pipelines for a Merge Requests

parent 80186b249436
......@@ -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
......
......@@ -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
......
......@@ -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) }
......
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