Last active
January 18, 2021 07:46
-
-
Save odsod/d7e01bb08070e7cd02d8fbeeaf2d8603 to your computer and use it in GitHub Desktop.
Scripted Dependabot reviews
This file contains hidden or 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 | |
set -euo pipefail | |
user=$(gh api graphql -f query="{ viewer { login } }" | jq -r .data.viewer.login) | |
echo "Listing dependency reviews for ${user}..." | |
search_results=$(gh api graphql -f query=" | |
query { | |
search( | |
query: \"type:pr state:open review:none review-requested:${user} label:dependencies\", | |
type: ISSUE, | |
first: 100, | |
) { | |
issueCount | |
edges { | |
node { | |
... on PullRequest { | |
url | |
} | |
} | |
} | |
} | |
} | |
") | |
pr_count=$(jq .data.search.issueCount <<<"$search_results") | |
echo "Found ${pr_count} dependency PRs to review..." | |
sleep 2 | |
while read -u 3 -r url; do | |
clear | |
echo "Starting review of ${url}..." | |
sleep 2 | |
PAGER=delta gh pr view "$url" | |
PAGER=delta gh pr diff "$url" | |
echo | |
gh pr checks "$url" || { | |
echo "Skipping ${url} due to failing checks" | |
sleep 2 | |
continue | |
} | |
echo | |
read -r -p "Merge PR ${url}? [Y/n] " ok | |
if [[ $ok =~ ^[Yy]$ || $ok == "" ]]; then | |
gh pr review --approve --body '@dependabot merge' "$url" | |
else | |
echo "Skipping ${url}..." | |
sleep 2 | |
fi | |
done 3< <(jq -r .data.search.edges[].node.url <<<"$search_results") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment