class GitHubPr::Poster

Public Class Methods

new(token) click to toggle source
# File lib/github-pr/poster.rb, line 5
def initialize(token)
        @token = token
end
repo_url() click to toggle source
# File lib/github-pr/poster.rb, line 35
def self.repo_url
     `git config --get remote.origin.url`.chomp
end

Public Instance Methods

cut_scheme_and_host(url) click to toggle source

github.com/user/reponame cutting path user/reponame

# File lib/github-pr/poster.rb, line 32
def cut_scheme_and_host(url)
     URI::parse(url).path[1..-1]
end
post(options) click to toggle source
# File lib/github-pr/poster.rb, line 9
def post(options)
        client = Octokit::Client.new(:access_token => @token.get())
        begin
                postPrivate(client, options)
        rescue Octokit::Unauthorized
                puts 'Unauthorized error, revoking access token'
                client = Octokit::Client.new(:access_token => @token.get(regenerate: true))
                postPrivate(client, options)
        end
end
postPrivate(client, options) click to toggle source
# File lib/github-pr/poster.rb, line 19
def postPrivate(client, options)
        repo_url = options[:url]
        repo_url = Poster.repo_url() if repo_url.nil?
        repo = cut_scheme_and_host(repo_url)
        pull_request = client.create_pull_request(repo, 
                options[:base],
                options[:feature], 
                options[:title], nil)
        client.post("/repos/#{repo}/issues/#{pull_request['number']}/assignees", 
                assignees: [options[:assign]])
end