From 263abda3fd7ddfb826cd17ae88fb47d0e1d67fae Mon Sep 17 00:00:00 2001 From: Kirilll Zaitsev Date: Thu, 27 Aug 2015 02:58:49 +0300 Subject: Drone CI service --- lib/api/services.rb | 86 +++++++++++++++++++---------------------------------- 1 file changed, 31 insertions(+), 55 deletions(-) (limited to 'lib/api/services.rb') diff --git a/lib/api/services.rb b/lib/api/services.rb index 3ad59cf3adf..73645cedea4 100644 --- a/lib/api/services.rb +++ b/lib/api/services.rb @@ -4,73 +4,49 @@ 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 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 - - if user_project.gitlab_ci_service.update_attributes(attrs.merge(active: true)) - true - else - not_found! - end - end - - # Delete GitLab CI service settings # - # 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 + 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 - # Set Hipchat service for project - # - # Parameters: - # token (required) - Hipchat token - # room (required) - Hipchat room name - # - # 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 + required_attributes! validators.map(&:attributes).flatten.uniq + attrs = attributes_for_keys service_attributes - if user_project.hipchat_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 Hipchat service settings + # Delete service 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 - ) + # + # DELETE /project/:id/services/gitlab-ci + # + delete ':id/services/:service_slug' do + if project_service + attrs = service_attributes.inject({}) do |hash, key| + hash.merge!(key => nil) + end + + if project_service.update_attributes(attrs.merge(active: false)) + true + else + not_found! + end end end end -- cgit v1.2.1 From 9bda4b8d88fc93b8938d8c4d001d6660d112ae1c Mon Sep 17 00:00:00 2001 From: Petheo Bence Date: Thu, 3 Sep 2015 15:38:54 +0200 Subject: Added service API endpoint to retrieve service parameters --- lib/api/services.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/api/services.rb') diff --git a/lib/api/services.rb b/lib/api/services.rb index 73645cedea4..d170b3067ed 100644 --- a/lib/api/services.rb +++ b/lib/api/services.rb @@ -49,6 +49,16 @@ module API end end end + + # Get service settings for project + # + # Example Request: + # + # GET /project/:id/services/gitlab-ci + # + get ':id/services/:service_slug' do + present project_service + end end end end -- cgit v1.2.1 From 2ed2ef921026cbde5dddda89177bfa50e2993ecd Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 11 Sep 2015 13:38:37 +0200 Subject: Remove network from CI --- lib/api/services.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/api/services.rb') diff --git a/lib/api/services.rb b/lib/api/services.rb index 73645cedea4..6d2322bb464 100644 --- a/lib/api/services.rb +++ b/lib/api/services.rb @@ -20,7 +20,7 @@ module API end required_attributes! validators.map(&:attributes).flatten.uniq - attrs = attributes_for_keys service_attributes + attrs = attributes_for_keys service_attributes if project_service.update_attributes(attrs.merge(active: true)) true @@ -41,7 +41,7 @@ module API attrs = service_attributes.inject({}) do |hash, key| hash.merge!(key => nil) end - + if project_service.update_attributes(attrs.merge(active: false)) true else -- cgit v1.2.1