Class: GitHubPr::Poster
- Inherits:
-
Object
- Object
- GitHubPr::Poster
- Defined in:
- lib/github-pr/poster.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#cut_scheme_and_host(url) ⇒ Object
github.com/user/reponame cutting path user/reponame.
-
#initialize(token) ⇒ Poster
constructor
A new instance of Poster.
- #post(options) ⇒ Object
- #postPrivate(client, options) ⇒ Object
Constructor Details
#initialize(token) ⇒ Poster
Returns a new instance of Poster.
5 6 7 |
# File 'lib/github-pr/poster.rb', line 5 def initialize(token) @token = token end |
Class Method Details
.repo_url ⇒ Object
35 36 37 |
# File 'lib/github-pr/poster.rb', line 35 def self.repo_url `git config --get remote.origin.url`.chomp end |
Instance Method Details
#cut_scheme_and_host(url) ⇒ Object
github.com/user/reponame cutting path user/reponame
32 33 34 |
# File 'lib/github-pr/poster.rb', line 32 def cut_scheme_and_host(url) URI::parse(url).path[1..-1] end |
#post(options) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/github-pr/poster.rb', line 9 def post() client = Octokit::Client.new(:access_token => @token.get()) begin postPrivate(client, ) rescue Octokit:: puts 'Unauthorized error, revoking access token' client = Octokit::Client.new(:access_token => @token.get(regenerate: true)) postPrivate(client, ) end end |
#postPrivate(client, options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/github-pr/poster.rb', line 19 def postPrivate(client, ) repo_url = [:url] repo_url = Poster.repo_url() if repo_url.nil? repo = cut_scheme_and_host(repo_url) pull_request = client.create_pull_request(repo, [:base], [:feature], [:title], nil) client.post("/repos/#{repo}/issues/#{pull_request['number']}/assignees", assignees: [[:assign]]) end |