Class: Ocak::Commands::Issue::List

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/ocak/commands/issue/list.rb

Instance Method Summary collapse

Instance Method Details

#call(**options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ocak/commands/issue/list.rb', line 14

def call(**options)
  config = Config.load
  fetcher = LocalIssueFetcher.new(config: config)
  issues = fetcher.all_issues

  if options[:label]
    issues = issues.select do |i|
      i['labels']&.any? { |l| l['name'] == options[:label] }
    end
  end

  if issues.empty?
    puts 'No issues found.'
    return
  end

  issues.sort_by { |i| i['number'] }.each do |issue|
    labels = (issue['labels'] || []).map { |l| l['name'] }.join(', ')
    label_str = labels.empty? ? '' : "  [#{labels}]"
    puts format('#%-4<num>d %<title>s%<labels>s',
                num: issue['number'], title: issue['title'], labels: label_str)
  end
rescue Config::ConfigNotFound => e
  warn "Error: #{e.message}"
  exit 1
end