Skip to content

Instantly share code, notes, and snippets.

@knbknb
Created December 10, 2019 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knbknb/27635e5ad8ee8b21d9ab414bd8dba1fb to your computer and use it in GitHub Desktop.
Save knbknb/27635e5ad8ee8b21d9ab414bd8dba1fb to your computer and use it in GitHub Desktop.
GET metadata of users that have submitted pull requests to a repo
#!/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
@knbknb
Copy link
Author

knbknb commented Dec 10, 2019

Returns a table like this (no header rows)

table header: #, $date, .reqno, .state, .user.login, prtitle, watchers_cnt, .repo.html_url)

a b c d e f g h
1 2019-09-17 131 open jovsa fixed results_per_iteration miscount 0 https://github.com/jovsa/arxiv-sanity-preserver
2 2019-03-25 126 open Randl Fix link in readme 0 https://github.com/Randl/arxiv-sanity-preserver
3 2018-09-10 116 closed pranayaryal Update readme.md 1 https://github.com/pranayaryal/arxiv-sanity-preserver
4 2018-05-29 112 closed lukasheinrich Adds a Dockerfile that builds an image with all required dependencies 0 https://github.com/lukasheinrich/arxiv-sanity-preserver
5 2018-04-11 111 closed chennakeshava1998 add mongodb server in workflow 0 https://github.com/chennakeshava1998/arxiv-sanity-preserver
6 2018-01-21 104 closed yong-talentseer Predict
... ...
47 2015-11-28 1 closed kylemcdonald clear thumbnails before generating new ones 1 https://github.com/kylemcdonald/arxiv-sanity-preserver

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