diff --git a/CHANGELOG b/CHANGELOG index 02e1627c44d64b45a9dc0b361038b1c55c2ae3d2..c60bbc3c88c41ed72360a55ff399528bebeab141 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ v 6.3.0 + - API for adding gitlab-ci service - Init script now waits for pids to appear after (re)starting before reporting status (Rovanion Luckey) - Restyle project home page - Grammar fixes diff --git a/app/models/hipchat_service.rb b/app/models/hipchat_service.rb index c3fb482633453935bc961f79ebb3377cdad53236..7fec5c4fbe8861531d00fa4a648979669497e2e9 100644 --- a/app/models/hipchat_service.rb +++ b/app/models/hipchat_service.rb @@ -71,5 +71,4 @@ class HipchatService < Service message end - end diff --git a/lib/api/api.rb b/lib/api/api.rb index c4c9f166db1d9efae6567bb07a7dae39efb1b43f..4db81f42b4ce8fd8352b01dd0fa08df7ec32d2e0 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -38,5 +38,6 @@ module API mount ProjectSnippets mount DeployKeys mount ProjectHooks + mount Services end end diff --git a/lib/api/deploy_keys.rb b/lib/api/deploy_keys.rb index 218b3d8eee2e7c4c90a1e27d7f73088e0daaea7a..b59976089978275777ef152b984f86fccc63222e 100644 --- a/lib/api/deploy_keys.rb +++ b/lib/api/deploy_keys.rb @@ -5,16 +5,6 @@ module API before { authorize_admin_project } resource :projects do - helpers do - def handle_project_member_errors(errors) - if errors[:project_access].any? - error!(errors[:project_access], 422) - end - not_found! - end - end - - # Get a specific project's keys # # Example Request: diff --git a/lib/api/services.rb b/lib/api/services.rb new file mode 100644 index 0000000000000000000000000000000000000000..d562b9484c55cac252d35e0a06ae4033482fd872 --- /dev/null +++ b/lib/api/services.rb @@ -0,0 +1,40 @@ +module API + # Projects API + class Services < Grape::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 + # + # 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/keys/:id + delete ":id/services/gitlab-ci" do + if user_project.gitlab_ci_service + user_project.gitlab_ci_service.destroy + end + end + end + end +end + diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..e2fd945bad3259aa3ad4614902004e61ef899db3 --- /dev/null +++ b/spec/requests/api/services_spec.rb @@ -0,0 +1,33 @@ +require "spec_helper" + +describe API::API do + include ApiHelpers + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } + + let(:user) { create(:user) } + let(:project) {create(:project_with_code, creator_id: user.id, namespace: user.namespace) } + + describe "POST /projects/:id/services/gitlab-ci" do + it "should update gitlab-ci settings" do + put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'secret-token', project_url: "http://ci.example.com/projects/1" + + response.status.should == 200 + end + + it "should return if required fields missing" do + put api("/projects/#{project.id}/services/gitlab-ci", user), project_url: "http://ci.example.com/projects/1", active: true + + response.status.should == 400 + end + end + + describe "DELETE /projects/:id/services/gitlab-ci" do + it "should update gitlab-ci settings" do + delete api("/projects/#{project.id}/services/gitlab-ci", user) + + response.status.should == 200 + project.gitlab_ci_service.should be_nil + end + end +end