Permalink
Browse files

refactor 404 handling

  • Loading branch information...
1 parent a55b74e commit 32f6319bb7dc47333b4dc6259b2958c4cd786010 @georgeguimaraes georgeguimaraes committed Feb 6, 2012
Showing with 30 additions and 24 deletions.
  1. +30 −24 lib/github-hooker/cli.rb
View
@@ -3,49 +3,55 @@ module Hooker
class CLI < Thor
desc "list user/repo", "List hooks in the given repository"
def list(repo)
- check_config!
- hooks = Github::Hooker.hooks(repo)
- hooks.each do |hook|
- puts "#{hook['url']}"
- puts "> name: #{hook['name']}"
- puts "> events: #{hook['events'].join(", ")}"
- puts "> config: #{hook['config']}"
- puts
- end unless hooks.nil?
- rescue RestClient::ResourceNotFound
- resource_not_found_message!
+ handle_404 do
+ check_config!
+ hooks = Github::Hooker.hooks(repo)
+ hooks.each do |hook|
+ puts "#{hook['url']}"
+ puts "> name: #{hook['name']}"
+ puts "> events: #{hook['events'].join(", ")}"
+ puts "> config: #{hook['config']}"
+ puts
+ end unless hooks.nil?
+ end
end
desc "campfire user/repo events", "Add a campfire hook in the given repository. Events must be separated by commas."
method_option :room, :required => true
method_option :subdomain, :required => true
def campfire(repo, events)
- check_config!
- events = split_events(events)
- Github::Hooker.add_hook(repo, :name => "campfire", :events => events, :config => options)
- rescue RestClient::ResourceNotFound
- resource_not_found_message!
+ handle_404 do
+ check_config!
+ events = split_events(events)
+ Github::Hooker.add_hook(repo, :name => "campfire", :events => events, :config => options)
+ end
end
desc "web user/repo events", "Add a web hook in the given repository. Events must be separated by commas."
method_option :url, :required => true
def web(repo, events)
- check_config!
- events = split_events(events)
- Github::Hooker.add_hook(repo, :name => "web", :events => events, :config => options)
- rescue RestClient::ResourceNotFound
- resource_not_found_message!
+ handle_404 do
+ check_config!
+ events = split_events(events)
+ Github::Hooker.add_hook(repo, :name => "web", :events => events, :config => options)
+ end
end
desc "delete user/repo hook", "Delete the hook 1111 from the given repository"
def delete(repo, hook)
- check_config!
- Github::Hooker.delete_hook(repo, hook)
+ handle_404 do
+ check_config!
+ Github::Hooker.delete_hook(repo, hook)
+ end
+ end
+
+ private
+ def handle_404
+ yield
rescue RestClient::ResourceNotFound
resource_not_found_message!
end
- private
def split_events(events)
events.split(",").map(&:strip)
end

0 comments on commit 32f6319

Please sign in to comment.