summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
diff options
context:
space:
mode:
authorFabio Pitino <fpitino@gitlab.com>2019-08-09 11:40:45 +0200
committerFabio Pitino <fpitino@gitlab.com>2019-09-05 15:53:48 +0100
commitca6a1f33f91a8cceadebfb9c4e9ac6afa340f71d (patch)
treebd9ddad975384be7c022eea49a248ce78ee76445 /spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
parent273ba34c9e85269c6f7653727caafc49fa151fd1 (diff)
downloadgitlab-ce-ca6a1f33f91a8cceadebfb9c4e9ac6afa340f71d.tar.gz
CE port for pipelines for external pull requestsce-detect-github-pull-requests
Detect if pipeline runs for a GitHub pull request When using a mirror for CI/CD only we register a pull_request webhook. When a pull_request webhook is received, if the source branch SHA matches the actual head of the branch in the repository we create immediately a new pipeline for the external pull request. Otherwise we store the pull request info for when the push webhook is received. When using "only/except: external_pull_requests" we can detect if the pipeline has a open pull request on GitHub and create or not the job based on that.
Diffstat (limited to 'spec/lib/gitlab/ci/pipeline/chain/build_spec.rb')
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/build_spec.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
index bf9ff922c05..ba4f841cf43 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
@@ -128,4 +128,38 @@ describe Gitlab::Ci::Pipeline::Chain::Build do
expect(pipeline.target_sha).to eq(merge_request.target_branch_sha)
end
end
+
+ context 'when pipeline is running for an external pull request' do
+ let(:command) do
+ Gitlab::Ci::Pipeline::Chain::Command.new(
+ source: :external_pull_request_event,
+ origin_ref: 'feature',
+ checkout_sha: project.commit.id,
+ after_sha: nil,
+ before_sha: nil,
+ source_sha: external_pull_request.source_sha,
+ target_sha: external_pull_request.target_sha,
+ trigger_request: nil,
+ schedule: nil,
+ external_pull_request: external_pull_request,
+ project: project,
+ current_user: user)
+ end
+
+ let(:external_pull_request) { build(:external_pull_request, project: project) }
+
+ before do
+ step.perform!
+ end
+
+ it 'correctly indicated that this is an external pull request pipeline' do
+ expect(pipeline).to be_external_pull_request_event
+ expect(pipeline.external_pull_request).to eq(external_pull_request)
+ end
+
+ it 'correctly sets source sha and target sha to pipeline' do
+ expect(pipeline.source_sha).to eq(external_pull_request.source_sha)
+ expect(pipeline.target_sha).to eq(external_pull_request.target_sha)
+ end
+ end
end