Rename variables_attributes => variables and adds spec for exclude/only option

This commit is contained in:
Jacopo 2018-05-31 09:47:53 +02:00
parent 9b2e19fe37
commit 6ae16b6d4d
3 changed files with 21 additions and 6 deletions

View file

@ -102,7 +102,7 @@ POST /projects/:id/pipeline
|------------|---------|----------|---------------------| |------------|---------|----------|---------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user | | `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
| `ref` | string | yes | Reference to commit | | `ref` | string | yes | Reference to commit |
| `variables_attributes` | array | no | An array containing the variables available in the pipeline matching the structure [{ 'key' => 'UPLOAD_TO_S3', 'value' => 'true' }] | | `variables` | array | no | An array containing the variables available in the pipeline matching the structure [{ 'key' => 'UPLOAD_TO_S3', 'value' => 'true' }] |
``` ```
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/pipeline?ref=master" curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/pipeline?ref=master"

View file

@ -41,7 +41,7 @@ module API
end end
params do params do
requires :ref, type: String, desc: 'Reference' requires :ref, type: String, desc: 'Reference'
optional :variables_attributes, Array, desc: 'Array of variables available in the pipeline' optional :variables, Array, desc: 'Array of variables available in the pipeline'
end end
post ':id/pipeline' do post ':id/pipeline' do
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42124') Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42124')
@ -50,7 +50,7 @@ module API
new_pipeline = Ci::CreatePipelineService.new(user_project, new_pipeline = Ci::CreatePipelineService.new(user_project,
current_user, current_user,
declared_params(include_missing: false)) declared_params(include_missing: false).merge(variables_attributes: params[:variables]))
.execute(:api, ignore_skip_ci: true, save_on_errors: false) .execute(:api, ignore_skip_ci: true, save_on_errors: false)
if new_pipeline.persisted? if new_pipeline.persisted?

View file

@ -302,17 +302,32 @@ describe API::Pipelines do
end end
context 'variables given' do context 'variables given' do
let(:variables_attributes) { [{ 'key' => 'UPLOAD_TO_S3', 'value' => 'true' }] } let(:variables) { [{ 'key' => 'UPLOAD_TO_S3', 'value' => 'true' }] }
it 'creates and returns a new pipeline using the given variables' do it 'creates and returns a new pipeline using the given variables' do
expect do expect do
post api("/projects/#{project.id}/pipeline", user), ref: project.default_branch, variables_attributes: variables_attributes post api("/projects/#{project.id}/pipeline", user), ref: project.default_branch, variables: variables
end.to change { project.pipelines.count }.by(1) end.to change { project.pipelines.count }.by(1)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response).to be_a Hash expect(json_response).to be_a Hash
expect(json_response['sha']).to eq project.commit.id expect(json_response['sha']).to eq project.commit.id
expect(json_response['variables']).to eq variables_attributes expect(json_response['variables']).to eq variables
end
end
context 'when excluding a ref' do
before do
config = YAML.dump(test: { script: 'test', except: [project.default_branch] })
stub_ci_pipeline_yaml_file(config)
end
it "doesn't not create a job for the exluded ref" do
expect do
post api("/projects/#{project.id}/pipeline", user), ref: project.default_branch
end.not_to change { project.pipelines.count }
expect(response).to have_gitlab_http_status(400)
end end
end end