Skip to content

Instantly share code, notes, and snippets.

@stolarczyk
Last active July 17, 2024 10:51
Show Gist options
  • Save stolarczyk/1f072858d24176824dd8572741083d7d to your computer and use it in GitHub Desktop.
Save stolarczyk/1f072858d24176824dd8572741083d7d to your computer and use it in GitHub Desktop.
Save GitHub issues as TSV

Save GitHub issues as TSV

This script saves GitHub issues in TSV format

Installation

The script has two software dependancies:

  1. GitHub CLI for querying GitHub API
  2. jq for transforming the output of the above to TSV format

There are multiple ways to install these tools. If you're using Homebrew on macOS, it's as simple as running the code snippet below:

brew install jq
brew install gh

Usage

  1. Download the script
  2. Make it executable
chmod +x issues2tsv.sh
  1. Run it in the cloned repository
gh repo clone <organization>/<name>
# cd to the cloned repository
./issues2tsv.sh

Content

The following issue attributes are included in the TSV by default: number, title, assignees, state, url.

These are the available issue attributes, the script can be modified to include any of the following:

  assignees
  author
  body
  closed
  closedAt
  comments
  createdAt
  id
  labels
  milestone
  number
  projectCards
  reactionGroups
  state
  title
  updatedAt
  url

Output

The script outputs a TSV file named issues-<date>.tsv with content formatted like this:

number	title	assignees	state	url
<issue_number> <issue_title> <assigned_users> <issue_state> <issue_url>
<issue_number> <issue_title> <assigned_users> <issue_state> <issue_url>
<issue_number> <issue_title> <assigned_users> <issue_state> <issue_url>
#!/usr/bin/env bash
gh issue list --limit 10000 --state all --json number,title,assignees,state,url | jq -r '["number","title","assignees","state","url"], (.[] | [.number, .title, (.assignees | if .|length==0 then "Unassigned" elif .|length>1 then map(.login)|join(",") else .[].login end) , .state, .url]) | @tsv' > issues-$(date '+%Y-%m-%d').tsv
@BrianSwift-Intel
Copy link

Cool. With current gh 2.37.0 (2023-10-17) on Linux I was able to use the --jq option instead of installing and piping to jq

@ChenYuYeh
Copy link

ChenYuYeh commented Jul 17, 2024

Hello, it was a great tool. I made it successfully. But when I tried to add a new field for "author" but cannot figure out the right changes.
could you kindly support the how-to? Thanks!
gh issue list --limit 10000 --state all --json number,title,author,assignees,state,url | jq -r '["number","title","author","assignees","state","url"], (.[] | [.number, .title, .author, (.assignees | if .|length==0 then "Unassigned" elif .|length>1 then map(.login)|join(",") else .[].login end) , .state, .url]) | @tsv' > issues-$(date '+%Y-%m-%d').tsv

error:
../issues2tsv/issues2tsv+author.sh jq: error (at <stdin>:1): object ({"login":"d...) is not valid in a csv row

@ChenYuYeh
Copy link

issue resolved by below changes. Thanks!

gh issue list --limit 10000 --state all --json number,title,author,assignees,state,url | jq -r '["number","title","author","assignees","state","url"], (.[] | [.number, .title, (.author.login? // "No Author"), (.assignees | if length == 0 then "Unassigned" elif length > 1 then map(.login) | join(",") else first(.login? // "No Assignee") end), .state, .url]) | @TSV' > issues-$(date '+%Y-%m-%d').tsv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment