diff options
author | Mariusz Michalak <stricte@gumed.edu.pl> | 2014-11-24 11:51:46 +0100 |
---|---|---|
committer | Mariusz Michalak <stricte@gumed.edu.pl> | 2014-11-24 11:51:46 +0100 |
commit | 114d22e77d0c66a9548170c18602d3787daad7c5 (patch) | |
tree | e6b6d9680b49023f819a947b33327c9b0d3fc54a /lib/api | |
parent | cffbdb87f54318fdeab42d56036a86c12ee2c14b (diff) | |
download | gitlab-ci-114d22e77d0c66a9548170c18602d3787daad7c5.tar.gz |
Projects API method for webhooks creation
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/projects.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb index d6cd689..f1f86fc 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: |