123456789_123456789_123456789_123456789_123456789_

Module: Octokit::Client::Hooks

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/octokit/client/hooks.rb

Overview

Methods for the Hooks API

Instance Method Summary

Instance Method Details

#available_hooks(options = {}) ⇒ Sawyer::Resource

List all Service Hooks supported by GitHub

Examples:

List all hooks

Octokit.available_hooks

Returns:

  • (Sawyer::Resource)

    A list of all hooks on GitHub

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/hooks.rb', line 13

def available_hooks(options = {})
  get 'hooks', options
end

#create_hook(repo, name, config, options = {}) ⇒ Sawyer::Resource

Create a hook

Requires authenticated client.

Examples:

@client.create_hook(
  'octokit/octokit.rb',
  'web',
  {
    :url => 'http://something.com/webhook',
    :content_type => 'json'
  },
  {
    :events => ['push', 'pull_request'],
    :active => true
  }
)

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • name (String)

    The name of the service that is being called. See Hooks for the possible names.

  • 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 github-services repo.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :events (Array<String>) — default: '["push"]'

    Determines what events the hook is triggered for.

  • :active (Boolean)

    Determines whether the hook is actually triggered on pushes.

Returns:

  • (Sawyer::Resource)

    Hook info for the new hook

See Also:

[ GitHub ]

  
# 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_org_hook(org, config, options = {}) ⇒ Sawyer::Resource

Create an org hook

Requires client authenticated as admin for the org.

Examples:

@client.create_org_hook(
  'octokit',
  {
    :url => 'http://something.com/webhook',
    :content_type => 'json'
  },
  {
    :events => ['push', 'pull_request'],
    :active => true
  }
)

Parameters:

  • org (String, Integer)

    ::Octokit::Organization GitHub login or id.

  • config (Hash)

    A Hash containing key/value pairs to provide settings for this hook.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :events (Array<String>) — default: '["push"]'

    Determines what events the hook is triggered for.

  • :active (Boolean)

    Determines whether the hook is actually triggered on pushes.

Returns:

  • (Sawyer::Resource)

    Hook info for the new hook

See Also:

[ GitHub ]

  
# 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_hook(repo, id, name, config, options = {}) ⇒ Sawyer::Resource

Edit a hook

Requires authenticated client.

Examples:

@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
  }
)

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Id of the hook being updated.

  • name (String)

    The name of the service that is being called. See Hooks for the possible names.

  • 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 github-services repo.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :events (Array<String>) — default: '["push"]'

    Determines what events the hook is triggered for.

  • :add_events (Array<String>)

    Determines a list of events to be added to the list of events that the Hook triggers for.

  • :remove_events (Array<String>)

    Determines a list of events to be removed from the list of events that the Hook triggers for.

  • :active (Boolean)

    Determines whether the hook is actually triggered on pushes.

Returns:

  • (Sawyer::Resource)

    Hook info for the updated hook

See Also:

[ GitHub ]

  
# 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

#edit_org_hook(org, id, config, options = {}) ⇒ Sawyer::Resource Also known as: #update_org_hook

Update an org hook

Requires client authenticated as admin for the org.

Examples:

@client.edit_org_hook(
  'octokit',
  123,
  {
    :url => 'http://something.com/webhook',
    :content_type => 'json'
  },
  {
    :events => ['push', 'pull_request'],
    :active => true
  }
)

Parameters:

  • org (String, Integer)

    ::Octokit::Organization GitHub login or id.

  • id (Integer)

    Id of the hook to update.

  • config (Hash)

    A Hash containing key/value pairs to provide settings for this hook.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :events (Array<String>) — default: '["push"]'

    Determines what events the hook is triggered for.

  • :active (Boolean)

    Determines whether the hook is actually triggered on pushes.

Returns:

  • (Sawyer::Resource)

    Hook info for the new hook

See Also:

[ GitHub ]

  
# 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

#hook(repo, id, options = {}) ⇒ Sawyer::Resource

Get single hook

Requires authenticated client.

Examples:

@client.hook('octokit/octokit.rb', 100000)

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Id of the hook to get.

Returns:

  • (Sawyer::Resource)

    Hash representing hook.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/hooks.rb', line 40

def hook(repo, id, options = {})
  get "#{Repository.path repo}/hooks/#{id}", options
end

#hooks(repo, options = {}) ⇒ Array<Sawyer::Resource>

List repo hooks

Requires authenticated client.

Examples:

@client.hooks('octokit/octokit.rb')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing hooks.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/hooks.rb', line 26

def hooks(repo, options = {})
  paginate "#{Repository.path repo}/hooks", options
end

#list_org_hooks(org, options = {})

Alias for #org_hooks.

[ GitHub ]

  
# File 'lib/octokit/client/hooks.rb', line 177

alias list_org_hooks org_hooks

#org_hook(org, id, options = {}) ⇒ Sawyer::Resource

Get an org hook

Requires client authenticated as admin for the org.

Examples:

@client.org_hook('octokit', 123)

Parameters:

Returns:

  • (Sawyer::Resource)

    Hash representing hook.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/hooks.rb', line 189

def org_hook(org, id, options = {})
  get "#{Organization.path org}/hooks/#{id}", options
end

#org_hooks(org, options = {}) ⇒ Array<Sawyer::Resource> Also known as: #list_org_hooks

List org hooks

Requires client authenticated as admin for the org.

Examples:

@client.org_hooks('octokit')

Parameters:

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing hooks.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/hooks.rb', line 174

def org_hooks(org, options = {})
  paginate "#{Organization.path org}/hooks", options
end

#parse_payload(payload_string) ⇒ Sawyer::Resource

Parse payload string

Parameters:

  • payload_string (String)

    The payload

Returns:

  • (Sawyer::Resource)

    The payload object

See Also:

[ GitHub ]

  
# 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(repo, id, options = {}) ⇒ Boolean

Ping hook

Requires authenticated client.

Examples:

@client.ping_hook('octokit/octokit.rb', 1000000)

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Id of the hook to send a ping.

Returns:

  • (Boolean)

    Ping requested?

See Also:

[ GitHub ]

  
# 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(org, id, options = {}) ⇒ Boolean

Ping org hook

Requires client authenticated as admin for the org.

Examples:

@client.ping_org_hook('octokit', 1000000)

Parameters:

Returns:

  • (Boolean)

    Success

See Also:

[ GitHub ]

  
# 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

#remove_hook(repo, id, options = {}) ⇒ Boolean

Delete hook

Requires authenticated client.

Examples:

@client.remove_hook('octokit/octokit.rb', 1000000)

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Id of the hook to remove.

Returns:

  • (Boolean)

    True if hook removed, false otherwise.

See Also:

[ GitHub ]

  
# 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(org, id, options = {}) ⇒ Boolean

Remove org hook

Requires client authenticated as admin for the org.

Examples:

@client.remove_org_hook('octokit', 1000000)

Parameters:

Returns:

  • (Boolean)

    True if hook removed, false otherwise.

See Also:

[ GitHub ]

  
# 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(repo, id, options = {}) ⇒ Boolean

Test hook

Requires authenticated client.

Examples:

@client.test_hook('octokit/octokit.rb', 1000000)

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Id of the hook to test.

Returns:

  • (Boolean)

    Success

See Also:

[ GitHub ]

  
# 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

#update_org_hook(org, id, config, options = {})

Alias for #edit_org_hook.

[ GitHub ]

  
# File 'lib/octokit/client/hooks.rb', line 256

alias update_org_hook edit_org_hook