class Githuh::CLI::Commands::Issue::Export

Constants

CSV_HEADER
CSV_MAP
DEFAULT_FORMAT
DEFAULT_OUTPUT_FORMAT
FORMATS

Attributes

file[RW]
filename[RW]
format[RW]
issues[RW]
mapping[RW]
output[RW]
record_count[RW]
repo[RW]

Public Class Methods

find_user(client, username) click to toggle source
# File lib/githuh/cli/commands/issue/export.rb, line 100
def self.find_user(client, username)
  @user_cache ||= {}
  @user_cache[username] ||= client.user(username).name
end
issue_labels(issue) click to toggle source
# File lib/githuh/cli/commands/issue/export.rb, line 96
def self.issue_labels(issue)
  issue.labels.map(&:name)
end

Public Instance Methods

bar_size() click to toggle source
# File lib/githuh/cli/commands/issue/export.rb, line 88
def bar_size
  record_count + 1
end
call(repo: nil, file: nil, format: nil, mapping: nil, **opts) click to toggle source
Calls superclass method Githuh::CLI::Commands::Base#call
# File lib/githuh/cli/commands/issue/export.rb, line 38
def call(repo: nil, file: nil, format: nil, mapping: nil, **opts)
  super(**opts)

  self.record_count = 0
  self.repo = repo

  raise ArgumentError, "argument <repo> is required" unless repo
  raise ArgumentError, "argument <repo> is not a repository, expected eg 'rails/rails'" unless repo =~ %r{/}

  self.mapping = {}
  if mapping && ::File.exist?(mapping)
    self.mapping = ::YAML.safe_load(::File.read(mapping))['label-to-estimates'] || {}
  end

  Export.const_set(:LabelEstimates, self.mapping)

  self.issues = []
  self.output = StringIO.new
  self.format = (format || DEFAULT_FORMAT).to_sym

  self.filename = file || file_name(repo)
  self.file = File.open(filename, "w")

  print_summary

  raise ArgumentError, "Format is not provided" unless FORMATS.key?(format&.to_sym)

  # —————————— actually get all issues ———————————————
  self.file.write send("render_as_#{format}", fetch_issues)
  # ————————————————————————————————————————————————————————

  print_conclusion
ensure
  file.close if file.respond_to?(:close) && !file.closed?
end
default_options() click to toggle source
# File lib/githuh/cli/commands/issue/export.rb, line 92
def default_options
  { state: "open" }
end
fetch_issues() click to toggle source
# File lib/githuh/cli/commands/issue/export.rb, line 74
def fetch_issues
  client.auto_paginate = true
  self.issues = filter_issues(client.issues(repo, query: default_options)).tap do |issue_list|
    self.record_count = issue_list.size
    bar("Issues")&.advance
  end
end
filter_issues(issues_list) click to toggle source
# File lib/githuh/cli/commands/issue/export.rb, line 82
def filter_issues(issues_list)
  issues_list.reject do |issue|
    issue.html_url =~ /pull/
  end
end
render_as_csv(issue_list) click to toggle source

Id,Title,Labels,Type,Estimate,Current State,Created at,Accepted at,Deadline,Requested By,Owned By,Description,Comment,Comment 100, existing started story,“label one,label two”,feature,1,started,“Nov 22, 2007”,,,user1,user2,this will update story 100,, ,new story,label one,feature,-1,unscheduled,,,,user1,,this will create a new story in the icebox,comment1,comment2

# File lib/githuh/cli/commands/issue/export.rb, line 132
def render_as_csv(issue_list)
  # puts "rendering issues as CVS:"
  # pp issue_list
  ::CSV.generate do |csv|
    csv << CSV_HEADER
    issue_list.each do |issue|
      row = []
      CSV_HEADER.each do |column|
        method = column.downcase.underscore.to_sym
        value = if CSV_MAP[column]
            CSV_MAP[column][client, issue]
          else
            begin
              issue.to_h[method]
            rescue StandardError
              nil
            end
          end
        value = value.strip if value.is_a?(String)
        row << value
      end
      csv << row
      bar&.advance
    end
    bar.finish
  end
end
render_as_json(issue_list) click to toggle source
# File lib/githuh/cli/commands/issue/export.rb, line 160
def render_as_json(issue_list)
  JSON.pretty_generate(issue_list.map(&:to_h))
end

Private Instance Methods

file_name(repo) click to toggle source
# File lib/githuh/cli/commands/issue/export.rb, line 182
def file_name(repo)
  "#{repo.gsub(%r{/}, '.')}.issues.#{FORMATS[self.format.to_sym]}"
end
print_conclusion() click to toggle source
print_summary() click to toggle source