Skip to content

Instantly share code, notes, and snippets.

@knbknb
Created February 7, 2018 22:05
Show Gist options
  • Save knbknb/c068f3966f0935401101817e094c6ef9 to your computer and use it in GitHub Desktop.
Save knbknb/c068f3966f0935401101817e094c6ef9 to your computer and use it in GitHub Desktop.
bash script to create a tab-separated list of github issues on the command line
#!/bin/sh
# https://stackoverflow.com/questions/48659631/github-issues-api-and-jq-filter-and-grep
# get github issues
GITHUB_PAT=5b01b116....
#user=Leaflet
#repo=Leaflet
user=stedolan
repo=jq
url=https://$GITHUB_PAT:x-oauth-basic@api.github.com/repos/$user/$repo/issues
echo curl -k -I $url?state=all\\\&per_page=10
tot_page=`curl -k -I $url?state=all\&per_page=10 2>/dev/null | awk -F'[&=<>]' '{for(i=1;i<=NF;i++) if($i ~ /^page$/) {kk=$(i+1)}} END{print kk}'`;
echo "total issues: $tot_page"
for i in $( seq 1 $tot_page); do
curl -k $url?state=all\&per_page=10\&page=$i 2>/dev/null | \
jq -L$HOME/.jq -r '.[] | (.created_at | sub("Z.*";"")) as $date | select($date) | [.number, .user.login, .state, .created_at] | @tsv'
#jq -L $HOME/.jq '.[] | (.created_at | sub("Z.*";"")) as $date | select($date | older(7) | not) | [.number, .user.login, .state, .created_at] | @tsv'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment