class Github::PullRequests

Public Instance Methods

list() click to toggle source
# File lib/github/pull_requests.rb, line 14
def list
  prs = Github::CLI.repository.pull_requests(page: options[:page])
  page_count = prs.count_pages == 0 ? 1 : prs.count_pages

  say "Pull requests for #{Github::CLI.repository.id} (Page #{options[:page]}/#{page_count})"

  title_width = width_for_percent(0.45)
  creator_width = width_for_percent(0.15)
  format_s = "%-8s %-#{title_width}.#{title_width}s %-#{creator_width}s %s"

  say sprintf(format_s, '#', 'Title', 'User', 'Date')
  prs.each do |pr|
    say sprintf(format_s, "##{pr.number}", pr.title, pr.user.login, time_ago_in_words(Date.parse(pr.updated_at)) + ' ago')
  end
end
show(number) click to toggle source
# File lib/github/pull_requests.rb, line 31
def show(number)
  pr = Github::CLI.repository.pull_request(number)

  say "##{number} - #{pr.title}"
  say sprintf("%#{terminal_width}s", "#{pr.user.login} on #{pr.created_at}")
  say hr
  say "#{pr.commits} commits into #{pr.base.ref} from #{pr.head.ref}."
  say hr
  say pr.body.body + "\n"

  commits = Github::CLI.repository.pull_request_commits(number)

  message_width = width_for_percent(0.6) - 1
  commit_width = width_for_percent(0.4)
  format_s = "%-#{message_width}.#{message_width}s %#{commit_width}.#{commit_width}s"
  say hr
  commits.each do |commit|
    say sprintf(format_s, "#{commit.commit.message}", (commit.author.login + ' - ' + commit.commit.tree.sha[0..8]))
  end

  files = Github::CLI.repository.pull_request_files(number)

  files.each_with_index do |file, i|
    say hr
    say "#{file.filename} - #{file.additions}/#{file.changes}/#{file.deletions}"
    say hr
    say "#{file.patch}"
  end
end