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 ...@@ -652,9 +652,9 @@ module Ci
def all_merge_requests def all_merge_requests
@all_merge_requests ||= @all_merge_requests ||=
if merge_request? if merge_request?
project.merge_requests.where(id: merge_request_id) MergeRequest.where(id: merge_request_id)
else else
project.merge_requests.where(source_branch: ref) MergeRequest.where(source_project_id: project_id, source_branch: ref)
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Ci::Pipeline, :mailer do describe Ci::Pipeline, :mailer do
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
set(:project) { create(:project) } set(:project) { create(:project) }
...@@ -2114,16 +2116,18 @@ describe Ci::Pipeline, :mailer do ...@@ -2114,16 +2116,18 @@ describe Ci::Pipeline, :mailer do
describe "#all_merge_requests" do describe "#all_merge_requests" do
let(:project) { create(:project) } 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 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]) expect(pipeline.all_merge_requests).to eq([merge_request])
end end
it "doesn't return merge requests having a different source branch" do 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 expect(pipeline.all_merge_requests).to be_empty
end end
...@@ -2135,14 +2139,14 @@ describe Ci::Pipeline, :mailer do ...@@ -2135,14 +2139,14 @@ describe Ci::Pipeline, :mailer do
let!(:pipeline) do let!(:pipeline) do
create(:ci_pipeline, create(:ci_pipeline,
source: :merge_request, source: :merge_request,
project: project, project: pipeline_project,
ref: source_branch, ref: source_branch,
merge_request: merge_request) merge_request: merge_request)
end end
let(:merge_request) do let(:merge_request) do
create(:merge_request, create(:merge_request,
source_project: project, source_project: pipeline_project,
source_branch: source_branch, source_branch: source_branch,
target_project: project, target_project: project,
target_branch: target_branch) target_branch: target_branch)
...@@ -2158,14 +2162,14 @@ describe Ci::Pipeline, :mailer do ...@@ -2158,14 +2162,14 @@ describe Ci::Pipeline, :mailer do
let!(:pipeline_2) do let!(:pipeline_2) do
create(:ci_pipeline, create(:ci_pipeline,
source: :merge_request, source: :merge_request,
project: project, project: pipeline_project,
ref: source_branch, ref: source_branch,
merge_request: merge_request_2) merge_request: merge_request_2)
end end
let(:merge_request_2) do let(:merge_request_2) do
create(:merge_request, create(:merge_request,
source_project: project, source_project: pipeline_project,
source_branch: source_branch, source_branch: source_branch,
target_project: project, target_project: project,
target_branch: target_branch_2) target_branch: target_branch_2)
...@@ -2178,6 +2182,19 @@ describe Ci::Pipeline, :mailer do ...@@ -2178,6 +2182,19 @@ describe Ci::Pipeline, :mailer do
end end
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 describe '#stuck?' do
before do before do
create(:ci_build, :pending, pipeline: pipeline) 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