Class: GitHub::PullRequest
- Inherits:
-
Object
- Object
- GitHub::PullRequest
- Defined in:
- lib/git-process/github_pull_request.rb
Defined Under Namespace
Classes: NotFoundError
Constant Summary collapse
- MAX_RESEND =
5
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#gitlib ⇒ Object
readonly
Returns the value of attribute gitlib.
-
#remote_name ⇒ Object
readonly
Returns the value of attribute remote_name.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #client ⇒ Object
- #close(*args) ⇒ Object
-
#create(base, head, title, body) ⇒ Hash
Create a pull request.
-
#find_pull_request(base, head, error_if_missing = false) ⇒ Hash?
Find the pull request (PR) that matches the ‘head’ and ‘base’.
-
#get_pull_request(base, head) ⇒ Hash
Find the pull request (PR) that matches the ‘head’ and ‘base’.
-
#initialize(lib, remote_name, repo, opts = {}) ⇒ PullRequest
constructor
A new instance of PullRequest.
- #logger ⇒ Object
- #pull_request(pr_number) ⇒ Object
- #pull_requests(opts = {}) ⇒ Object
Constructor Details
#initialize(lib, remote_name, repo, opts = {}) ⇒ PullRequest
Returns a new instance of PullRequest.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/git-process/github_pull_request.rb', line 25 def initialize(lib, remote_name, repo, opts = {}) @gitlib = lib @repo = repo @remote_name = remote_name @configuration = GitHubService::Configuration.new( gitlib.config, :user => opts[:user], :password => opts[:password], :remote_name => remote_name ) end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
21 22 23 |
# File 'lib/git-process/github_pull_request.rb', line 21 def configuration @configuration end |
#gitlib ⇒ Object (readonly)
Returns the value of attribute gitlib.
21 22 23 |
# File 'lib/git-process/github_pull_request.rb', line 21 def gitlib @gitlib end |
#remote_name ⇒ Object (readonly)
Returns the value of attribute remote_name.
21 22 23 |
# File 'lib/git-process/github_pull_request.rb', line 21 def remote_name @remote_name end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
21 22 23 |
# File 'lib/git-process/github_pull_request.rb', line 21 def repo @repo end |
Instance Method Details
#client ⇒ Object
38 39 40 |
# File 'lib/git-process/github_pull_request.rb', line 38 def client @configuration.client end |
#close(*args) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/git-process/github_pull_request.rb', line 126 def close(*args) pull_number = if args.size == 2 get_pull_request(args[0], args[1])[:number] elsif args.size == 1 args[0] else raise ArgumentError.new('close(..) needs 1 or 2 arguments') end logger.info { "Closing a pull request \##{pull_number} on #{repo}." } send_close_req(pull_number, 1) end |
#create(base, head, title, body) ⇒ Hash
Create a pull request
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/git-process/github_pull_request.rb', line 62 def create(base, head, title, body) logger.info { "Creating a pull request asking for '#{head}' to be merged into '#{base}' on #{repo}." } begin return sym_hash_JSON(client.create_pull_request(repo, base, head, title, body)) rescue Octokit::UnprocessableEntity => exp pull = pull_requests.find { |p| p[:head][:ref] == head and p[:base][:ref] == base } if pull logger.warn { "Pull request already exists. See #{pull[:html_url]}" } else logger.warn { "UnprocessableEntity: #{exp}" } end return pull end end |
#find_pull_request(base, head, error_if_missing = false) ⇒ Hash?
Find the pull request (PR) that matches the ‘head’ and ‘base’.
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/git-process/github_pull_request.rb', line 112 def find_pull_request(base, head, error_if_missing = false) logger.info { "Looking for a pull request asking for '#{head}' to be merged into '#{base}' on #{repo}." } json = pull_requests pr = json.find do |p| p[:head][:ref] == head and p[:base][:ref] == base end raise NotFoundError.new(base, head, repo, json) if error_if_missing && pr.nil? pr end |
#get_pull_request(base, head) ⇒ Hash
Find the pull request (PR) that matches the ‘head’ and ‘base’.
97 98 99 |
# File 'lib/git-process/github_pull_request.rb', line 97 def get_pull_request(base, head) find_pull_request(base, head, true) end |
#logger ⇒ Object
78 79 80 |
# File 'lib/git-process/github_pull_request.rb', line 78 def logger @gitlib.logger end |
#pull_request(pr_number) ⇒ Object
83 84 85 |
# File 'lib/git-process/github_pull_request.rb', line 83 def pull_request(pr_number) sym_hash_JSON(client.pull_request(repo, pr_number)) end |
#pull_requests(opts = {}) ⇒ Object
43 44 45 |
# File 'lib/git-process/github_pull_request.rb', line 43 def pull_requests(opts = {}) @pull_requests ||= sym_hash_JSON(client.pull_requests(repo, opts)) end |