Class: Git::Pr::GitHub
- Inherits:
-
Object
- Object
- Git::Pr::GitHub
- Defined in:
- lib/git/pr/github.rb
Defined Under Namespace
Classes: Failed
Instance Method Summary collapse
-
#initialize(git_properties) ⇒ GitHub
constructor
A new instance of GitHub.
- #list_pull_requests(profile, mine) ⇒ Object
- #submit_pull_request(title, message) ⇒ Object
Constructor Details
#initialize(git_properties) ⇒ GitHub
Returns a new instance of GitHub.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/git/pr/github.rb', line 8 def initialize(git_properties) @git = git_properties Octokit.configure do |c| c.login = @git.login c.password = @git.api_token c.api_endpoint = @git.api_endpoint unless @git.api_endpoint.empty? c.auto_paginate = true end end |
Instance Method Details
#list_pull_requests(profile, mine) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/git/pr/github.rb', line 19 def list_pull_requests(profile, mine) if profile repositories = profile == :all ? all_repositories : @git.repository_profile(profile) else repositories = [@git.repository] end [].tap do |prs| repositories.flatten.uniq.each do |repo| pull_requests = Octokit.pull_requests(repo, 'open') if mine prs << pull_requests.select { |pr| pr.user.login == @git.login } else prs << pull_requests end end end.flatten end |
#submit_pull_request(title, message) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/git/pr/github.rb', line 39 def submit_pull_request(title, ) response = Octokit.create_pull_request(@git.repository, @git.base_branch, @git.current_branch, title, ) response.state == 'open' ? response : raise(Failed, response.state) rescue Octokit::UnprocessableEntity => e = e..match(/message: (.*)/)[1].sub(/ \/\/.*/, '') raise Failed, end |