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

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



13
14
15
# 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:



75
76
77
78
# 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)

    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:



219
220
221
222
# 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:



118
119
120
121
# 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)

    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:



252
253
254
255
# 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:



40
41
42
# 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:



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

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:



189
190
191
# 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:

  • org (String, Integer)

    Organization GitHub login or id.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing hooks.

See Also:



174
175
176
# 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:



291
292
293
294
# 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:



161
162
163
# 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:

  • org (String, Integer)

    Organization GitHub login or id.

  • id (Integer)

    Id of the hook to update.

Returns:

  • (Boolean)

    Success

See Also:



268
269
270
# 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:



133
134
135
# 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:

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



282
283
284
# 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:



147
148
149
# 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