Commit bf20a3aa authored by Kamil Trzcinski's avatar Kamil Trzcinski

Improve after code review

parent 35d0b9ff
...@@ -53,7 +53,7 @@ module Ci ...@@ -53,7 +53,7 @@ module Ci
schedule: 4, schedule: 4,
api: 5, api: 5,
external: 6, external: 6,
dependent_pipeline: 7 pipeline: 7
} }
state_machine :status, initial: :created do state_machine :status, initial: :created do
......
...@@ -15,8 +15,8 @@ module Ci ...@@ -15,8 +15,8 @@ module Ci
return unless trigger.project == project return unless trigger.project == project
trigger_request = trigger.trigger_requests.create(variables: params[:variables]) trigger_request = trigger.trigger_requests.create(variables: params[:variables])
pipeline = Ci::CreatePipelineService.new(project, trigger.owner, ref: params[:ref]). pipeline = Ci::CreatePipelineService.new(project, trigger.owner, ref: params[:ref])
execute(:trigger, ignore_skip_ci: true, trigger_request: trigger_request) .execute(:trigger, ignore_skip_ci: true, trigger_request: trigger_request)
if pipeline.persisted? if pipeline.persisted?
success(pipeline: pipeline) success(pipeline: pipeline)
...@@ -33,7 +33,7 @@ module Ci ...@@ -33,7 +33,7 @@ module Ci
return error("400 Variables not supported", 400) if params[:variables].any? return error("400 Variables not supported", 400) if params[:variables].any?
pipeline = Ci::CreatePipelineService.new(project, job.user, ref: params[:ref]). pipeline = Ci::CreatePipelineService.new(project, job.user, ref: params[:ref]).
execute(:dependent_pipeline, ignore_skip_ci: true) do |pipeline| execute(:pipeline, ignore_skip_ci: true) do |pipeline|
job.sourced_pipelines.create!(pipeline: pipeline) job.sourced_pipelines.create!(pipeline: pipeline)
end end
...@@ -47,13 +47,13 @@ module Ci ...@@ -47,13 +47,13 @@ module Ci
def trigger_from_token def trigger_from_token
return @trigger if defined?(@trigger) return @trigger if defined?(@trigger)
@trigger ||= Ci::Trigger.find_by_token(params[:token].to_s) @trigger = Ci::Trigger.find_by_token(params[:token].to_s)
end end
def job_from_token def job_from_token
return @job if defined?(@job) return @job if defined?(@job)
@job ||= Ci::Build.find_by_token(params[:token].to_s) @job = Ci::Build.find_by_token(params[:token].to_s)
end end
end end
end end
...@@ -168,7 +168,7 @@ Since GitLab 9.3 you can trigger a new pipeline using a CI_JOB_TOKEN. ...@@ -168,7 +168,7 @@ Since GitLab 9.3 you can trigger a new pipeline using a CI_JOB_TOKEN.
This method currently doesn't support Variables. This method currently doesn't support Variables.
The support for them will be included in 9.4 of GitLab. The support for them will be included in 9.4 of GitLab.
This way of triggering does create a dependent pipeline relation on Pipeline Graph page. This way of triggering creates a dependent pipeline relation visible on the Pipeline Graph.
```yaml ```yaml
build_docs: build_docs:
...@@ -179,7 +179,7 @@ build_docs: ...@@ -179,7 +179,7 @@ build_docs:
- tags - tags
``` ```
Pipelines triggered that way do expose a special variable: `CI_PIPELINE_SOURCE=dependent_pipeline`. Pipelines triggered that way do expose a special variable: `CI_PIPELINE_SOURCE=pipeline`.
### Making use of trigger variables ### Making use of trigger variables
......
...@@ -53,7 +53,7 @@ future GitLab releases.** ...@@ -53,7 +53,7 @@ future GitLab releases.**
| **CI_RUNNER_ID** | 8.10 | 0.5 | The unique id of runner being used | | **CI_RUNNER_ID** | 8.10 | 0.5 | The unique id of runner being used |
| **CI_RUNNER_TAGS** | 8.10 | 0.5 | The defined runner tags | | **CI_RUNNER_TAGS** | 8.10 | 0.5 | The defined runner tags |
| **CI_PIPELINE_ID** | 8.10 | 0.5 | The unique id of the current pipeline that GitLab CI uses internally | | **CI_PIPELINE_ID** | 8.10 | 0.5 | The unique id of the current pipeline that GitLab CI uses internally |
| **CI_PIPELINE_SOURCE** | 9.3 | all | The variable indicates how the pipeline was triggered, possible options are: push, web, trigger, schedule, api, dependent_pipeline | | **CI_PIPELINE_SOURCE** | 9.3 | all | The variable indicates how the pipeline was triggered, possible options are: push, web, trigger, schedule, api, pipeline |
| **CI_PIPELINE_TRIGGERED** | all | all | The flag to indicate that job was [triggered] | | **CI_PIPELINE_TRIGGERED** | all | all | The flag to indicate that job was [triggered] |
| **CI_PROJECT_DIR** | all | all | The full path where the repository is cloned and where the job is run | | **CI_PROJECT_DIR** | all | all | The full path where the repository is cloned and where the job is run |
| **CI_PROJECT_ID** | all | all | The unique id of the current project that GitLab CI uses internally | | **CI_PROJECT_ID** | all | all | The unique id of the current project that GitLab CI uses internally |
......
...@@ -145,12 +145,12 @@ describe API::Triggers do ...@@ -145,12 +145,12 @@ describe API::Triggers do
context 'for related user' do context 'for related user' do
let(:other_user) { create(:user) } let(:other_user) { create(:user) }
context 'with reported permissions' do context 'with reporter permissions' do
before do before do
project.add_reporter(other_user) project.add_reporter(other_user)
end end
it 'forbidds pipeline creation' do it 'forbids to create a pipeline' do
subject subject
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
...@@ -167,7 +167,7 @@ describe API::Triggers do ...@@ -167,7 +167,7 @@ describe API::Triggers do
expect { subject }.to change(Ci::Pipeline, :count) expect { subject }.to change(Ci::Pipeline, :count)
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(Ci::Pipeline.last.source).to eq('dependent_pipeline') expect(Ci::Pipeline.last.source).to eq('pipeline')
expect(Ci::Pipeline.last.triggered_by_pipeline).not_to be_nil expect(Ci::Pipeline.last.triggered_by_pipeline).not_to be_nil
end end
...@@ -176,10 +176,11 @@ describe API::Triggers do ...@@ -176,10 +176,11 @@ describe API::Triggers do
other_job.success other_job.success
end end
it 'creates a new pipeline' do it 'does not create a pipeline' do
subject subject
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('400 Job has to be running')
end end
end end
...@@ -189,7 +190,7 @@ describe API::Triggers do ...@@ -189,7 +190,7 @@ describe API::Triggers do
variables: { 'KEY' => 'VALUE' } } variables: { 'KEY' => 'VALUE' } }
end end
it 'forbidds pipeline creation' do it 'forbids to create a pipeline' do
subject subject
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
......
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