Class: Github::Repos::Hooks

Inherits:
API
  • Object
show all
Defined in:
lib/github_api/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 Github::Request

Github::Request::METHODS, Github::Request::METHODS_WITH_BODIES

Constants included from Connection

Connection::ALLOWED_OPTIONS

Constants included from Constants

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

Constants included from MimeType

MimeType::MEDIA_LOOKUP

Instance Attribute Summary

Attributes inherited from API

#current_options

Attributes included from Authorization

#scopes

Instance Method Summary collapse

Methods inherited from API

#api_methods_in, #append_arguments, #arguments, inherited, #initialize, #method_missing, #process_basic_auth, #set, #setup, #with, #yield_or_eval

Methods included from Github::RateLimit

#ratelimit, #ratelimit_remaining

Methods included from Github::Request

#delete_request, #get_request, #patch_request, #post_request, #put_request, #request

Methods included from Connection

#caching?, #clear_cache, #connection, #default_middleware, #default_options, #stack

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

Inputs

  • :name - Required string - the name of the service that is being called.

  • :config - Required hash - A Hash containing key/value pairs to provide settings for this hook.

  • :events - Optional array - Determines what events the hook is triggered for. Default: [“push”]

  • :active - Optional boolean - Determines whether the hook is actually triggered on pushes.

Examples

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


86
87
88
89
90
91
92
93
# File 'lib/github_api/repos/hooks.rb', line 86

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

  post_request("/repos/#{user}/#{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'


146
147
148
149
150
151
# File 'lib/github_api/repos/hooks.rb', line 146

def delete(*args)
  arguments(args, :required => [:user, :repo, :id])
  params = arguments.params

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

#edit(*args) ⇒ Object

Edit a hook

Inputs

  • :name - Required string - the name of the service that is being called.

  • :config - Required hash - A Hash containing key/value pairs to provide settings for this hook.

  • :events - Optional array - Determines what events the hook is triggered for. This replaces the entire array of events. Default: [“push”].

  • :add_events - Optional array - Determines a list of events to be added to the list of events that the Hook triggers for.

  • :remove_events - Optional array - Determines a list of events to be removed from the list of events that the Hook triggers for.

  • :active - Optional boolean - Determines whether the hook is actually triggered on pushes.

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


116
117
118
119
120
121
122
123
# File 'lib/github_api/repos/hooks.rb', line 116

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

  patch_request("/repos/#{user}/#{repo}/hooks/#{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'


61
62
63
64
65
# File 'lib/github_api/repos/hooks.rb', line 61

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

  get_request("/repos/#{user}/#{repo}/hooks/#{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| ... }


46
47
48
49
50
51
52
# File 'lib/github_api/repos/hooks.rb', line 46

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

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

#test(*args) ⇒ Object

Test a hook

This will trigger the hook with the latest push to the current repository.

Examples

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


133
134
135
136
137
138
# File 'lib/github_api/repos/hooks.rb', line 133

def test(*args)
  arguments(args, :required => [:user, :repo, :id])
  params = arguments.params

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