Gem::Command
# File lib/rubygems/commands/webhook_command.rb, line 24 24: def initialize 25: super 'webhook', "Register a webhook that will be called any time a gem is updated on Gemcutter." 26: option_text = "The URL of the webhook to" 27: 28: add_option('-a', '--add URL', "#{option_text} add") do |value, options| 29: options[:send] = 'add' 30: options[:url] = value 31: end 32: 33: add_option('-r', '--remove URL', "#{option_text} remove") do |value, options| 34: options[:send] = 'remove' 35: options[:url] = value 36: end 37: 38: add_option('-f', '--fire URL', "#{option_text} testfire") do |value, options| 39: options[:send] = 'fire' 40: options[:url] = value 41: end 42: 43: add_option('-g', '--global', "Apply hook globally") do |value, options| 44: options[:global] = true 45: end 46: 47: add_proxy_option 48: end
# File lib/rubygems/commands/webhook_command.rb, line 61 61: def add_webhook(name, url) 62: say "Adding webhook..." 63: make_webhook_request(:post, name, url) 64: end
# File lib/rubygems/commands/webhook_command.rb, line 16 16: def arguments 17: "GEM_NAME name of gem to register webhook for, or omit to list hooks." 18: end
# File lib/rubygems/commands/webhook_command.rb, line 8 8: def description 9: Webhooks can be created for either specific gems or all gems. In both casesyou'll get a POST request of the gem in JSON format at the URL you specify inthe command. You can also use this command to test fire a webhook for any gem. 10: end
# File lib/rubygems/commands/webhook_command.rb, line 50 50: def execute 51: sign_in 52: 53: if options[:url] 54: name = options[:global] ? '*' : get_one_gem_name 55: send("#{options[:send]}_webhook", name, options[:url]) 56: else 57: list_webhooks 58: end 59: end
# File lib/rubygems/commands/webhook_command.rb, line 71 71: def fire_webhook(name, url) 72: say "Test firing webhook..." 73: make_webhook_request(:post, name, url, "api/v1/web_hooks/fire") 74: end
# File lib/rubygems/commands/webhook_command.rb, line 76 76: def list_webhooks 77: resp = rubygems_api_request(:get, "api/v1/web_hooks.yaml") do |request| 78: request.add_field("Authorization", Gem.configuration.rubygems_api_key) 79: end 80: 81: with_response(resp) do |response| 82: begin 83: groups = YAML.load(response.body) 84: 85: if groups.size.zero? 86: say "You haven't added any webhooks yet." 87: else 88: groups.each do |group, hooks| 89: if options[:global] 90: next if group != "all gems" 91: elsif options[:args] && options[:args].first 92: next if group != options[:args].first 93: end 94: 95: say "#{group}:" 96: hooks.each do |hook| 97: say "- #{hook['url']}" 98: end 99: end 100: end 101: rescue Exception => error 102: say "There was a problem parsing the data:" 103: say error.to_s 104: terminate_interaction 105: end 106: end 107: end
# File lib/rubygems/commands/webhook_command.rb, line 109 109: def make_webhook_request(method, name, url, api = "api/v1/web_hooks") 110: response = rubygems_api_request(method, api) do |request| 111: request.set_form_data("gem_name" => name, "url" => url) 112: request.add_field("Authorization", Gem.configuration.rubygems_api_key) 113: end 114: 115: with_response(response) 116: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.