Class: Github::PullRequests

Inherits:
Thor
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, CLI::ShellHelpers
Defined in:
lib/github/pull_requests.rb

Instance Method Summary collapse

Methods included from CLI::ShellHelpers

#hr, #width_for_percent

Instance Method Details

#listObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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., time_ago_in_words(Date.parse(pr.updated_at)) + ' ago')
  end
end

#show(number) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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. + ' - ' + 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