Created
December 10, 2019 13:19
-
-
Save knbknb/27635e5ad8ee8b21d9ab414bd8dba1fb to your computer and use it in GitHub Desktop.
GET metadata of users that have submitted pull requests to a repo
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/sh | |
# knb 20191210 | |
# args: username reponame | |
# get users that have submitted pull requests to a repo | |
# table header: $date, .number, .state, .user.login, watchers_cnt, prtitle, .repo.html_url | |
if [ -z "GITHUB_PAT" ] | |
then | |
GITHUB_PAT=5b01b1... | |
fi | |
if [ -z "$1" ] | |
then | |
user=karpathy | |
else | |
user=$1 | |
shift | |
fi | |
if [ -z "$1" ] | |
then | |
repo=arxiv-sanity-preserver | |
else | |
repo=$1 | |
fi | |
url=https://$GITHUB_PAT:x-oauth-basic@api.github.com/repos/$user/$repo/pulls | |
# approx PR count: get only the header with the last page, use this as threshold in loop | |
tot_page=`curl -H \'Accept: application/vnd.github.shadow-cat-preview+json\' -L --insecure --head $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 pages of pull requests: $tot_page" >&2 | |
for i in $( seq 1 $tot_page); do | |
curl -L --insecure $url?state=all\&per_page=10\&page=$i 2>/dev/null | \ | |
jq -L$HOME/.jq -r '.[] | (.created_at | sub("T.*";"")) as $date | select($date) | [$date, .number, .state, .user.login, .title, .head.repo.watchers_count, .head.repo.html_url ] | @tsv' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Returns a table like this (no header rows)
table header: #, $date, .reqno, .state, .user.login, prtitle, watchers_cnt, .repo.html_url)