Merge branch 'api/gitlab-ci' of /home/git/repositories/gitlab/gitlabhq
This commit is contained in:
commit
0b57c118fc
6 changed files with 75 additions and 11 deletions
|
@ -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
|
||||
|
|
|
@ -71,5 +71,4 @@ class HipchatService < Service
|
|||
|
||||
message
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -38,5 +38,6 @@ module API
|
|||
mount ProjectSnippets
|
||||
mount DeployKeys
|
||||
mount ProjectHooks
|
||||
mount Services
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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:
|
||||
|
|
40
lib/api/services.rb
Normal file
40
lib/api/services.rb
Normal file
|
@ -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
|
||||
|
33
spec/requests/api/services_spec.rb
Normal file
33
spec/requests/api/services_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue