Skip to content

Instantly share code, notes, and snippets.

@gburgett
Created January 5, 2022 15:59
Show Gist options
  • Save gburgett/b56aa44e4eed0eda2a928580c3112440 to your computer and use it in GitHub Desktop.
Save gburgett/b56aa44e4eed0eda2a928580c3112440 to your computer and use it in GitHub Desktop.
open_prs_all.sh
#! /bin/bash
SCRIPT=$0
COLOR_NC='\033[0m' # No Color
COLOR_LGREEN='\033[1;32m'
COLOR_GRAY='\033[1;30m'
COLOR_RED='\033[0;31m'
COLOR_CYAN='\033[0;36m'
logv() {
[[ ! -z "$VERBOSE" ]] && >&2 echo -e "${COLOR_GRAY}$D: $@${COLOR_NC}"
return 0
}
execv() {
logv "$@"
"$@"
}
usage() {
echo "$0 <from> <to>
Scan an entire directory of git repos, reporting a list of open pull requests.
" && \
grep " .)\ #" $0; exit 0;
}
while getopts ":hvms" arg; do
case $arg in
v) # Verbose mode - extra output
VERBOSE=true
FLAGS="$FLAGS -v"
;;
h | *) # Display help.
usage
exit 0
;;
esac
done
shift $(($OPTIND - 1))
set -e
open_prs_d() {
PROJECT=$(git config --get remote.origin.url | sed -E 's/.*github\.com.(.*)(\.git)?/\1/')
PROJECT=${PROJECT%.git}
logv "Project is ${PROJECT}"
[[ "$PROJECT" == $(git config --get remote.origin.url) ]] && logv "remote $PROJECT is not a github repo" && return 0;
PRS=$(curl --fail -L -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/${PROJECT}/pulls | jq -r '.[].title')
# remove Dependabot PRs
PRS=$(echo "$PRS" | grep -iv "^bump" | grep -iv "^\[Security\]" | grep -iv '^build(' | grep -iv "^\[WIP\]")
[[ -z "$PRS" ]] && logv "$D: no PRs" && return 0;
echo -e "${COLOR_LGREEN}$D${COLOR_NC} ${COLOR_GRAY}https://github.com/${PROJECT}/pulls${COLOR_NC}\n${PRS}\n"
}
for D in *; do
if [ -d "${D}/.git" ]; then
pushd ${D} > /dev/null
open_prs_d $@ || true
popd > /dev/null
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment