Skip to content
Browse files

fix key hooks

  • Loading branch information...
1 parent e45b73d commit e4ba310a030f96cf442ef40c4c32c1f0b549a64f Mateus Caruccio committed Jan 17, 2013
Showing with 34 additions and 24 deletions.
  1. +34 −24 app/observers/key_observer.rb
View
58 app/observers/key_observer.rb
@@ -2,33 +2,43 @@ class KeyObserver < ActiveRecord::Observer
include GitHost
def after_save(key)
- git_host.set_key(key.identifier, key.key, key.projects)
- SystemHook.all_hooks_fire({
- event_name: "key_save",
- id: key.id,
- title: key.title,
- key: key.key,
- user_id: key.user.user_id,
- owner_email: key.user.email,
- owner_name: key.user.name,
- projects: key.projects,
- created_at: key.created_at,
- })
+ r = git_host.set_key(key.identifier, key.key, key.projects)
+ begin
+ SystemHook.all_hooks_fire({
+ event_name: "key_save",
+ id: key.id,
+ title: key.title,
+ key: key.key,
+ user_id: key.user.user_id,
+ owner_email: key.user.email,
+ owner_name: key.user.name,
+ projects: key.projects,
+ created_at: key.created_at,
+ })
+ rescue => ex
+ logger.error "SystemHook error: failed POST: #{ex}"
+ end
+ r
end
def after_destroy(key)
return if key.is_deploy_key && !key.last_deploy?
- git_host.remove_key(key.identifier, key.projects)
- SystemHook.all_hooks_fire({
- event_name: "key_destroy",
- id: key.id,
- title: key.title,
- key: key.key,
- user_id: key.user.user_id,
- owner_email: key.user.email,
- owner_name: key.user.name,
- projects: key.projects,
- created_at: key.created_at,
- })
+ r = git_host.remove_key(key.identifier, key.projects)
+ begin
+ SystemHook.all_hooks_fire({
+ event_name: "key_destroy",
+ id: key.id,
+ title: key.title,
+ key: key.key,
+ user_id: key.user.user_id,
+ owner_email: key.user.email,
+ owner_name: key.user.name,
+ projects: key.projects,
+ created_at: key.created_at,
+ })
+ rescue => ex
+ logger.error "SystemHook error: failed POST: #{ex}"
+ end
+ r
end
end

0 comments on commit e4ba310

Please sign in to comment.
Something went wrong with that request. Please try again.