Skip to content

Instantly share code, notes, and snippets.

@ScriptAutomate
Last active May 22, 2024 02:49
Show Gist options
  • Save ScriptAutomate/e379c4bf15954c1911763eaaa33cf369 to your computer and use it in GitHub Desktop.
Save ScriptAutomate/e379c4bf15954c1911763eaaa33cf369 to your computer and use it in GitHub Desktop.
Provided a PR that is deleting files from a project, checks all other open PRs to see what PRs may be impacted
#!/usr/bin/env bash
# Wraps around GitHub CLI (gh): https://cli.github.com/
# Check all other open PRs that are working on
# files being deleted by the target PR.
# Usage:
# ./gh-delete-auditor.sh <PR>
#
# Example:
# ./gh-delete-auditor.sh 57645
CURRENT_PR=$1 # PR deleting files
DELETED_FILES=$(gh pr diff $CURRENT_PR | grep "deleted file" -A2 | grep '\-\-\-' | sed s/\-\-\-\ a\\///g)
EGREP_DELETED_FILES=$(echo $DELETED_FILES | sed 's: :\|:g')
OPEN_PRS=$(gh pr list --state open --limit 700 | cut -f1 | sed 's:\#::g' | grep -v $CURRENT_PR)
# Initialize bash array
declare -a IMPACTED_PRS
# Loop through all open PRs impacted by deleting files
for OPEN_PR in $OPEN_PRS; do
CHECK_DIFF=$(gh pr diff $OPEN_PR | egrep "$EGREP_DELETED_FILES")
if [ -n "$CHECK_DIFF" ]; then
echo "$OPEN_PR PR impacted:"
echo "$CHECK_DIFF"
IMPACTED_PRS+=($OPEN_PR)
fi
done
# Reference PRs impacted
declare -p IMPACTED_PRS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment