Commit e7e5efd1 authored by Stan Hu's avatar Stan Hu Committed by Rémy Coutable

Fix Ci::Pipeline#all_merge_requests missing forked MRs

Ci::Pipeline#all_merge_requests was only returning merge requests
for that project, but it should include merge requests from forks
as well.
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent c5c71299
......@@ -652,9 +652,9 @@ module Ci
def all_merge_requests
@all_merge_requests ||=
if merge_request?
project.merge_requests.where(id: merge_request_id)
MergeRequest.where(id: merge_request_id)
else
project.merge_requests.where(source_branch: ref)
MergeRequest.where(source_project_id: project_id, source_branch: ref)
end
end
......
require 'spec_helper'
describe Ci::Pipeline, :mailer do
include ProjectForksHelper
let(:user) { create(:user) }
set(:project) { create(:project) }
......@@ -2114,16 +2116,18 @@ describe Ci::Pipeline, :mailer do
describe "#all_merge_requests" do
let(:project) { create(:project) }
let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: 'master') }
shared_examples 'a method that returns all merge requests for a given pipeline' do
let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: pipeline_project, ref: 'master') }
it "returns all merge requests having the same source branch" do
merge_request = create(:merge_request, source_project: project, source_branch: pipeline.ref)
merge_request = create(:merge_request, source_project: pipeline_project, target_project: project, source_branch: pipeline.ref)
expect(pipeline.all_merge_requests).to eq([merge_request])
end
it "doesn't return merge requests having a different source branch" do
create(:merge_request, source_project: project, source_branch: 'feature', target_branch: 'master')
create(:merge_request, source_project: pipeline_project, target_project: project, source_branch: 'feature', target_branch: 'master')
expect(pipeline.all_merge_requests).to be_empty
end
......@@ -2135,14 +2139,14 @@ describe Ci::Pipeline, :mailer do
let!(:pipeline) do
create(:ci_pipeline,
source: :merge_request,
project: project,
project: pipeline_project,
ref: source_branch,
merge_request: merge_request)
end
let(:merge_request) do
create(:merge_request,
source_project: project,
source_project: pipeline_project,
source_branch: source_branch,
target_project: project,
target_branch: target_branch)
......@@ -2158,14 +2162,14 @@ describe Ci::Pipeline, :mailer do
let!(:pipeline_2) do
create(:ci_pipeline,
source: :merge_request,
project: project,
project: pipeline_project,
ref: source_branch,
merge_request: merge_request_2)
end
let(:merge_request_2) do
create(:merge_request,
source_project: project,
source_project: pipeline_project,
source_branch: source_branch,
target_project: project,
target_branch: target_branch_2)
......@@ -2178,6 +2182,19 @@ describe Ci::Pipeline, :mailer do
end
end
it_behaves_like 'a method that returns all merge requests for a given pipeline' do
let(:pipeline_project) { project }
end
context 'for a fork' do
let(:fork) { fork_project(project) }
it_behaves_like 'a method that returns all merge requests for a given pipeline' do
let(:pipeline_project) { fork }
end
end
end
describe '#stuck?' do
before do
create(:ci_build, :pending, pipeline: pipeline)
......
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