Class: GithubIssueSync::IssueExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/github_issue_sync/issue_exporter.rb

Overview

Fetches GitHub issues matching the given filters and writes them to a CSV that QA engineers can open in Google Sheets.

Usage:

exporter = GithubIssueSync::IssueExporter.new(
  repo:   "owner/repo",
  token:  ENV["GITHUB_TOKEN"],
  labels: ["qa-feedback"],
  state:  "open"
)
exporter.call(output_path: "tmp/gh-issues-export.csv")
exporter.call(output_path: "tmp/gh-issues-export.csv", dry_run: true, io: $stdout)

Constant Summary collapse

PER_PAGE =
100

Instance Method Summary collapse

Constructor Details

#initialize(repo:, token:, labels: [ "qa-feedback" ], state: "open") ⇒ IssueExporter

Returns a new instance of IssueExporter.



23
24
25
26
27
28
# File 'lib/github_issue_sync/issue_exporter.rb', line 23

def initialize(repo:, token:, labels: [ "qa-feedback" ], state: "open")
  @repo   = repo
  @token  = token
  @labels = labels
  @state  = state
end

Instance Method Details

#call(output_path: nil, dry_run: false, io: $stdout) ⇒ Object

Parameters:

  • output_path (String, nil) (defaults to: nil)

    Path to write the CSV file; nil writes CSV to io.

  • dry_run (Boolean) (defaults to: false)

    When true, print preview to io instead of writing.

  • io (IO) (defaults to: $stdout)

    Output stream for dry-run / nil-path mode (default $stdout).



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/github_issue_sync/issue_exporter.rb', line 33

def call(output_path: nil, dry_run: false, io: $stdout)
  issues = fetch_all_issues
  rows   = issues.map { |i| IssueRow.from_github(i) }

  if dry_run
    print_preview(rows, io)
  elsif output_path
    write_csv(rows, output_path)
    io.puts "Exported #{rows.size} issue(s) to #{output_path}" if io.respond_to?(:puts)
  else
    io.print generate_csv(rows)
  end
end