Module: Octokit::Client::Hooks

Included in:
Octokit::Client
Defined in:
lib/octokit/client/hooks.rb

Overview

Methods for the Hooks API

Instance Method Summary collapse

Instance Method Details

#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:



65
66
67
68
# File 'lib/octokit/client/hooks.rb', line 65

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)

    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:



209
210
211
212
# File 'lib/octokit/client/hooks.rb', line 209

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:



108
109
110
111
# File 'lib/octokit/client/hooks.rb', line 108

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)

    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:



242
243
244
245
# File 'lib/octokit/client/hooks.rb', line 242

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:



30
31
32
# File 'lib/octokit/client/hooks.rb', line 30

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:



16
17
18
# File 'lib/octokit/client/hooks.rb', line 16

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

#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:

  • org (String, Integer)

    Organization GitHub login or id.

  • id (Integer)

    Id of the hook to get.

Returns:

  • (Sawyer::Resource)

    Hash representing hook.

See Also:



179
180
181
# File 'lib/octokit/client/hooks.rb', line 179

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:

  • org (String, Integer)

    Organization GitHub login or id.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing hooks.

See Also:



164
165
166
# File 'lib/octokit/client/hooks.rb', line 164

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:



281
282
283
284
# File 'lib/octokit/client/hooks.rb', line 281

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:



151
152
153
# File 'lib/octokit/client/hooks.rb', line 151

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:

  • org (String, Integer)

    Organization GitHub login or id.

  • id (Integer)

    Id of the hook to update.

Returns:

  • (Boolean)

    Success

See Also:



258
259
260
# File 'lib/octokit/client/hooks.rb', line 258

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:



123
124
125
# File 'lib/octokit/client/hooks.rb', line 123

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:

  • org (String, Integer)

    Organization GitHub login or id.

  • id (Integer)

    Id of the hook to update.

Returns:

  • (Boolean)

    True if hook removed, false otherwise.

See Also:



272
273
274
# File 'lib/octokit/client/hooks.rb', line 272

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:



137
138
139
# File 'lib/octokit/client/hooks.rb', line 137

def test_hook(repo, id, options = {})
  boolean_from_response :post, "#{Repository.path repo}/hooks/#{id}/tests", options
end