Commit 680c4923 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch '335814-fix-cross-db-modification-in-commit-status-api' into 'master'

Ensure ci_pipelines.iid set before transaction in commit status API

See merge request gitlab-org/gitlab!75713
parents e8c4ce24 c2dde812
......@@ -78,13 +78,16 @@ module API
name = params[:name] || params[:context] || 'default'
pipeline ||= user_project.ci_pipelines.create!(
pipeline ||= user_project.ci_pipelines.build(
source: :external,
sha: commit.sha,
ref: ref,
user: current_user,
protected: user_project.protected_for?(ref))
pipeline.ensure_project_iid!
pipeline.save!
authorize! :update_pipeline, pipeline
status = GenericCommitStatus.running_or_pending.find_or_initialize_by(
......
......@@ -131,7 +131,7 @@ RSpec.describe API::CommitStatuses do
%w[pending running success failed canceled].each do |status|
context "for #{status}" do
context 'when pipeline for sha does not exists' do
it 'creates commit status' do
it 'creates commit status and sets pipeline iid' do
post api(post_url, developer), params: { state: status }
expect(response).to have_gitlab_http_status(:created)
......@@ -145,6 +145,8 @@ RSpec.describe API::CommitStatuses do
if status == 'failed'
expect(CommitStatus.find(json_response['id'])).to be_api_failure
end
expect(::Ci::Pipeline.last.iid).not_to be_nil
end
end
end
......
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