diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-03-13 15:55:12 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-03-13 15:55:12 +0000 |
commit | 0f04d4b2b4f41b5530ac7110d1c883540d5bc96f (patch) | |
tree | 6641c611b6b7367dbd75d7564dfe3a43a13cf5d2 | |
parent | 3bc8a2fe71cfe6512577ba3dc37479001405763f (diff) | |
parent | 05c0377008438025a7e3396effefc197f6bf2a97 (diff) | |
download | gitlab-ce-0f04d4b2b4f41b5530ac7110d1c883540d5bc96f.tar.gz |
Merge branch 'fix-pipeline-entity' into 'master'
Add merge request pipeline flag to pipeline entity
See merge request gitlab-org/gitlab-ce!25846
-rw-r--r-- | app/serializers/pipeline_entity.rb | 3 | ||||
-rw-r--r-- | changelogs/unreleased/fix-pipeline-entity.yml | 5 | ||||
-rw-r--r-- | spec/factories/merge_requests.rb | 23 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/concerns/has_ref_spec.rb | 4 | ||||
-rw-r--r-- | spec/serializers/pipeline_entity_spec.rb | 19 | ||||
-rw-r--r-- | spec/serializers/pipeline_serializer_spec.rb | 4 |
7 files changed, 51 insertions, 11 deletions
diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index 5ac1e590d39..fba72410217 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -28,7 +28,8 @@ class PipelineEntity < Grape::Entity expose :can_retry?, as: :retryable expose :can_cancel?, as: :cancelable expose :failure_reason?, as: :failure_reason - expose :detached_merge_request_pipeline?, as: :detached + expose :detached_merge_request_pipeline?, as: :detached_merge_request_pipeline + expose :merge_request_pipeline?, as: :merge_request_pipeline end expose :details do diff --git a/changelogs/unreleased/fix-pipeline-entity.yml b/changelogs/unreleased/fix-pipeline-entity.yml new file mode 100644 index 00000000000..b429139402c --- /dev/null +++ b/changelogs/unreleased/fix-pipeline-entity.yml @@ -0,0 +1,5 @@ +--- +title: Add merge request pipeline flag to pipeline entity +merge_request: 25846 +author: +type: added diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index ecd7ea65fb7..a73f330a7a9 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -101,17 +101,36 @@ FactoryBot.define do end end - trait :with_merge_request_pipeline do + trait :with_detached_merge_request_pipeline do after(:build) do |merge_request| merge_request.merge_request_pipelines << build(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, project: merge_request.source_project, - ref: merge_request.source_branch, + ref: merge_request.ref_path, sha: merge_request.source_branch_sha) end end + trait :with_merge_request_pipeline do + transient do + merge_sha { 'test-merge-sha' } + source_sha { source_branch_sha } + target_sha { target_branch_sha } + end + + after(:build) do |merge_request, evaluator| + merge_request.merge_request_pipelines << create(:ci_pipeline, + source: :merge_request_event, + merge_request: merge_request, + project: merge_request.source_project, + ref: merge_request.merge_ref_path, + sha: evaluator.merge_sha, + source_sha: evaluator.source_sha, + target_sha: evaluator.target_sha) + end + end + trait :deployed_review_app do target_branch 'pages-deploy-target' diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index dd40b968bc1..9ca4241d7d8 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2772,7 +2772,7 @@ describe Ci::Build do end context 'when ref is merge request' do - let(:merge_request) { create(:merge_request, :with_merge_request_pipeline) } + let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) } let(:pipeline) { merge_request.merge_request_pipelines.first } let(:build) { create(:ci_build, ref: merge_request.source_branch, tag: false, pipeline: pipeline, project: project) } @@ -2830,7 +2830,7 @@ describe Ci::Build do end context 'when ref is merge request' do - let(:merge_request) { create(:merge_request, :with_merge_request_pipeline) } + let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) } let(:pipeline) { merge_request.merge_request_pipelines.first } let(:build) { create(:ci_build, ref: merge_request.source_branch, tag: false, pipeline: pipeline, project: project) } diff --git a/spec/models/concerns/has_ref_spec.rb b/spec/models/concerns/has_ref_spec.rb index 8aa2fecb18c..6805731fed3 100644 --- a/spec/models/concerns/has_ref_spec.rb +++ b/spec/models/concerns/has_ref_spec.rb @@ -18,7 +18,7 @@ describe HasRef do end context 'when it was triggered by merge request' do - let(:merge_request) { create(:merge_request, :with_merge_request_pipeline) } + let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) } let(:pipeline) { merge_request.merge_request_pipelines.first } let(:build) { create(:ci_build, pipeline: pipeline) } @@ -67,7 +67,7 @@ describe HasRef do end context 'when it is triggered by a merge request' do - let(:merge_request) { create(:merge_request, :with_merge_request_pipeline) } + let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) } let(:pipeline) { merge_request.merge_request_pipelines.first } let(:build) { create(:ci_build, tag: false, pipeline: pipeline) } diff --git a/spec/serializers/pipeline_entity_spec.rb b/spec/serializers/pipeline_entity_spec.rb index d510293ae38..c8308a0ae85 100644 --- a/spec/serializers/pipeline_entity_spec.rb +++ b/spec/serializers/pipeline_entity_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe PipelineEntity do include Gitlab::Routing + set(:project) { create(:project) } set(:user) { create(:user) } set(:project) { create(:project) } let(:request) { double('request') } @@ -134,12 +135,12 @@ describe PipelineEntity do end context 'when pipeline is detached merge request pipeline' do - let(:merge_request) { create(:merge_request, :with_merge_request_pipeline) } + let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) } let(:project) { merge_request.target_project } let(:pipeline) { merge_request.merge_request_pipelines.first } it 'makes detached flag true' do - expect(subject[:flags][:detached]).to be_truthy + expect(subject[:flags][:detached_merge_request_pipeline]).to be_truthy end context 'when user is a developer' do @@ -175,5 +176,19 @@ describe PipelineEntity do end end end + + context 'when pipeline is merge request pipeline' do + let(:merge_request) { create(:merge_request, :with_merge_request_pipeline, merge_sha: 'abc') } + let(:project) { merge_request.target_project } + let(:pipeline) { merge_request.merge_request_pipelines.first } + + it 'makes detached flag false' do + expect(subject[:flags][:detached_merge_request_pipeline]).to be_falsy + end + + it 'makes atached flag true' do + expect(subject[:flags][:merge_request_pipeline]).to be_truthy + end + end end end diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb index cead75c0895..0fdd675aa01 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -102,7 +102,7 @@ describe PipelineSerializer do let!(:merge_request_1) do create(:merge_request, - :with_merge_request_pipeline, + :with_detached_merge_request_pipeline, target_project: project, target_branch: 'master', source_project: project, @@ -111,7 +111,7 @@ describe PipelineSerializer do let!(:merge_request_2) do create(:merge_request, - :with_merge_request_pipeline, + :with_detached_merge_request_pipeline, target_project: project, target_branch: 'master', source_project: project, |