summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2019-03-01 15:18:08 +0900
committerShinya Maeda <shinya@gitlab.com>2019-03-01 21:38:51 +0900
commit6572c9b49e906d8e47504a47f218ac24bb9320ff (patch)
treeb7699645db5acb46a2d1be74480fc757e994ccce
parentdc5fc28382246fbbe2bb6f61fe8dac136b5f3189 (diff)
downloadgitlab-ce-delegate-to-pipeline-for-merge-request.tar.gz
Make all_pipelines method compatible with pipelines for merge requestsdelegate-to-pipeline-for-merge-request
Make it sane Include merge ref head Single source of fetching merge request Revert some Fix spec ok
-rw-r--r--app/models/ci/build.rb18
-rw-r--r--app/models/ci/pipeline.rb4
-rw-r--r--app/serializers/build_details_entity.rb8
-rw-r--r--spec/models/ci/build_spec.rb10
4 files changed, 14 insertions, 26 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index c902e49ee6d..daf226b7311 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -46,7 +46,7 @@ module Ci
delegate :terminal_specification, to: :runner_session, allow_nil: true
delegate :gitlab_deploy_token, to: :project
delegate :trigger_short_token, to: :trigger_request, allow_nil: true
- delegate :merge_request?, to: :pipeline
+ delegate :merge_request?, :first_merge_request, to: :pipeline
##
# Since Gitlab 11.5, deployments records started being created right after
@@ -463,22 +463,6 @@ module Ci
{ trace_sections: true }
end
- def merge_request
- return @merge_request if defined?(@merge_request)
-
- @merge_request ||=
- begin
- merge_requests = MergeRequest.includes(:latest_merge_request_diff)
- .where(source_branch: ref,
- source_project: pipeline.project)
- .reorder(iid: :desc)
-
- merge_requests.find do |merge_request|
- merge_request.commit_shas.include?(pipeline.sha)
- end
- end
- end
-
def repo_url
return unless token
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index ca941ca4331..77ebd01d047 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -676,6 +676,10 @@ module Ci
end
end
+ def first_merge_request
+ all_merge_requests.first
+ end
+
def detailed_status(current_user)
Gitlab::Ci::Status::Pipeline::Factory
.new(self, current_user)
diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb
index 9ddce0d2c80..0112e9f6535 100644
--- a/app/serializers/build_details_entity.rb
+++ b/app/serializers/build_details_entity.rb
@@ -49,14 +49,14 @@ class BuildDetailsEntity < JobEntity
terminal_project_job_path(project, build)
end
- expose :merge_request, if: -> (*) { can?(current_user, :read_merge_request, build.merge_request) } do
+ expose :merge_request, if: -> (*) { can?(current_user, :read_merge_request, build.first_merge_request) } do
expose :iid do |build|
- build.merge_request.iid
+ build.first_merge_request.iid
end
expose :path do |build|
- project_merge_request_path(build.merge_request.project,
- build.merge_request)
+ project_merge_request_path(build.first_merge_request.project,
+ build.first_merge_request)
end
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index e5281f3a09e..c61bfd04a48 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -1630,7 +1630,7 @@ describe Ci::Build do
end
end
- describe '#merge_request' do
+ describe '#first_merge_request' do
def create_mr(build, pipeline, factory: :merge_request, created_at: Time.now)
create(factory, source_project: pipeline.project,
target_project: pipeline.project,
@@ -1648,13 +1648,13 @@ describe Ci::Build do
end
it 'returns the single associated MR' do
- expect(build.merge_request.id).to eq(@merge_request.id)
+ expect(build.first_merge_request.id).to eq(@merge_request.id)
end
end
context 'when there is not a MR referencing the pipeline' do
it 'returns nil' do
- expect(build.merge_request).to be_nil
+ expect(build.first_merge_request).to be_nil
end
end
@@ -1671,7 +1671,7 @@ describe Ci::Build do
end
it 'returns the first MR' do
- expect(build.merge_request.id).to eq(@merge_request.id)
+ expect(build.first_merge_request.id).to eq(@merge_request.id)
end
end
@@ -1687,7 +1687,7 @@ describe Ci::Build do
end
it 'returns the current MR' do
- expect(@build2.merge_request.id).to eq(@merge_request.id)
+ expect(@build2.first_merge_request.id).to eq(@merge_request.id)
end
end
end