Commit d636ad49bfba59499e45b445ca7e137e83613d8b
1 parent
d71914ca
Exists in
master
and in
4 other branches
API: set gitlab-ci service for project
Showing
6 changed files
with
75 additions
and
11 deletions
Show diff stats
CHANGELOG
app/models/hipchat_service.rb
lib/api/api.rb
lib/api/deploy_keys.rb
... | ... | @@ -5,16 +5,6 @@ module API |
5 | 5 | before { authorize_admin_project } |
6 | 6 | |
7 | 7 | resource :projects do |
8 | - helpers do | |
9 | - def handle_project_member_errors(errors) | |
10 | - if errors[:project_access].any? | |
11 | - error!(errors[:project_access], 422) | |
12 | - end | |
13 | - not_found! | |
14 | - end | |
15 | - end | |
16 | - | |
17 | - | |
18 | 8 | # Get a specific project's keys |
19 | 9 | # |
20 | 10 | # Example Request: | ... | ... |
... | ... | @@ -0,0 +1,40 @@ |
1 | +module API | |
2 | + # Projects API | |
3 | + class Services < Grape::API | |
4 | + before { authenticate! } | |
5 | + before { authorize_admin_project } | |
6 | + | |
7 | + resource :projects do | |
8 | + # Set GitLab CI service for project | |
9 | + # | |
10 | + # Parameters: | |
11 | + # token (required) - CI project token | |
12 | + # project_url (required) - CI project url | |
13 | + # | |
14 | + # Example Request: | |
15 | + # PUT /projects/:id/services/gitlab-ci | |
16 | + put ":id/services/gitlab-ci" do | |
17 | + required_attributes! [:token, :project_url] | |
18 | + attrs = attributes_for_keys [:token, :project_url] | |
19 | + user_project.build_missing_services | |
20 | + | |
21 | + if user_project.gitlab_ci_service.update_attributes(attrs.merge(active: true)) | |
22 | + true | |
23 | + else | |
24 | + not_found! | |
25 | + end | |
26 | + end | |
27 | + | |
28 | + # Delete GitLab CI service settings | |
29 | + # | |
30 | + # Example Request: | |
31 | + # DELETE /projects/:id/keys/:id | |
32 | + delete ":id/services/gitlab-ci" do | |
33 | + if user_project.gitlab_ci_service | |
34 | + user_project.gitlab_ci_service.destroy | |
35 | + end | |
36 | + end | |
37 | + end | |
38 | + end | |
39 | +end | |
40 | + | ... | ... |
... | ... | @@ -0,0 +1,33 @@ |
1 | +require "spec_helper" | |
2 | + | |
3 | +describe API::API do | |
4 | + include ApiHelpers | |
5 | + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } | |
6 | + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } | |
7 | + | |
8 | + let(:user) { create(:user) } | |
9 | + let(:project) {create(:project_with_code, creator_id: user.id, namespace: user.namespace) } | |
10 | + | |
11 | + describe "POST /projects/:id/services/gitlab-ci" do | |
12 | + it "should update gitlab-ci settings" do | |
13 | + put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'secret-token', project_url: "http://ci.example.com/projects/1" | |
14 | + | |
15 | + response.status.should == 200 | |
16 | + end | |
17 | + | |
18 | + it "should return if required fields missing" do | |
19 | + put api("/projects/#{project.id}/services/gitlab-ci", user), project_url: "http://ci.example.com/projects/1", active: true | |
20 | + | |
21 | + response.status.should == 400 | |
22 | + end | |
23 | + end | |
24 | + | |
25 | + describe "DELETE /projects/:id/services/gitlab-ci" do | |
26 | + it "should update gitlab-ci settings" do | |
27 | + delete api("/projects/#{project.id}/services/gitlab-ci", user) | |
28 | + | |
29 | + response.status.should == 200 | |
30 | + project.gitlab_ci_service.should be_nil | |
31 | + end | |
32 | + end | |
33 | +end | ... | ... |