Last active
May 7, 2019 17:38
-
-
Save hayajo/5501c1c986fdaaaf6bfb2e4cd243bf5b to your computer and use it in GitHub Desktop.
GitHubのPRとISSUEを取ってくる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
OWNER=${1:?"repo onwer required"} | |
URL_BASE="https://api.github.com" | |
REPOS_URL="/users/$OWNER/repos?per_page=100" | |
PULLS_URL="/repos/$OWNER/%s/pulls" | |
ISSUES_URL="/repos/$OWNER/%s/issues" | |
HEADER_AUTH=${GITHUB_ACCESS_TOKEN:+"Authorization: token $GITHUB_ACCESS_TOKEN"} | |
JQ_FILTER='.number, .url, .user.login, .title' | |
# for using in xargs | |
export URL_BASE PULLS_URL ISSUES_URL HEADER_AUTH JQ_FILTER | |
PARALLEL=3 | |
TMPDIR=`mktemp -d` | |
echo TMPDIR=$TMPDIR >&2 | |
repos() { | |
curl -sL $HEADER_AUTH $URL_BASE$REPOS_URL | jq .[].name | |
} | |
cleanup() { | |
rm -rf $TMPDIR | |
} | |
pulls() { | |
if [ $# -gt 0 ]; then | |
curl -sL -H "$HEADER_AUTH" $URL_BASE$(printf "$PULLS_URL" $1) | jq ".[] | $JQ_FILTER" | xargs -n 4 echo $1 | |
fi | |
} | |
# for using in xargs | |
export -f pulls | |
issues() { | |
if [ $# -gt 0 ]; then | |
curl -sL -H "$HEADER_AUTH" $URL_BASE$(printf "$ISSUES_URL" $1) | jq ".[] | $JQ_FILTER" | xargs -n 4 echo $1 | |
fi | |
} | |
# for using in xargs | |
export -f issues | |
## main | |
tmp_repos=$TMPDIR/repos.txt | |
repos > $tmp_repos | |
cat $tmp_repos | xargs -I@ -P $PARALLEL /bin/bash -c 'pulls @' | tee $TMPDIR/pulls.txt | |
cat $tmp_repos | xargs -I@ -P $PARALLEL /bin/bash -c 'issues @' | tee $TMPDIR/issues.txt | |
cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment