Commit 882029d9c62c54293147da0d5e2d3b6eaaa89535

Authored by Dmitriy Zaporozhets
1 parent fff69bdb

Expose ProjectHook attributes via API

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing 2 changed files with 8 additions and 4 deletions   Show diff stats
lib/api/entities.rb
@@ -24,6 +24,10 @@ module API @@ -24,6 +24,10 @@ module API
24 expose :id, :url, :created_at 24 expose :id, :url, :created_at
25 end 25 end
26 26
  27 + class ProjectHook < Hook
  28 + expose :project_id, :push_events, :issues_events, :merge_requests_events
  29 + end
  30 +
27 class ForkedFromProject < Grape::Entity 31 class ForkedFromProject < Grape::Entity
28 expose :id 32 expose :id
29 expose :name, :name_with_namespace 33 expose :name, :name_with_namespace
lib/api/project_hooks.rb
@@ -22,7 +22,7 @@ module API @@ -22,7 +22,7 @@ module API
22 # GET /projects/:id/hooks 22 # GET /projects/:id/hooks
23 get ":id/hooks" do 23 get ":id/hooks" do
24 @hooks = paginate user_project.hooks 24 @hooks = paginate user_project.hooks
25 - present @hooks, with: Entities::Hook 25 + present @hooks, with: Entities::ProjectHook
26 end 26 end
27 27
28 # Get a project hook 28 # Get a project hook
@@ -34,7 +34,7 @@ module API @@ -34,7 +34,7 @@ module API
34 # GET /projects/:id/hooks/:hook_id 34 # GET /projects/:id/hooks/:hook_id
35 get ":id/hooks/:hook_id" do 35 get ":id/hooks/:hook_id" do
36 @hook = user_project.hooks.find(params[:hook_id]) 36 @hook = user_project.hooks.find(params[:hook_id])
37 - present @hook, with: Entities::Hook 37 + present @hook, with: Entities::ProjectHook
38 end 38 end
39 39
40 40
@@ -50,7 +50,7 @@ module API @@ -50,7 +50,7 @@ module API
50 50
51 @hook = user_project.hooks.new({"url" => params[:url]}) 51 @hook = user_project.hooks.new({"url" => params[:url]})
52 if @hook.save 52 if @hook.save
53 - present @hook, with: Entities::Hook 53 + present @hook, with: Entities::ProjectHook
54 else 54 else
55 if @hook.errors[:url].present? 55 if @hook.errors[:url].present?
56 error!("Invalid url given", 422) 56 error!("Invalid url given", 422)
@@ -73,7 +73,7 @@ module API @@ -73,7 +73,7 @@ module API
73 73
74 attrs = attributes_for_keys [:url] 74 attrs = attributes_for_keys [:url]
75 if @hook.update_attributes attrs 75 if @hook.update_attributes attrs
76 - present @hook, with: Entities::Hook 76 + present @hook, with: Entities::ProjectHook
77 else 77 else
78 if @hook.errors[:url].present? 78 if @hook.errors[:url].present?
79 error!("Invalid url given", 422) 79 error!("Invalid url given", 422)