Created
August 13, 2022 03:30
-
-
Save ebinnion/b9f7d9fe6614fc97ad97a8ff1b328c9c to your computer and use it in GitHub Desktop.
A bash script to export all PRs for a given repository.
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 | |
# This script requires jq to be installed and available in the path. | |
# | |
# To create a personal access token, follow the instructions here: | |
# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token | |
TOKEN=$1 | |
ORG=$2 | |
REPO=$3 | |
OUTPUT_RAW="" | |
get_pull_requests() { | |
curl -s --location --request GET "https://api.github.com/repos/$ORG/$REPO/pulls?state=all&per_page=40&page=$1" \ | |
--header "Authorization: token $TOKEN" \ | |
--header "Accept: application/vnd.github+json" | |
} | |
get_raw_output() { | |
printf '%s' "$1" | jq -r | |
} | |
i=1 | |
while [ "$OUTPUT_RAW" != "[]" ] ; do | |
OUTPUT=$( get_pull_requests "$i" ) | |
OUTPUT_RAW=$( get_raw_output "$OUTPUT" ) | |
i=$((i+1)) | |
printf '%s' "$OUTPUT" | jq -r '.[] | [ .created_at, .html_url, .user.login, .title ] | @csv' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment