Merge branch 'fix-pipeline-entity' into 'master'
Add merge request pipeline flag to pipeline entity See merge request gitlab-org/gitlab-ce!25846
This commit is contained in:
commit
0f04d4b2b4
7 changed files with 51 additions and 11 deletions
|
@ -28,7 +28,8 @@ class PipelineEntity < Grape::Entity
|
||||||
expose :can_retry?, as: :retryable
|
expose :can_retry?, as: :retryable
|
||||||
expose :can_cancel?, as: :cancelable
|
expose :can_cancel?, as: :cancelable
|
||||||
expose :failure_reason?, as: :failure_reason
|
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
|
end
|
||||||
|
|
||||||
expose :details do
|
expose :details do
|
||||||
|
|
5
changelogs/unreleased/fix-pipeline-entity.yml
Normal file
5
changelogs/unreleased/fix-pipeline-entity.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Add merge request pipeline flag to pipeline entity
|
||||||
|
merge_request: 25846
|
||||||
|
author:
|
||||||
|
type: added
|
|
@ -101,17 +101,36 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :with_merge_request_pipeline do
|
trait :with_detached_merge_request_pipeline do
|
||||||
after(:build) do |merge_request|
|
after(:build) do |merge_request|
|
||||||
merge_request.merge_request_pipelines << build(:ci_pipeline,
|
merge_request.merge_request_pipelines << build(:ci_pipeline,
|
||||||
source: :merge_request_event,
|
source: :merge_request_event,
|
||||||
merge_request: merge_request,
|
merge_request: merge_request,
|
||||||
project: merge_request.source_project,
|
project: merge_request.source_project,
|
||||||
ref: merge_request.source_branch,
|
ref: merge_request.ref_path,
|
||||||
sha: merge_request.source_branch_sha)
|
sha: merge_request.source_branch_sha)
|
||||||
end
|
end
|
||||||
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
|
trait :deployed_review_app do
|
||||||
target_branch 'pages-deploy-target'
|
target_branch 'pages-deploy-target'
|
||||||
|
|
||||||
|
|
|
@ -2772,7 +2772,7 @@ describe Ci::Build do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when ref is merge request' do
|
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(:pipeline) { merge_request.merge_request_pipelines.first }
|
||||||
let(:build) { create(:ci_build, ref: merge_request.source_branch, tag: false, pipeline: pipeline, project: project) }
|
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
|
end
|
||||||
|
|
||||||
context 'when ref is merge request' do
|
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(:pipeline) { merge_request.merge_request_pipelines.first }
|
||||||
let(:build) { create(:ci_build, ref: merge_request.source_branch, tag: false, pipeline: pipeline, project: project) }
|
let(:build) { create(:ci_build, ref: merge_request.source_branch, tag: false, pipeline: pipeline, project: project) }
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ describe HasRef do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when it was triggered by merge request' do
|
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(:pipeline) { merge_request.merge_request_pipelines.first }
|
||||||
let(:build) { create(:ci_build, pipeline: pipeline) }
|
let(:build) { create(:ci_build, pipeline: pipeline) }
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ describe HasRef do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when it is triggered by a merge request' do
|
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(:pipeline) { merge_request.merge_request_pipelines.first }
|
||||||
let(:build) { create(:ci_build, tag: false, pipeline: pipeline) }
|
let(:build) { create(:ci_build, tag: false, pipeline: pipeline) }
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ require 'spec_helper'
|
||||||
describe PipelineEntity do
|
describe PipelineEntity do
|
||||||
include Gitlab::Routing
|
include Gitlab::Routing
|
||||||
|
|
||||||
|
set(:project) { create(:project) }
|
||||||
set(:user) { create(:user) }
|
set(:user) { create(:user) }
|
||||||
set(:project) { create(:project) }
|
set(:project) { create(:project) }
|
||||||
let(:request) { double('request') }
|
let(:request) { double('request') }
|
||||||
|
@ -134,12 +135,12 @@ describe PipelineEntity do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when pipeline is detached merge request pipeline' do
|
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(:project) { merge_request.target_project }
|
||||||
let(:pipeline) { merge_request.merge_request_pipelines.first }
|
let(:pipeline) { merge_request.merge_request_pipelines.first }
|
||||||
|
|
||||||
it 'makes detached flag true' do
|
it 'makes detached flag true' do
|
||||||
expect(subject[:flags][:detached]).to be_truthy
|
expect(subject[:flags][:detached_merge_request_pipeline]).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user is a developer' do
|
context 'when user is a developer' do
|
||||||
|
@ -175,5 +176,19 @@ describe PipelineEntity do
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -102,7 +102,7 @@ describe PipelineSerializer do
|
||||||
|
|
||||||
let!(:merge_request_1) do
|
let!(:merge_request_1) do
|
||||||
create(:merge_request,
|
create(:merge_request,
|
||||||
:with_merge_request_pipeline,
|
:with_detached_merge_request_pipeline,
|
||||||
target_project: project,
|
target_project: project,
|
||||||
target_branch: 'master',
|
target_branch: 'master',
|
||||||
source_project: project,
|
source_project: project,
|
||||||
|
@ -111,7 +111,7 @@ describe PipelineSerializer do
|
||||||
|
|
||||||
let!(:merge_request_2) do
|
let!(:merge_request_2) do
|
||||||
create(:merge_request,
|
create(:merge_request,
|
||||||
:with_merge_request_pipeline,
|
:with_detached_merge_request_pipeline,
|
||||||
target_project: project,
|
target_project: project,
|
||||||
target_branch: 'master',
|
target_branch: 'master',
|
||||||
source_project: project,
|
source_project: project,
|
||||||
|
|
Loading…
Reference in a new issue