Class: Github::PullRequests
- Inherits:
-
API
- Object
- API
- Github::PullRequests
- Extended by:
- AutoloadHelper
- Defined in:
- lib/github_api/pull_requests.rb
Defined Under Namespace
Classes: Comments
Constant Summary
- VALID_REQUEST_PARAM_NAMES =
%w[ title body base head state issue commit_message mime_type resource ].freeze
- VALID_REQUEST_PARAM_VALUES =
{ 'state' => %w[ open closed ] }
Constants included from Request
Request::METHODS, Request::METHODS_WITH_BODIES
Constants included from Connection
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
Instance Attribute Summary
Attributes inherited from API
Attributes included from Authorization
Instance Method Summary (collapse)
-
- (Object) comments(options = {}, &block)
Access to PullRequests::Comments API.
-
- (Object) commits(*args)
List commits on a pull request.
-
- (Object) create(*args)
Create a pull request.
-
- (Object) files(*args)
List pull requests files.
-
- (Object) get(*args)
(also: #find)
Get a single pull request.
-
- (Object) list(*args)
(also: #all)
List pull requests.
-
- (Object) merge(*args)
Merge a pull request(Merge Button).
-
- (Boolean) merged?(*args)
Check if pull request has been merged.
-
- (Object) update(*args)
Update a pull request.
Methods included from AutoloadHelper
autoload_all, lookup_constant, register_constant
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 RateLimit
#ratelimit, #ratelimit_remaining
Methods included from 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
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
- (Object) comments(options = {}, &block)
Access to PullRequests::Comments API
27 28 29 |
# File 'lib/github_api/pull_requests.rb', line 27 def comments(={}, &block) @comments ||= ApiFactory.new('PullRequests::Comments', .merge(), &block) end |
- (Object) commits(*args)
List commits on a pull request
Examples
github = Github.new
github.pull_requests.commits 'user-name', 'repo-name', 'number'
135 136 137 138 139 140 141 142 |
# File 'lib/github_api/pull_requests.rb', line 135 def commits(*args) arguments(args, :required => [:user, :repo, :number]) response = get_request("/repos/#{user}/#{repo}/pulls/#{number}/commits", arguments.params) return response unless block_given? response.each { |el| yield el } end |
- (Object) create(*args)
Create a pull request
Inputs
-
:title - Required string
-
:body - Optional string
-
:base - Required string - The branch you want your changes pulled into.
-
:head - Required string - The branch where your changes are implemented.
note: head and base can be either a sha or a branch name. Typically you would namespace head with a user like this: username:branch.
Alternative Input
You can also create a Pull Request from an existing Issue by passing an Issue number instead of title and body.
-
issue - Required number - Issue number in this repository to turn into a Pull Request.
Examples
github = Github.new :oauth_token => '...'
github.pull_requests.create 'user-name', 'repo-name',
"title" => "Amazing new feature",
"body" => "Please pull this in!",
"head" => "octocat:new-feature",
"base" => "master"
alternatively
github.pull_requests.create 'user-name', 'repo-name',
"issue" => "5",
"head" => "octocat:new-feature",
"base" => "master"
98 99 100 101 102 103 104 |
# File 'lib/github_api/pull_requests.rb', line 98 def create(*args) arguments(args, :required => [:user, :repo]) do sift VALID_REQUEST_PARAM_NAMES end post_request("/repos/#{user}/#{repo}/pulls", arguments.params) end |
- (Object) files(*args)
List pull requests files
Examples
github = Github.new
github.pull_requests.files 'user-name', 'repo-name', 'number'
150 151 152 153 154 155 156 157 |
# File 'lib/github_api/pull_requests.rb', line 150 def files(*args) arguments(args, :required => [:user, :repo, :number]) response = get_request("/repos/#{user}/#{repo}/pulls/#{number}/files", arguments.params) return response unless block_given? response.each { |el| yield el } end |
- (Object) get(*args) Also known as: find
Get a single pull request
Examples
github = Github.new
github.pull_requests.get 'user-name', 'repo-name', 'number'
pulls = Github::PullRequests.new
pulls.get 'user-name', 'repo-name', 'number'
62 63 64 65 66 |
# File 'lib/github_api/pull_requests.rb', line 62 def get(*args) arguments(args, :required => [:user, :repo, :number]) get_request("/repos/#{user}/#{repo}/pulls/#{number}", arguments.params) end |
- (Object) list(*args) Also known as: all
List pull requests
Examples
github = Github.new :user => 'user-name', :repo => 'repo-name'
github.pull_requests.list
github.pull_requests.list { |req| ... }
pulls = Github::PullRequests.new
pulls.pull_requests.list 'user-name', 'repo-name'
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/github_api/pull_requests.rb', line 41 def list(*args) arguments(args, :required => [:user, :repo]) do sift VALID_REQUEST_PARAM_NAMES assert_values VALID_REQUEST_PARAM_VALUES end response = get_request("/repos/#{user}/#{repo}/pulls", arguments.params) return response unless block_given? response.each { |el| yield el } end |
- (Object) merge(*args)
Merge a pull request(Merge Button)
Inputs
<tt>:commit_message</tt> - Optional string -
The message that will be used for the merge commit
Examples
github = Github.new
github.pull_requests.merge 'user-name', 'repo-name', 'number'
184 185 186 187 188 189 190 |
# File 'lib/github_api/pull_requests.rb', line 184 def merge(*args) arguments(args, :required => [:user, :repo, :number]) do sift VALID_REQUEST_PARAM_NAMES end put_request("/repos/#{user}/#{repo}/pulls/#{number}/merge", arguments.params) end |
- (Boolean) merged?(*args)
Check if pull request has been merged
Examples
github = Github.new
github.pull_requests.merged? 'user-name', 'repo-name', 'number'
165 166 167 168 169 170 171 172 |
# File 'lib/github_api/pull_requests.rb', line 165 def merged?(*args) arguments(args, :required => [:user, :repo, :number]) get_request("/repos/#{user}/#{repo}/pulls/#{number}/merge", arguments.params) true rescue Github::Error::NotFound false end |
- (Object) update(*args)
Update a pull request
Inputs
-
:title - Optional string
-
:body - Optional string
-
:state - Optional string - State of this Pull Request. Valid values are open and closed.
Examples
github = Github.new :oauth_token => '...'
github.pull_requests.update 'user-name', 'repo-name', 'number'
"title" => "Amazing new title",
"body" => "Update body",
"state" => "open",
120 121 122 123 124 125 126 127 |
# File 'lib/github_api/pull_requests.rb', line 120 def update(*args) arguments(args, :required => [:user, :repo, :number]) do sift VALID_REQUEST_PARAM_NAMES assert_values VALID_REQUEST_PARAM_VALUES end patch_request("/repos/#{user}/#{repo}/pulls/#{number}", arguments.params) end |