diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2015-01-08 18:37:17 +0100 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2015-01-08 18:37:17 +0100 |
commit | 37e57baf3d064660ab8251e29f938c14d3ec6ee3 (patch) | |
tree | 9cf70a7bea442d2eecfcc73009e094b176f8e93a /lib | |
parent | d161babe69765fe0e2816d4f42bc009c31e57552 (diff) | |
parent | 7b92b470420bcdd522f1088d1852d3b46a926c92 (diff) | |
download | gitlab-ci-37e57baf3d064660ab8251e29f938c14d3ec6ee3.tar.gz |
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ci
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/projects.rb | 24 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 0748442..dfd419a 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -23,5 +23,9 @@ module API class RunnerProject < Grape::Entity expose :id, :project_id, :runner_id end + + class WebHook < Grape::Entity + expose :id, :project_id, :url + end end end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 89faa04..632aa51 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -4,6 +4,30 @@ module API before { authenticate! } resource :projects do + # Register new webhook for project + # + # Parameters + # project_id (required) - The ID of a project + # web_hook (required) - WebHook URL + # Example Request + # POST /projects/:project_id/webhooks + post ":project_id/webhooks" do + required_attributes! [:web_hook] + + project = Project.find(params[:project_id]) + + if project.present? && current_user.can_access_project?(project.gitlab_id) + web_hook = project.web_hooks.new({url: params[:web_hook]}) + + if web_hook.save + present web_hook, :with => Entities::WebHook + else + errors = web_hook.errors.full_messages.join(", ") + render_api_error!(errors, 400) + end + end + end + # Retrieve all Gitlab CI projects that the user has access to # # Example Request: |