Module: Octokit::Client::Hooks

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

Overview

Methods for the Hooks API

Constant Summary

ORG_HOOKS_PREVIEW_MEDIA_TYPE =
"application/vnd.github.sersi-preview+json".freeze

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

See Also:



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

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

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.

See Also:



77
78
79
80
# File 'lib/octokit/client/hooks.rb', line 77

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

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.

See Also:



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

def create_org_hook(org, config, options = {})
  options = ensure_org_hooks_api_media_type(options)
  options = { :name => "web", :config => config }.merge(options)
  post "orgs/#{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
  }
)

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.

See Also:



120
121
122
123
# File 'lib/octokit/client/hooks.rb', line 120

def edit_hook(repo, id, name, config, options = {})
  options = {:name => name, :config => config, :events => ["push"], :active => true}.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
  }
)

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.

See Also:



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

def edit_org_hook(org, id, config, options = {})
  options = ensure_org_hooks_api_media_type(options)
  options = { :config => config }.merge(options)
  patch "orgs/#{org}/hooks/#{id}", options
end

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

Get single hook

Requires authenticated client.

Examples:

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

See Also:



42
43
44
# File 'lib/octokit/client/hooks.rb', line 42

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')

See Also:



28
29
30
# File 'lib/octokit/client/hooks.rb', line 28

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)

See Also:



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

def org_hook(org, id, options = {})
  options = ensure_org_hooks_api_media_type(options)
  get "orgs/#{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')

See Also:



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

def org_hooks(org, options = {})
  options = ensure_org_hooks_api_media_type(options)
  paginate "orgs/#{org}/hooks", 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)

See Also:



260
261
262
263
# File 'lib/octokit/client/hooks.rb', line 260

def ping_org_hook(org, id, options = {})
  options = ensure_org_hooks_api_media_type(options)
  boolean_from_response :post, "orgs/#{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)

See Also:



135
136
137
# File 'lib/octokit/client/hooks.rb', line 135

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)

See Also:



275
276
277
278
# File 'lib/octokit/client/hooks.rb', line 275

def remove_org_hook(org, id, options = {})
  options = ensure_org_hooks_api_media_type(options)
  boolean_from_response :delete, "orgs/#{org}/hooks/#{id}", options
end

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

Test hook

Requires authenticated client.

Examples:

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

See Also:



149
150
151
# File 'lib/octokit/client/hooks.rb', line 149

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