Class: OctocatHerder::PullRequest
- Inherits:
-
Object
- Object
- OctocatHerder::PullRequest
- Includes:
- Base
- Defined in:
- lib/octocat_herder/pull_request.rb,
lib/octocat_herder/pull_request/repo.rb
Overview
Interface to the GitHub v3 API for interacting with pull requests.
Currently, this only supports retrieval of information about the pull request itself, not the comments, or any updating/creation.
Defined Under Namespace
Classes: Repo
Instance Attribute Summary
Attributes included from Base
Class Method Summary collapse
-
.fetch(owner_login, repository_name, pull_request_number, conn = OctocatHerder::Connection.new) ⇒ OctocatHerder::PullRequest
Query information about a specific pull request.
-
.find_closed_for_repository(owner_login, repository_name, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::PullRequest>
Query the closed pull requests for a given repository.
-
.find_for_repository(owner_login, repository_name, status = 'open', conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::PullRequest>
Query either the open or closed pull requests for a given repository.
-
.find_open_for_repository(owner_login, repository_name, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::PullRequest>
Query the open pull requests for a given repository.
Instance Method Summary collapse
-
#base ⇒ OctocatHerder::PullRequest::Repo
Information about what the pull request was based on in the pull request.
-
#closed_at ⇒ Time?
When the pull request was closed, or
nil
if it is still open. -
#created_at ⇒ Time
When the pull request was first created.
-
#diff_text ⇒ String
The diff introduced by all of the commits in the pull request.
-
#get_detail ⇒ self
Get the full pull request details.
-
#head ⇒ OctocatHerder::PullRequest::Repo
Information about what is being asked to be merged in the pull request.
-
#initialize(raw_hash, raw_detail_hash = nil, conn = OctocatHerder::Connection.new) ⇒ PullRequest
constructor
private
A new instance of PullRequest.
-
#merged_at ⇒ Time?
When the pull request was merged, or
nil
if it hasn’t been merged. -
#merged_by ⇒ OctocatHerder::User?
The user that merged the pull request, or
nil
if it has not been merged yet. -
#merged_by_avatar_url ⇒ String?
The URL to the avatar image of the person that merged the pull request, or
nil
if it has not been merged yet. -
#merged_by_id ⇒ String?
The ID number of the person that merged the pull request, or
nil
if it has not been merged yet. -
#merged_by_login ⇒ String?
The login name of the person that merged the pull request, or
nil
if it has not been merged yet. -
#merged_by_url ⇒ String?
The URL of the person that merged the pull request, or
nil
if it has not been merged yet. -
#method_missing(id, *args) ⇒ String
Check the “normal” place first for the information returned by the GitHub API, then check @raw_detail_hash (populating it if needed).
-
#patch_text ⇒ String
The pull request as a single patch, with the pull request title & body as the commit message, and the total diff as the patch.
-
#to_hash ⇒ Hash
A Hash representation of the pull request.
-
#updated_at ⇒ Time
When the pull request was last updated.
-
#user ⇒ OctocatHerder::User
The user that opened the pull request.
-
#user_avatar_url ⇒ String
The URL to the avatar image of the person that opened the pull request.
-
#user_id ⇒ Integer
The ID number of the person that opened the pull request.
-
#user_login ⇒ String
The login name of the person that opened the pull request.
-
#user_url ⇒ String
The URL of the person that opened the pull request.
Methods included from Base
Constructor Details
#initialize(raw_hash, raw_detail_hash = nil, conn = OctocatHerder::Connection.new) ⇒ PullRequest
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of PullRequest.
85 86 87 88 |
# File 'lib/octocat_herder/pull_request.rb', line 85 def initialize(raw_hash, raw_detail_hash = nil, conn = OctocatHerder::Connection.new) super raw_hash, conn @raw_detail_hash = raw_detail_hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args) ⇒ String
Check the “normal” place first for the information returned by the GitHub API, then check @raw_detail_hash (populating it if needed).
116 117 118 119 120 121 122 123 |
# File 'lib/octocat_herder/pull_request.rb', line 116 def method_missing(id, *args) super rescue NoMethodError => e get_detail return @raw_detail_hash[id.id2name] if @raw_detail_hash and @raw_detail_hash.keys.include?(id.id2name) raise e end |
Class Method Details
.fetch(owner_login, repository_name, pull_request_number, conn = OctocatHerder::Connection.new) ⇒ OctocatHerder::PullRequest
Query information about a specific pull request.
71 72 73 74 75 76 77 78 |
# File 'lib/octocat_herder/pull_request.rb', line 71 def self.fetch(owner_login, repository_name, pull_request_number, conn = OctocatHerder::Connection.new) request = conn.get( "/repos/#{CGI.escape(owner_login.to_s)}/#{CGI.escape(repository_name.to_s)}/pulls/#{CGI.escape(pull_request_number.to_s)}", :headers => { 'Accept' => 'application/vnd.github-pull.full+json' } ) new(nil, request, conn) end |
.find_closed_for_repository(owner_login, repository_name, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::PullRequest>
Query the closed pull requests for a given repository.
59 60 61 |
# File 'lib/octocat_herder/pull_request.rb', line 59 def self.find_closed_for_repository(owner_login, repository_name, conn = OctocatHerder::Connection.new) OctocatHerder::PullRequest.find_for_repository(owner_login, repository_name, 'closed', conn) end |
.find_for_repository(owner_login, repository_name, status = 'open', conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::PullRequest>
Query either the open or closed pull requests for a given repository.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/octocat_herder/pull_request.rb', line 25 def self.find_for_repository(owner_login, repository_name, status = 'open', conn = OctocatHerder::Connection.new) raise ArgumentError.new("Unknown PullRequest status '#{status}'. Must be one of ['open', 'closed'].") unless ['open', 'closed'].include? status pull_requests = conn.get( "/repos/#{CGI.escape(owner_login.to_s)}/#{CGI.escape(repository_name.to_s)}/pulls", :paginated => true, :params => { :state => status }, :headers => { 'Accept' => 'application/vnd.github-pull.full+json' } ) pull_requests.map do |pull| new(pull, nil, conn) end end |
.find_open_for_repository(owner_login, repository_name, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::PullRequest>
Query the open pull requests for a given repository.
48 49 50 |
# File 'lib/octocat_herder/pull_request.rb', line 48 def self.find_open_for_repository(owner_login, repository_name, conn = OctocatHerder::Connection.new) OctocatHerder::PullRequest.find_for_repository(owner_login, repository_name, 'open', conn) end |
Instance Method Details
#base ⇒ OctocatHerder::PullRequest::Repo
Information about what the pull request was based on in the pull request.
288 289 290 291 292 |
# File 'lib/octocat_herder/pull_request.rb', line 288 def base get_detail @base_repo ||= OctocatHerder::PullRequest::Repo.new(@raw_detail_hash['base'], connection) end |
#closed_at ⇒ Time?
When the pull request was closed, or nil
if it is still open.
260 261 262 |
# File 'lib/octocat_herder/pull_request.rb', line 260 def closed_at parse_date_time(@raw_detail_hash['closed_at']) end |
#created_at ⇒ Time
When the pull request was first created.
244 245 246 |
# File 'lib/octocat_herder/pull_request.rb', line 244 def created_at parse_date_time(@raw_detail_hash['created_at']) end |
#diff_text ⇒ String
The diff introduced by all of the commits in the pull request.
323 324 325 |
# File 'lib/octocat_herder/pull_request.rb', line 323 def diff_text @diff_text ||= connection.raw_get(diff_url).body end |
#get_detail ⇒ self
Get the full pull request details. When retrieved from .find_for_repository, .find_open_for_repository, or .find_closed_for_repository not all of the details of the pull request are available since GitHub doesn’t return them in the listing. This will query information about the specific pull request, which will get us all of the available details.
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/octocat_herder/pull_request.rb', line 99 def get_detail return if @raw_detail_hash @raw_detail_hash = connection.get( url, :headers => { 'Accept' => 'application/vnd.github-pull.full+json' } ) self end |
#head ⇒ OctocatHerder::PullRequest::Repo
Information about what is being asked to be merged in the pull request.
277 278 279 280 281 |
# File 'lib/octocat_herder/pull_request.rb', line 277 def head get_detail @head_repo ||= OctocatHerder::PullRequest::Repo.new(@raw_detail_hash['head'], connection) end |
#merged_at ⇒ Time?
When the pull request was merged, or nil
if it hasn’t been merged.
268 269 270 |
# File 'lib/octocat_herder/pull_request.rb', line 268 def merged_at parse_date_time(@raw_detail_hash['merged_at']) end |
#merged_by ⇒ OctocatHerder::User?
This is cached locally to the individual pull request, but will make an additional API request to populate it initially.
The user that merged the pull request, or nil
if it has not been merged yet.
234 235 236 237 238 |
# File 'lib/octocat_herder/pull_request.rb', line 234 def merged_by return nil unless merged @merged_by ||= OctocatHerder::User.fetch(merged_by_login, connection) end |
#merged_by_avatar_url ⇒ String?
The URL to the avatar image of the person that merged the pull request, or nil
if it has not been merged yet.
208 209 210 211 212 213 |
# File 'lib/octocat_herder/pull_request.rb', line 208 def merged_by_avatar_url return nil unless merged get_detail @raw_detail_hash['merged_by']['avatar_url'] end |
#merged_by_id ⇒ String?
The ID number of the person that merged the pull request, or nil
if it has not been merged yet.
196 197 198 199 200 201 |
# File 'lib/octocat_herder/pull_request.rb', line 196 def merged_by_id return nil unless merged get_detail @raw_detail_hash['merged_by']['id'] end |
#merged_by_login ⇒ String?
The login name of the person that merged the pull request, or nil
if it has not been merged yet.
184 185 186 187 188 189 |
# File 'lib/octocat_herder/pull_request.rb', line 184 def merged_by_login return nil unless merged get_detail @raw_detail_hash['merged_by']['login'] end |
#merged_by_url ⇒ String?
The URL of the person that merged the pull request, or nil
if it has not been merged yet.
220 221 222 223 224 225 |
# File 'lib/octocat_herder/pull_request.rb', line 220 def merged_by_url return nil unless merged get_detail @raw_detail_hash['merged_by']['url'] end |
#patch_text ⇒ String
The pull request as a single patch, with the pull request title & body as the commit message, and the total diff as the patch.
315 316 317 |
# File 'lib/octocat_herder/pull_request.rb', line 315 def patch_text @patch_text ||= connection.raw_get(patch_url).body end |
#to_hash ⇒ Hash
A Hash representation of the pull request. Combines @raw, and @raw_detail_hash into a single hash.
299 300 301 302 303 304 305 306 307 308 |
# File 'lib/octocat_herder/pull_request.rb', line 299 def to_hash raw = @raw || {} detail = @raw_detail_hash || {} ret = raw.merge(detail) ret['patch_text'] = patch_text ret['diff_text'] = diff_text ret end |
#updated_at ⇒ Time
When the pull request was last updated.
252 253 254 |
# File 'lib/octocat_herder/pull_request.rb', line 252 def updated_at parse_date_time(@raw_detail_hash['updated_at']) end |
#user ⇒ OctocatHerder::User
This is cached locally to the individual pull request, but will make an additional API request to populate it initially.
The user that opened the pull request.
175 176 177 |
# File 'lib/octocat_herder/pull_request.rb', line 175 def user @user ||= OctocatHerder::User.fetch(user_login, connection) end |
#user_avatar_url ⇒ String
Since this is returned by the pull request API itself, this can be used without making an additional API request.
The URL to the avatar image of the person that opened the pull request.
131 132 133 134 |
# File 'lib/octocat_herder/pull_request.rb', line 131 def user_avatar_url return @raw['user']['avatar_url'] if @raw @raw_detail_hash['user']['avatar_url'] end |
#user_id ⇒ Integer
Since this is returned by the pull request API itself, this can be used without making an additional API request.
The ID number of the person that opened the pull request.
153 154 155 156 |
# File 'lib/octocat_herder/pull_request.rb', line 153 def user_id return @raw['user']['id'] if @raw @raw_detail_hash['user']['id'] end |
#user_login ⇒ String
Since this is returned by the pull request API itself, this can be used without making an additional API request.
The login name of the person that opened the pull request.
164 165 166 167 |
# File 'lib/octocat_herder/pull_request.rb', line 164 def user_login return @raw['user']['login'] if @raw @raw_detail_hash['user']['login'] end |
#user_url ⇒ String
Since this is returned by the pull request API itself, this can be used without making an additional API request.
The URL of the person that opened the pull request.
142 143 144 145 |
# File 'lib/octocat_herder/pull_request.rb', line 142 def user_url return @raw['user']['url'] if @raw @raw_detail_hash['user']['url'] end |