diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-03-07 16:55:03 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-03-07 16:55:03 +0800 |
commit | fb167787f2c470649195a5d623f489ec2c3a9117 (patch) | |
tree | ad60222b53a11ee2b29131f57e24ba66dd823c3d /lib/api/triggers.rb | |
parent | 7c9cff3a744a64848207bfde1aedcfe652f07dce (diff) | |
parent | 24f1ee5e9b1f4d9bc8cff581419b091756da8deb (diff) | |
download | gitlab-ce-fb167787f2c470649195a5d623f489ec2c3a9117.tar.gz |
Merge remote-tracking branch 'upstream/master' into set-default-cache-key-for-jobs
* upstream/master: (289 commits)
re-add Assign to Me link on new MR/Issue forms
thinner bottom header border
make header match old 16px padding of body contents
Update font-awesome-rails to 4.7.0.1
Relax font-awesome-rails dependency to ~> 4.7
Restore keyboard shortcuts for "Activity" and "Charts"
fix border radius bottom for header
match padding for mr-widget sections
Update changelog
Fix project-last-commit alignment
Docs: update GL Pages IP on GL.com
Fix up @DouweM review
Remove readme-only project view preference
Add `uploads` to known models for Import/Export spec
Add `has_many` associations for models that can have Upload records
Handle relative and absolute Upload paths in the Uploaders
Change the default CarrierWave root path for tests
Fix Projects::UploadService spec
Add a Project::UploadsController spec to ensure an Upload is created
Add `RecordsUploads` module to record Upload records via callbacks
...
Diffstat (limited to 'lib/api/triggers.rb')
-rw-r--r-- | lib/api/triggers.rb | 76 |
1 files changed, 63 insertions, 13 deletions
diff --git a/lib/api/triggers.rb b/lib/api/triggers.rb index b7c9c5f2b7f..119e9024712 100644 --- a/lib/api/triggers.rb +++ b/lib/api/triggers.rb @@ -6,15 +6,15 @@ module API requires :id, type: String, desc: 'The ID of a project' end resource :projects do - desc 'Trigger a GitLab project build' do - success Entities::TriggerRequest + desc 'Trigger a GitLab project pipeline' do + success Entities::Pipeline end params do requires :ref, type: String, desc: 'The commit sha or name of a branch or tag' requires :token, type: String, desc: 'The unique token of trigger' optional :variables, type: Hash, desc: 'The list of variables to be injected into build' end - post ":id/(ref/:ref/)trigger/builds" do + post ":id/(ref/:ref/)trigger/pipeline" do project = find_project(params[:id]) trigger = Ci::Trigger.find_by_token(params[:token].to_s) not_found! unless project && trigger @@ -29,9 +29,9 @@ module API # create request and trigger builds trigger_request = Ci::CreateTriggerRequestService.new.execute(project, trigger, params[:ref].to_s, variables) if trigger_request - present trigger_request, with: Entities::TriggerRequest + present trigger_request.pipeline, with: Entities::Pipeline else - errors = 'No builds created' + errors = 'No pipeline created' render_api_error!(errors, 400) end end @@ -55,13 +55,13 @@ module API success Entities::Trigger end params do - requires :token, type: String, desc: 'The unique token of trigger' + requires :trigger_id, type: Integer, desc: 'The trigger ID' end - get ':id/triggers/:token' do + get ':id/triggers/:trigger_id' do authenticate! authorize! :admin_build, user_project - trigger = user_project.triggers.find_by(token: params[:token].to_s) + trigger = user_project.triggers.find(params.delete(:trigger_id)) return not_found!('Trigger') unless trigger present trigger, with: Entities::Trigger @@ -70,26 +70,76 @@ module API desc 'Create a trigger' do success Entities::Trigger end + params do + requires :description, type: String, desc: 'The trigger description' + end post ':id/triggers' do authenticate! authorize! :admin_build, user_project - trigger = user_project.triggers.create + trigger = user_project.triggers.create( + declared_params(include_missing: false).merge(owner: current_user)) - present trigger, with: Entities::Trigger + if trigger.valid? + present trigger, with: Entities::Trigger + else + render_validation_error!(trigger) + end + end + + desc 'Update a trigger' do + success Entities::Trigger + end + params do + requires :trigger_id, type: Integer, desc: 'The trigger ID' + optional :description, type: String, desc: 'The trigger description' + end + put ':id/triggers/:trigger_id' do + authenticate! + authorize! :admin_build, user_project + + trigger = user_project.triggers.find(params.delete(:trigger_id)) + return not_found!('Trigger') unless trigger + + if trigger.update(declared_params(include_missing: false)) + present trigger, with: Entities::Trigger + else + render_validation_error!(trigger) + end + end + + desc 'Take ownership of trigger' do + success Entities::Trigger + end + params do + requires :trigger_id, type: Integer, desc: 'The trigger ID' + end + post ':id/triggers/:trigger_id/take_ownership' do + authenticate! + authorize! :admin_build, user_project + + trigger = user_project.triggers.find(params.delete(:trigger_id)) + return not_found!('Trigger') unless trigger + + if trigger.update(owner: current_user) + status :ok + present trigger, with: Entities::Trigger + else + render_validation_error!(trigger) + end end desc 'Delete a trigger' do success Entities::Trigger end params do - requires :token, type: String, desc: 'The unique token of trigger' + requires :trigger_id, type: Integer, desc: 'The trigger ID' end - delete ':id/triggers/:token' do + delete ':id/triggers/:trigger_id' do authenticate! authorize! :admin_build, user_project - trigger = user_project.triggers.find_by(token: params[:token].to_s) + trigger = user_project.triggers.find(params.delete(:trigger_id)) return not_found!('Trigger') unless trigger trigger.destroy |