Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-10-29 18:39:46 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-10-29 18:39:46 +0400
commitd636ad49bfba59499e45b445ca7e137e83613d8b (patch)
tree4f825ec920e898f2749c144992eff903887cc763
parentd71914ca230ce83fe1d908d31fb11667a9539304 (diff)
API: set gitlab-ci service for project
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/hipchat_service.rb1
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/deploy_keys.rb10
-rw-r--r--lib/api/services.rb40
-rw-r--r--spec/requests/api/services_spec.rb33
6 files changed, 75 insertions, 11 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 02e1627c44d..c60bbc3c88c 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 c3fb4826334..7fec5c4fbe8 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 c4c9f166db1..4db81f42b4c 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 218b3d8eee2..b5997608997 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 00000000000..d562b9484c5
--- /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 00000000000..e2fd945bad3
--- /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