module Octokit::Client::Hooks
Methods for the Hooks
API
Public Instance Methods
List all Service Hooks
supported by GitHub
@return [Sawyer::Resource] A list of all hooks on GitHub @see developer.github.com/v3/repos/hooks/#services @example List all hooks
Octokit.available_hooks
# File lib/octokit/client/hooks.rb, line 13 def available_hooks(options = {}) get "hooks", options end
Create a hook
Requires authenticated client.
@param repo [Integer, String, Hash, Repository] A GitHub repository. @param name [String] The name of the service that is being called. See
{https://api.github.com/hooks Hooks} for the possible names.
@param config [Hash] A Hash containing key/value pairs to provide
settings for this hook. These settings vary between the services and are defined in the {https://github.com/github/github-services github-services} repo.
@option options [Array<String>] :events ('[“push”]') Determines what
events the hook is triggered for.
@option options [Boolean] :active Determines whether the hook is
actually triggered on pushes.
@return [Sawyer::Resource] Hook info for the new hook @see api.github.com/hooks @see github.com/github/github-services @see developer.github.com/v3/repos/hooks/#create-a-hook @example
@client.create_hook( 'octokit/octokit.rb', 'web', { :url => 'http://something.com/webhook', :content_type => 'json' }, { :events => ['push', 'pull_request'], :active => true } )
# File lib/octokit/client/hooks.rb, line 75 def create_hook(repo, name, config, options = {}) options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options) post "#{Repository.path repo}/hooks", options end
Create an org hook
Requires client authenticated as admin for the org.
@param org [String, Integer] Organization
GitHub login or id. @param config [Hash] A Hash containing key/value pairs to provide
settings for this hook.
@option options [Array<String>] :events ('[“push”]') Determines what
events the hook is triggered for.
@option options [Boolean] :active Determines whether the hook is
actually triggered on pushes.
@return [Sawyer::Resource] Hook info for the new hook @see api.github.com/hooks @see developer.github.com/v3/orgs/hooks/#create-a-hook @example
@client.create_org_hook( 'octokit', { :url => 'http://something.com/webhook', :content_type => 'json' }, { :events => ['push', 'pull_request'], :active => true } )
# File lib/octokit/client/hooks.rb, line 219 def create_org_hook(org, config, options = {}) options = { :name => "web", :config => config }.merge(options) post "#{Organization.path org}/hooks", options end
Edit a hook
Requires authenticated client.
@param repo [Integer, String, Hash, Repository] A GitHub repository. @param id [Integer] Id of the hook being updated. @param name [String] The name of the service that is being called. See
{https://api.github.com/hooks Hooks} for the possible names.
@param config [Hash] A Hash containing key/value pairs to provide
settings for this hook. These settings vary between the services and are defined in the {https://github.com/github/github-services github-services} repo.
@option options [Array<String>] :events ('[“push”]') Determines what
events the hook is triggered for.
@option options [Array<String>] :add_events Determines a list of events
to be added to the list of events that the Hook triggers for.
@option options [Array<String>] :remove_events Determines a list of events
to be removed from the list of events that the Hook triggers for.
@option options [Boolean] :active Determines whether the hook is
actually triggered on pushes.
@return [Sawyer::Resource] Hook info for the updated hook @see api.github.com/hooks @see github.com/github/github-services @see developer.github.com/v3/repos/hooks/#edit-a-hook @example
@client.edit_hook( 'octokit/octokit.rb', 100000, 'web', { :url => 'http://something.com/webhook', :content_type => 'json' }, { :add_events => ['status'], :remove_events => ['pull_request'], :active => true } )
# File lib/octokit/client/hooks.rb, line 118 def edit_hook(repo, id, name, config, options = {}) options = {:name => name, :config => config}.merge(options) patch "#{Repository.path repo}/hooks/#{id}", options end
Update an org hook
Requires client authenticated as admin for the org.
@param org [String, Integer] Organization
GitHub login or id. @param id [Integer] Id of the hook to update. @param config [Hash] A Hash containing key/value pairs to provide
settings for this hook.
@option options [Array<String>] :events ('[“push”]') Determines what
events the hook is triggered for.
@option options [Boolean] :active Determines whether the hook is
actually triggered on pushes.
@return [Sawyer::Resource] Hook info for the new hook @see api.github.com/hooks @see developer.github.com/v3/orgs/hooks/#edit-a-hook @example
@client.edit_org_hook( 'octokit', 123, { :url => 'http://something.com/webhook', :content_type => 'json' }, { :events => ['push', 'pull_request'], :active => true } )
# File lib/octokit/client/hooks.rb, line 252 def edit_org_hook(org, id, config, options = {}) options = { :config => config }.merge(options) patch "#{Organization.path org}/hooks/#{id}", options end
Get single hook
Requires authenticated client.
@param repo [Integer, String, Hash, Repository] A GitHub repository. @param id [Integer] Id of the hook to get. @return [Sawyer::Resource] Hash representing hook. @see developer.github.com/v3/repos/hooks/#get-single-hook @example
@client.hook('octokit/octokit.rb', 100000)
# File lib/octokit/client/hooks.rb, line 40 def hook(repo, id, options = {}) get "#{Repository.path repo}/hooks/#{id}", options end
List repo hooks
Requires authenticated client.
@param repo [Integer, String, Hash, Repository] A GitHub repository. @return [Array<Sawyer::Resource>] Array of hashes representing hooks. @see developer.github.com/v3/repos/hooks/#list-hooks @example
@client.hooks('octokit/octokit.rb')
# File lib/octokit/client/hooks.rb, line 26 def hooks(repo, options = {}) paginate "#{Repository.path repo}/hooks", options end
Get an org hook
Requires client authenticated as admin for the org.
@param org [String, Integer] Organization
GitHub login or id. @param id [Integer] Id of the hook to get. @return [Sawyer::Resource] Hash representing hook. @see developer.github.com/v3/orgs/hooks/#get-single-hook @example
@client.org_hook('octokit', 123)
# File lib/octokit/client/hooks.rb, line 189 def org_hook(org, id, options = {}) get "#{Organization.path org}/hooks/#{id}", options end
List org hooks
Requires client authenticated as admin for the org.
@param org [String, Integer] Organization
GitHub login or id. @return [Array<Sawyer::Resource>] Array of hashes representing hooks. @see developer.github.com/v3/orgs/hooks/#list-hooks @example
@client.org_hooks('octokit')
# File lib/octokit/client/hooks.rb, line 174 def org_hooks(org, options = {}) paginate "#{Organization.path org}/hooks", options end
Parse payload string
@param payload_string [String] The payload @return [Sawyer::Resource] The payload object @see developer.github.com/v3/activity/events/types/
# File lib/octokit/client/hooks.rb, line 291 def parse_payload(payload_string) payload_hash = agent.class.decode payload_string Sawyer::Resource.new agent, payload_hash end
Ping hook
Requires authenticated client.
@param repo [Integer, String, Hash, Repository] A GitHub repository. @param id [Integer] Id of the hook to send a ping. @return [Boolean] Ping requested? @see developer.github.com/v3/repos/hooks/#ping-a-hook @example
@client.ping_hook('octokit/octokit.rb', 1000000)
# File lib/octokit/client/hooks.rb, line 161 def ping_hook(repo, id, options={}) boolean_from_response :post, "#{Repository.path repo}/hooks/#{id}/pings", options end
Ping org hook
Requires client authenticated as admin for the org.
@param org [String, Integer] Organization
GitHub login or id. @param id [Integer] Id of the hook to update. @return [Boolean] Success @see developer.github.com/v3/orgs/hooks/#ping-a-hook @example
@client.ping_org_hook('octokit', 1000000)
# File lib/octokit/client/hooks.rb, line 268 def ping_org_hook(org, id, options = {}) boolean_from_response :post, "#{Organization.path org}/hooks/#{id}/pings", options end
Delete hook
Requires authenticated client.
@param repo [Integer, String, Hash, Repository] A GitHub repository. @param id [Integer] Id of the hook to remove. @return [Boolean] True if hook removed, false otherwise. @see developer.github.com/v3/repos/hooks/#delete-a-hook @example
@client.remove_hook('octokit/octokit.rb', 1000000)
# File lib/octokit/client/hooks.rb, line 133 def remove_hook(repo, id, options = {}) boolean_from_response :delete, "#{Repository.path repo}/hooks/#{id}", options end
Remove org hook
Requires client authenticated as admin for the org.
@param org [String, Integer] Organization
GitHub login or id. @param id [Integer] Id of the hook to update. @return [Boolean] True if hook removed, false otherwise. @see developer.github.com/v3/orgs/hooks/#delete-a-hook @example
@client.remove_org_hook('octokit', 1000000)
# File lib/octokit/client/hooks.rb, line 282 def remove_org_hook(org, id, options = {}) boolean_from_response :delete, "#{Organization.path org}/hooks/#{id}", options end
Test hook
Requires authenticated client.
@param repo [Integer, String, Hash, Repository] A GitHub repository. @param id [Integer] Id of the hook to test. @return [Boolean] Success @see developer.github.com/v3/repos/hooks/#test-a-push-hook @example
@client.test_hook('octokit/octokit.rb', 1000000)
# File lib/octokit/client/hooks.rb, line 147 def test_hook(repo, id, options = {}) boolean_from_response :post, "#{Repository.path repo}/hooks/#{id}/tests", options end