Class: Reaper::CLI
- Inherits:
-
Object
- Object
- Reaper::CLI
- Defined in:
- lib/github-reaper.rb
Instance Method Summary collapse
-
#initialize(opts) ⇒ CLI
constructor
A new instance of CLI.
- #issue_action(issue, action_label, skip_confirm = false, show_title = true, &blk) ⇒ Object
- #run! ⇒ Object
Constructor Details
Instance Method Details
#issue_action(issue, action_label, skip_confirm = false, show_title = true, &blk) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/github-reaper.rb', line 99 def issue_action(issue, action_label, skip_confirm=false, show_title=true, &blk) return yield issue if skip_confirm puts "= Issue ##{issue.number}: #{issue.title}".white if show_title print "#{action_label} [Y]es, [N]o, or n[E]ver: ".yellow input = $stdin.gets.chomp.downcase case input when 'y' yield issue when 'n' puts "OK, skipping.".red when 'e' issue.protect puts "OK, added `do-not-reap`.".green else issue_action(issue, action_label, false, &blk) end end |
#run! ⇒ Object
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/github-reaper.rb', line 33 def run! now = Time.now puts "Welcome to Reaper! ⟝⦆ (fetching from `#{@client.repo}`)".white.bold issues_reaped = false # Fetch to-reap issues. = { labels: 'to-reap' } puts "Finding issues to reap..." issues = @client.list_issues() issues.each do |issue| issues_reaped = true issue = Reaper::Issue.new(issue) # TODO: Add force-all flag. issue_action(issue, "Close issue?", @skip_confirm) do |issue| issue.reap puts "Issue was reaped.".green end end # Fetch issues in ascending updated order. = { sort: :updated, direction: :asc } puts "Finding next reapable issues..." issues = @client.list_issues() issues.each do |issue| issue = Reaper::Issue.new(issue) # Skip if this task has already been closed or has a do-not-reap tag. next if issue.closed? next if issue.labels.include?('do-not-reap') # If there's a to-reap tag, close it. Else, add a to-reap tag and # a warning comment. # FIXME: The timeout for closing an issue after a warning should be # customizable and not based on run-time of the reaper (e.g. running # reaper should be idempotent). puts "\n" # Break out of the whole loop if the issue's updated date is outside # the range. break if issue.updated_at > now - @stale_threshold issues_reaped = true issue_action(issue, "Add warning?", @skip_confirm) do |issue| issue.warn(Reaper::REAPER_WARNING) puts "Added `to-reap` to #{issue.number}" end end if issues_reaped puts "Nice, you're done!".green else puts "No reap-able issues, woohoo!".green end end |