Commit ee0b4e88 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'add-application-context-metadata-for-pipeline-trigger-endpoint' into 'master'

Add application context metadata for pipeline trigger API endpoint

See merge request gitlab-org/gitlab!57499
parents 0988193e b9f05958
......@@ -6,8 +6,10 @@ module Ci
def execute
if trigger_from_token
set_application_context_from_trigger(trigger_from_token)
create_pipeline_from_trigger(trigger_from_token)
elsif job_from_token
set_application_context_from_job(job_from_token)
create_pipeline_from_job(job_from_token)
end
......@@ -87,5 +89,20 @@ module Ci
value: params.except(*PAYLOAD_VARIABLE_HIDDEN_PARAMS).to_json,
variable_type: :file }
end
def set_application_context_from_trigger(trigger)
Gitlab::ApplicationContext.push(
user: trigger.owner,
project: trigger.project
)
end
def set_application_context_from_job(job)
Gitlab::ApplicationContext.push(
user: job.user,
project: job.project,
runner: job.runner
)
end
end
end
......@@ -126,6 +126,39 @@ RSpec.describe API::Triggers do
end
end
describe 'adding arguments to the application context' do
subject { subject_proc.call }
let(:expected_params) { { client_id: "user/#{user.id}", project: project.full_path } }
let(:subject_proc) { proc { post api("/projects/#{project.id}/ref/master/trigger/pipeline?token=#{trigger_token}"), params: { ref: 'refs/heads/other-branch' } } }
context 'when triggering a pipeline from a trigger token' do
it_behaves_like 'storing arguments in the application context'
it_behaves_like 'not executing any extra queries for the application context'
end
context 'when triggered from another running job' do
let!(:trigger) { }
let!(:trigger_request) { }
context 'when other job is triggered by a user' do
let(:trigger_token) { create(:ci_build, :running, project: project, user: user).token }
it_behaves_like 'storing arguments in the application context'
it_behaves_like 'not executing any extra queries for the application context'
end
context 'when other job is triggered by a runner' do
let(:trigger_token) { create(:ci_build, :running, project: project, runner: runner).token }
let(:runner) { create(:ci_runner) }
let(:expected_params) { { client_id: "runner/#{runner.id}", project: project.full_path } }
it_behaves_like 'storing arguments in the application context'
it_behaves_like 'not executing any extra queries for the application context', 1
end
end
end
context 'when is triggered by a pipeline hook' do
it 'does not create a new pipeline' do
expect do
......
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