Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created February 19, 2023 16:50
Show Gist options
  • Save KyMidd/9a7481ef1be2f7d639b36b6d785e16b0 to your computer and use it in GitHub Desktop.
Save KyMidd/9a7481ef1be2f7d639b36b6d785e16b0 to your computer and use it in GitHub Desktop.
# Export STASH_PASS
#export STASH_PASS=xxx
# Set vars
PR_LIMIT=1000 # How many PR entries to call from Stash
USER_LIMIT=1000 # How many author and reviewer entries to call from Stash
STASH_USER='your.username'
STASH_URL='your.stash.server.com'
# Find all stash projects to iterate over
EHR_RELATED_STASH_PROJECTS=$(cat collections.json| jq -r '.[].code')
# Erase file for re-runs
echo "" > users
# Iterate over stash Projects
for PROJECT in $(echo $EHR_RELATED_STASH_PROJECTS); do
echo "💥 Working on project $PROJECT"
# Find slug of all repos in a project
unset PROJECT_REPOS
PROJECT_REPOS=$(curl -s --user $STASH_USER:$STASH_PASS https://$STASH_URL/rest/api/1.0/projects/$PROJECT/repos\?limit\=$PR_LIMIT | jq -r '.values[].slug')
# Iterate over each repo to find all PRs, limit 1000
for REPO in $(echo $PROJECT_REPOS); do
echo "Working on repo $REPO"
unset AUTHOR_USER_NAMES
unset REVIEWER_USER_NAMES
AUTHOR_USER_NAMES=$(curl -s --user $STASH_USER:$STASH_PASS https://$STASH_URL/rest/api/1.0/projects/$PROJECT/repos/$REPO/pull-requests\?state\=ALL\&limit\=$USER_LIMIT | jq -r '.values[].author.user.name' | sort | uniq)
REVIEWER_USER_NAMES=$(curl -s --user $STASH_USER:$STASH_PASS https://$STASH_URL/rest/api/1.0/projects/$PROJECT/repos/$REPO/pull-requests\?state\=ALL\&limit\=$USER_LIMIT | jq -r '.values[].reviewers[].user.name' | sort | uniq)
echo $AUTHOR_USER_NAMES | tr " " "\n" >> users
echo $REVIEWER_USER_NAMES | tr " " "\n" >> users
done
done
# Sort, uniq
cat users | sort | uniq > users_sorted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment