Class: Github::Client::Repos::Hooks

Inherits:
API
  • Object
show all
Defined in:
lib/github_api/client/repos/hooks.rb

Overview

The Repository Hooks API manages the post-receive web and service hooks for a repository.

Constant Summary collapse

VALID_HOOK_PARAM_NAMES =
%w[
  name
  config
  active
  events
  add_events
  remove_events
].freeze
VALID_HOOK_PARAM_VALUES =

Active hooks can be configured to trigger for one or more events. The default event is push. The available events are:

{
  'events' => %w[
    push
    issues
    issue_comment
    commit_comment
    pull_request
    gollum
    watch
    download
    fork
    fork_apply
    member
    public
  ]
}.freeze
REQUIRED_PARAMS =

:nodoc:

%w[ name config ].freeze

Constants included from MimeType

MimeType::MEDIA_LOOKUP

Constants included from Github::Constants

Github::Constants::ACCEPT, Github::Constants::ACCEPTED_OAUTH_SCOPES, Github::Constants::ACCEPT_CHARSET, Github::Constants::CACHE_CONTROL, Github::Constants::CONTENT_LENGTH, Github::Constants::CONTENT_TYPE, Github::Constants::DATE, Github::Constants::ETAG, Github::Constants::HEADER_LAST, Github::Constants::HEADER_LINK, Github::Constants::HEADER_NEXT, Github::Constants::LOCATION, Github::Constants::META_FIRST, Github::Constants::META_LAST, Github::Constants::META_NEXT, Github::Constants::META_PREV, Github::Constants::META_REL, Github::Constants::OAUTH_SCOPES, Github::Constants::PARAM_PAGE, Github::Constants::PARAM_PER_PAGE, Github::Constants::PARAM_START_PAGE, Github::Constants::RATELIMIT_LIMIT, Github::Constants::RATELIMIT_REMAINING, Github::Constants::RATELIMIT_RESET, Github::Constants::SERVER, Github::Constants::USER_AGENT

Instance Attribute Summary

Attributes inherited from API

#current_options

Instance Method Summary collapse

Methods inherited from API

after_callbacks, after_request, #api_methods_in, #arguments, before_callbacks, before_request, clear_request_methods!, #disable_redirects, #execute, extend_with_actions, extra_methods, #extract_basic_auth, extract_class_name, #filter_callbacks, inherited, #initialize, internal_methods, method_added, #method_missing, #module_methods_in, namespace, request_methods, require_all, #respond_to?, root!, #run_callbacks, #set, #yield_or_eval

Methods included from Request::Verbs

#delete_request, #get_request, #head_request, #options_request, #patch_request, #post_request, #put_request

Methods included from RateLimit

#ratelimit, #ratelimit_remaining, #ratelimit_reset

Methods included from MimeType

#lookup_media, #parse

Methods included from Authorization

#auth_code, #authenticated?, #authentication, #authorize_url, #basic_authed?, #client, #get_token

Constructor Details

This class inherits a constructor from Github::API

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Github::API

Instance Method Details

#create(*args) ⇒ Object

Create a hook

To create a webhook, the following fields are required by the config:

Examples:

github = Github.new
github.repos.hooks.create 'user-name', 'repo-name',
  name:  "web",
  active: true,
  config: {
    url: "http://something.com/webhook"
  }
}

Parameters:


118
119
120
121
122
123
124
125
# File 'lib/github_api/client/repos/hooks.rb', line 118

def create(*args)
  arguments(args, required: [:user, :repo]) do
    permit VALID_HOOK_PARAM_NAMES, recursive: false
    assert_required REQUIRED_PARAMS
  end

  post_request("/repos/#{arguments.user}/#{arguments.repo}/hooks", arguments.params)
end

#delete(*args) ⇒ Object

Delete a hook

Examples:

github = Github.new
github.repos.hooks.delete 'user-name', 'repo-name', 'hook-id'

208
209
210
211
212
# File 'lib/github_api/client/repos/hooks.rb', line 208

def delete(*args)
  arguments(args, required: [:user, :repo, :id])

  delete_request("/repos/#{arguments.user}/#{arguments.repo}/hooks/#{arguments.id}", arguments.params)
end

#edit(*args) ⇒ Object

Edit a hook

Examples:

github = Github.new
github.repos.hooks.edit 'user-name', 'repo-name', 'hook-id',
  "name" => "campfire",
  "active" =>  true,
  "config" =>  {
    "subdomain" => "github",
    "room" =>  "Commits",
    "token" => "abc123"
  }

Parameters:


159
160
161
162
163
164
165
166
# File 'lib/github_api/client/repos/hooks.rb', line 159

def edit(*args)
  arguments(args, required: [:user, :repo, :id]) do
    permit VALID_HOOK_PARAM_NAMES, recursive: false
    assert_required REQUIRED_PARAMS
  end

  patch_request("/repos/#{arguments.user}/#{arguments.repo}/hooks/#{arguments.id}", arguments.params)
end

#get(*args) ⇒ Object Also known as: find

Get a single hook

Examples:

github = Github.new
github.repos.hooks.get 'user-name', 'repo-name', 'hook-id'

64
65
66
67
68
# File 'lib/github_api/client/repos/hooks.rb', line 64

def get(*args)
  arguments(args, required: [:user, :repo, :id])

  get_request("/repos/#{arguments.user}/#{arguments.repo}/hooks/#{arguments.id}", arguments.params)
end

#list(*args) ⇒ Object Also known as: all

List repository hooks

Examples:

github = Github.new
github.repos.hooks.list 'user-name', 'repo-name'
github.repos.hooks.list 'user-name', 'repo-name' { |hook| ... }

48
49
50
51
52
53
54
# File 'lib/github_api/client/repos/hooks.rb', line 48

def list(*args)
  arguments(args, required: [:user, :repo])

  response = get_request("/repos/#{arguments.user}/#{arguments.repo}/hooks", arguments.params)
  return response unless block_given?
  response.each { |el| yield el }
end

#ping(*args) ⇒ Object

Ping a hook

This will trigger a ping event to be sent to the hook.

Examples:

github = Github.new
github.repos.hooks.ping 'user-name', 'repo-name', 'hook-id'

195
196
197
198
199
# File 'lib/github_api/client/repos/hooks.rb', line 195

def ping(*args)
  arguments(args, required: [:user, :repo, :id])

  post_request("/repos/#{arguments.user}/#{arguments.repo}/hooks/#{arguments.id}/pings", arguments.params)
end

#test(*args) ⇒ Object

Test a hook

This will trigger the hook with the latest push to the current repository if the hook is subscribed to push events. If the hook is not subscribed to push events, the server will respond with 204 but no test POST will be generated.

Examples:

github = Github.new
github.repos.hooks.test 'user-name', 'repo-name', 'hook-id'

180
181
182
183
184
# File 'lib/github_api/client/repos/hooks.rb', line 180

def test(*args)
  arguments(args, required: [:user, :repo, :id])

  post_request("/repos/#{arguments.user}/#{arguments.repo}/hooks/#{arguments.id}/tests", arguments.params)
end