diff options
author | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-02-12 17:44:42 +0100 |
---|---|---|
committer | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-02-12 17:44:42 +0100 |
commit | 7cc4339f71be5a71e1d8a95c4524c4671e9d8a24 (patch) | |
tree | e9ce47ff2fa22c810be45df7fd273f3ef7126448 /lib/api/projects.rb | |
parent | 449380265ad3276512d4de7d03e06854d9f1a536 (diff) | |
download | gitlab-ce-7cc4339f71be5a71e1d8a95c4524c4671e9d8a24.tar.gz |
API: changed status codes for project hooks functions
Different status codes in the API lib are returned on hook creation, update or deletion.
If a required parameter is not given (e.g. `url` in `/projects/:id/hooks/:hook_id`) status
code 400 (Bad request) is returned. On hook deletion a 200 status code is returned, regardless if
the hook is present or not. This makes the DELETE function an idempotent operation. Appropriate tests
are added to check these status codes.
Diffstat (limited to 'lib/api/projects.rb')
-rw-r--r-- | lib/api/projects.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb index f1e0f32e606..293353ab286 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -195,11 +195,14 @@ module Gitlab # POST /projects/:id/hooks post ":id/hooks" do authorize! :admin_project, user_project + + error!("Url not given", 400) unless params.has_key? :url + @hook = user_project.hooks.new({"url" => params[:url]}) if @hook.save present @hook, with: Entities::Hook else - error!({'message' => '404 Not found'}, 404) + not_found! end end @@ -215,7 +218,7 @@ module Gitlab @hook = user_project.hooks.find(params[:hook_id]) authorize! :admin_project, user_project - error!("Url not given", 400) if !params.has_key? :url + error!("Url not given", 400) unless params.has_key? :url attrs = attributes_for_keys [:url] if @hook.update_attributes attrs @@ -234,8 +237,13 @@ module Gitlab # DELETE /projects/:id/hooks delete ":id/hooks" do authorize! :admin_project, user_project - @hook = user_project.hooks.find(params[:hook_id]) - @hook.destroy + error!("Hook id not given", 400) unless params.has_key? :hook_id + + begin + @hook = ProjectHook.find(params[:hook_id]) + @hook.destroy + rescue + end end # Get a project repository branches |