Class: Github::PullRequests
Defined Under Namespace
Classes: Comments
Constant Summary collapse
- 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
-
#comments(options = {}, &block) ⇒ Object
Access to PullRequests::Comments API.
-
#commits(*args) ⇒ Object
List commits on a pull request.
-
#create(*args) ⇒ Object
Create a pull request.
-
#files(*args) ⇒ Object
List pull requests files.
-
#get(*args) ⇒ Object
(also: #find)
Get a single pull request.
-
#list(*args) ⇒ Object
(also: #all)
List pull requests.
-
#merge(*args) ⇒ Object
Merge a pull request(Merge Button).
-
#merged?(*args) ⇒ Boolean
Check if pull request has been merged.
-
#update(*args) ⇒ Object
Update a pull request.
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
#comments(options = {}, &block) ⇒ Object
Access to PullRequests::Comments API
26 27 28 |
# File 'lib/github_api/pull_requests.rb', line 26 def comments(={}, &block) @comments ||= ApiFactory.new('PullRequests::Comments', .merge(), &block) end |
#commits(*args) ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/github_api/pull_requests.rb', line 134 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 |
#create(*args) ⇒ Object
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"
97 98 99 100 101 102 103 |
# File 'lib/github_api/pull_requests.rb', line 97 def create(*args) arguments(args, :required => [:user, :repo]) do sift VALID_REQUEST_PARAM_NAMES end post_request("/repos/#{user}/#{repo}/pulls", arguments.params) end |
#files(*args) ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'lib/github_api/pull_requests.rb', line 149 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 |
#get(*args) ⇒ Object 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'
61 62 63 64 65 |
# File 'lib/github_api/pull_requests.rb', line 61 def get(*args) arguments(args, :required => [:user, :repo, :number]) get_request("/repos/#{user}/#{repo}/pulls/#{number}", arguments.params) end |
#list(*args) ⇒ Object 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'
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/github_api/pull_requests.rb', line 40 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 |
#merge(*args) ⇒ Object
183 184 185 186 187 188 189 |
# File 'lib/github_api/pull_requests.rb', line 183 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 |
#merged?(*args) ⇒ Boolean
164 165 166 167 168 169 170 171 |
# File 'lib/github_api/pull_requests.rb', line 164 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 |
#update(*args) ⇒ Object
Update a pull request
Inputs
-
:title
- Optional string -
:body
- Optional string -
:state
- Optional string - State of this Pull Request. Valid values areopen
andclosed
.
Examples
github = Github.new :oauth_token => '...'
github.pull_requests.update 'user-name', 'repo-name', 'number'
"title" => "Amazing new title",
"body" => "Update body",
"state" => "open",
119 120 121 122 123 124 125 126 |
# File 'lib/github_api/pull_requests.rb', line 119 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 |