diff options
| author | Douwe Maan <douwe@gitlab.com> | 2015-10-07 15:15:35 +0200 |
|---|---|---|
| committer | Douwe Maan <douwe@gitlab.com> | 2015-10-07 15:15:35 +0200 |
| commit | 4f629dab2a14c190b641bd709c28ebdad5b7a062 (patch) | |
| tree | 00035d114b896a38b4a2a6ac835411ba36d3e1e5 /lib/api/services.rb | |
| parent | 48837850838c8acb0c02ae60b29e18d287865878 (diff) | |
| parent | 0611a18964a998b6edc81ef9b469f9f70430e542 (diff) | |
| download | gitlab-ce-4f629dab2a14c190b641bd709c28ebdad5b7a062.tar.gz | |
Merge branch 'master' into rs-redactor-filter
Diffstat (limited to 'lib/api/services.rb')
| -rw-r--r-- | lib/api/services.rb | 86 |
1 files changed, 36 insertions, 50 deletions
diff --git a/lib/api/services.rb b/lib/api/services.rb index 3ad59cf3adf..6727e80ac1e 100644 --- a/lib/api/services.rb +++ b/lib/api/services.rb @@ -4,74 +4,60 @@ module API before { authenticate! } before { authorize_admin_project } + resource :projects do - # Set GitLab CI service for project - # - # Parameters: - # token (required) - CI project token - # project_url (required) - CI project url + # Set <service_slug> service for project # # Example Request: + # # PUT /projects/:id/services/gitlab-ci - put ":id/services/gitlab-ci" do - required_attributes! [:token, :project_url] - attrs = attributes_for_keys [:token, :project_url] - user_project.build_missing_services + # + put ':id/services/:service_slug' do + if project_service + validators = project_service.class.validators.select do |s| + s.class == ActiveRecord::Validations::PresenceValidator && + s.attributes != [:project_id] + end + + required_attributes! validators.map(&:attributes).flatten.uniq + attrs = attributes_for_keys service_attributes - if user_project.gitlab_ci_service.update_attributes(attrs.merge(active: true)) - true - else - not_found! + if project_service.update_attributes(attrs.merge(active: true)) + true + else + not_found! + end end end - # Delete GitLab CI service settings + # Delete <service_slug> service for project # # Example Request: - # DELETE /projects/:id/services/gitlab-ci - delete ":id/services/gitlab-ci" do - if user_project.gitlab_ci_service - user_project.gitlab_ci_service.update_attributes( - active: false, - token: nil, - project_url: nil - ) - end - end - - # Set Hipchat service for project # - # Parameters: - # token (required) - Hipchat token - # room (required) - Hipchat room name + # DELETE /project/:id/services/gitlab-ci # - # Example Request: - # PUT /projects/:id/services/hipchat - put ':id/services/hipchat' do - required_attributes! [:token, :room] - attrs = attributes_for_keys [:token, :room] - user_project.build_missing_services + delete ':id/services/:service_slug' do + if project_service + attrs = service_attributes.inject({}) do |hash, key| + hash.merge!(key => nil) + end - if user_project.hipchat_service.update_attributes( - attrs.merge(active: true)) - true - else - not_found! + if project_service.update_attributes(attrs.merge(active: false)) + true + else + not_found! + end end end - # Delete Hipchat service settings + # Get <service_slug> service settings for project # # Example Request: - # DELETE /projects/:id/services/hipchat - delete ':id/services/hipchat' do - if user_project.hipchat_service - user_project.hipchat_service.update_attributes( - active: false, - token: nil, - room: nil - ) - end + # + # GET /project/:id/services/gitlab-ci + # + get ':id/services/:service_slug' do + present project_service end end end |
