Add specs for specifying pipeline behavior
Adds specs for testing the new behavior of specifying a pipeline when POSTing a status.
This commit is contained in:
parent
4e814c257b
commit
41b8dca877
|
@ -1496,12 +1496,20 @@ class Project < ApplicationRecord
|
||||||
!namespace.share_with_group_lock
|
!namespace.share_with_group_lock
|
||||||
end
|
end
|
||||||
|
|
||||||
def pipeline_for(ref, sha = nil)
|
def pipeline_for(ref, sha = nil, id = nil)
|
||||||
|
if id.present?
|
||||||
|
pipelines_for(ref, sha).find_by(id: id)
|
||||||
|
else
|
||||||
|
pipelines_for(ref, sha).take
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def pipelines_for(ref, sha = nil)
|
||||||
sha ||= commit(ref).try(:sha)
|
sha ||= commit(ref).try(:sha)
|
||||||
|
|
||||||
return unless sha
|
return unless sha
|
||||||
|
|
||||||
ci_pipelines.order(id: :desc).find_by(sha: sha, ref: ref)
|
ci_pipelines.order(id: :desc).where(sha: sha, ref: ref)
|
||||||
end
|
end
|
||||||
|
|
||||||
def latest_successful_pipeline_for_default_branch
|
def latest_successful_pipeline_for_default_branch
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: Multiple pipeline support for Commit status
|
title: Multiple pipeline support for Commit status
|
||||||
merge_request: 21671
|
merge_request: 30828
|
||||||
author: Gaetan Semet
|
author: Gaetan Semet
|
||||||
type: changed
|
type: changed
|
||||||
|
|
|
@ -581,7 +581,7 @@ POST /projects/:id/statuses/:sha
|
||||||
| `target_url` | string | no | The target URL to associate with this status
|
| `target_url` | string | no | The target URL to associate with this status
|
||||||
| `description` | string | no | The short description of the status
|
| `description` | string | no | The short description of the status
|
||||||
| `coverage` | float | no | The total code coverage
|
| `coverage` | float | no | The total code coverage
|
||||||
| `pipeline_id` | integer | no | The id of the pipeline to set status. Use in case of several pipeline on same sha.
|
| `pipeline_id` | integer | no | The ID of the pipeline to set status. Use in case of several pipeline on same SHA.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/17/statuses/18f3e63d05582537db6d183d9d557be09e1f90c8?state=success"
|
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/17/statuses/18f3e63d05582537db6d183d9d557be09e1f90c8?state=success"
|
||||||
|
|
|
@ -52,7 +52,7 @@ module API
|
||||||
optional :name, type: String, desc: 'A string label to differentiate this status from the status of other systems. Default: "default"'
|
optional :name, type: String, desc: 'A string label to differentiate this status from the status of other systems. Default: "default"'
|
||||||
optional :context, type: String, desc: 'A string label to differentiate this status from the status of other systems. Default: "default"'
|
optional :context, type: String, desc: 'A string label to differentiate this status from the status of other systems. Default: "default"'
|
||||||
optional :coverage, type: Float, desc: 'The total code coverage'
|
optional :coverage, type: Float, desc: 'The total code coverage'
|
||||||
optional :pipeline_id, type: Integer, desc: 'An existing pipeline id, when multiple pipelines on the same commit sha have been triggered'
|
optional :pipeline_id, type: Integer, desc: 'An existing pipeline ID, when multiple pipelines on the same commit SHA have been triggered'
|
||||||
end
|
end
|
||||||
# rubocop: disable CodeReuse/ActiveRecord
|
# rubocop: disable CodeReuse/ActiveRecord
|
||||||
post ':id/statuses/:sha' do
|
post ':id/statuses/:sha' do
|
||||||
|
@ -73,11 +73,8 @@ module API
|
||||||
not_found! 'References for commit' unless ref
|
not_found! 'References for commit' unless ref
|
||||||
|
|
||||||
name = params[:name] || params[:context] || 'default'
|
name = params[:name] || params[:context] || 'default'
|
||||||
pipeline = if params[:pipeline_id]
|
|
||||||
@project.ci_pipelines.find_by(id: params[:pipeline_id])
|
pipeline = @project.pipeline_for(ref, commit.sha, params[:pipeline_id])
|
||||||
else
|
|
||||||
@project.pipeline_for(ref, commit.sha)
|
|
||||||
end
|
|
||||||
|
|
||||||
unless pipeline
|
unless pipeline
|
||||||
pipeline = @project.ci_pipelines.create!(
|
pipeline = @project.ci_pipelines.create!(
|
||||||
|
|
|
@ -1190,6 +1190,14 @@ describe Project do
|
||||||
subject { project.pipeline_for('master', pipeline.sha) }
|
subject { project.pipeline_for('master', pipeline.sha) }
|
||||||
|
|
||||||
it_behaves_like 'giving the correct pipeline'
|
it_behaves_like 'giving the correct pipeline'
|
||||||
|
|
||||||
|
context 'with supplied id' do
|
||||||
|
let!(:other_pipeline) { create_pipeline(project) }
|
||||||
|
|
||||||
|
subject { project.pipeline_for('master', pipeline.sha, other_pipeline.id) }
|
||||||
|
|
||||||
|
it { is_expected.to eq(other_pipeline) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with implicit sha' do
|
context 'with implicit sha' do
|
||||||
|
@ -1199,6 +1207,18 @@ describe Project do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#pipelines_for' do
|
||||||
|
let(:project) { create(:project, :repository) }
|
||||||
|
let!(:pipeline) { create_pipeline(project) }
|
||||||
|
let!(:other_pipeline) { create_pipeline(project) }
|
||||||
|
|
||||||
|
context 'with implicit sha' do
|
||||||
|
subject { project.pipelines_for('master') }
|
||||||
|
|
||||||
|
it { is_expected.to contain_exactly(pipeline, other_pipeline) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#builds_enabled' do
|
describe '#builds_enabled' do
|
||||||
let(:project) { create(:project) }
|
let(:project) { create(:project) }
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,6 @@ describe API::CommitStatuses do
|
||||||
let(:developer) { create_user(:developer) }
|
let(:developer) { create_user(:developer) }
|
||||||
let(:sha) { commit.id }
|
let(:sha) { commit.id }
|
||||||
|
|
||||||
let(:commit_status) do
|
|
||||||
create(:commit_status, status: :pending, pipeline: pipeline)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "GET /projects/:id/repository/commits/:sha/statuses" do
|
describe "GET /projects/:id/repository/commits/:sha/statuses" do
|
||||||
let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" }
|
let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" }
|
||||||
|
|
||||||
|
@ -239,6 +235,26 @@ describe API::CommitStatuses do
|
||||||
expect(CommitStatus.count).to eq 1
|
expect(CommitStatus.count).to eq 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when a pipeline id is specified' do
|
||||||
|
let!(:first_pipeline) { project.ci_pipelines.create(source: :push, sha: commit.id, ref: 'master', status: 'created') }
|
||||||
|
let!(:other_pipeline) { project.ci_pipelines.create(source: :push, sha: commit.id, ref: 'master', status: 'created') }
|
||||||
|
|
||||||
|
subject do
|
||||||
|
post api(post_url, developer), params: {
|
||||||
|
pipeline_id: other_pipeline.id,
|
||||||
|
state: 'success',
|
||||||
|
ref: 'master'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'update the correct pipeline' do
|
||||||
|
subject
|
||||||
|
|
||||||
|
expect(first_pipeline.reload.status).to eq('created')
|
||||||
|
expect(other_pipeline.reload.status).to eq('success')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when retrying a commit status' do
|
context 'when retrying a commit status' do
|
||||||
|
|
Loading…
Reference in New Issue