class Git::Pr
Constants
- VERSION
Public Class Methods
new(args)
click to toggle source
# File lib/git/pr.rb, line 12 def initialize(args) @args = args @github = GitHub.new(GitProperties.new) end
run(args)
click to toggle source
# File lib/git/pr.rb, line 8 def self.run(args) new(args).run end
Public Instance Methods
list()
click to toggle source
# File lib/git/pr.rb, line 28 def list prs = @github.list_pull_requests(@options.profile, @options.mine) puts formatted(prs) end
run()
click to toggle source
# File lib/git/pr.rb, line 17 def run @options = CliOptions.parse(@args) if self.respond_to?(@options.subcommand) self.send(@options.subcommand) else be_helpful end rescue CliOptions::Invalid => e be_helpful(e.message) end
submit()
click to toggle source
# File lib/git/pr.rb, line 33 def submit pr = @github.submit_pull_request(@options.title, @options.message) puts "Opened new pull request to merge #{pr.head.ref} into #{pr.base.repo.full_name}/#{pr.base.ref}" rescue GitHub::Failed => e $stderr.puts "Failed to open new pull request: #{e.message}" exit 1 end
version()
click to toggle source
# File lib/git/pr.rb, line 41 def version puts Git::Pr::VERSION end
Private Instance Methods
be_helpful(message = nil)
click to toggle source
# File lib/git/pr.rb, line 46 def be_helpful(message = nil) puts message if message puts <<-USAGE Usage: git pr list [options] or: git pr submit [options] or: git pr version USAGE end
command_exists?(command)
click to toggle source
# File lib/git/pr.rb, line 59 def command_exists?(command) ENV['PATH'].split(File::PATH_SEPARATOR).any? do |dir| File.exists?(File.join(dir, command)) end end
formatted(prs)
click to toggle source
# File lib/git/pr.rb, line 65 def formatted(prs) if prs.empty? 'No open pull requests' else prs.map do |pr| message = "#{pr.base.repo.full_name}: #{pr.title} -- (#{pr.user.login})" link = " #{pr._links.html.href} ".rjust(terminal_size - message.size) message + link end.join("\n") end end
terminal_size()
click to toggle source
# File lib/git/pr.rb, line 55 def terminal_size command_exists?('tput') ? `tput cols`.to_i : 80 end