|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# This script will, for each Pkl repo, approve PRs created by ./update_downstream_ci.sh for the given version. |
| 4 | +# |
| 5 | +# Usage: ./approve_downstream_prs.sh |
| 6 | + |
| 7 | +set -eo pipefail |
| 8 | + |
| 9 | +MY_GIT_USER="$(gh api user --jq '.login')" |
| 10 | + |
| 11 | +if [[ -z "$MY_GIT_USER" ]]; then |
| 12 | + echo "Could not determine the current user in gh. Try running \`gh auth login\`." |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" |
| 17 | + |
| 18 | +source "$SCRIPT_DIR/repos.sh" |
| 19 | + |
| 20 | +VERSION=$( |
| 21 | + curl -s https://api.github.com/repos/apple/pkl-project-commons/releases \ |
| 22 | + | jq -r '[.[] | select(.tag_name | startswith("pkl.impl.ghactions"))] | .[0].name | split("@")[1]' |
| 23 | +) |
| 24 | + |
| 25 | +echo "Latest pkl.impl.ghactions version: $VERSION" |
| 26 | + |
| 27 | +find_pr_and_approve() { |
| 28 | + repo="$1" |
| 29 | + pr_number="$(gh pr list --repo "apple/$repo" --json title,number \ |
| 30 | + | jq --arg VERSION $VERSION \ |
| 31 | + '.[] |
| 32 | + | select(.title == "Bump pkl.impl.ghactions to version \($VERSION)") |
| 33 | + | .number')" |
| 34 | + |
| 35 | + if [ -z "$pr_number" ]; then |
| 36 | + echo "✅ No PR to approve for $repo" |
| 37 | + return 0 |
| 38 | + fi |
| 39 | + |
| 40 | + existing_approvals="$(GH_PAGER='' gh pr view --repo "apple/$repo" "$pr_number" --json reviews | \ |
| 41 | + jq --arg MY_GIT_USER $MY_GIT_USER \ |
| 42 | + '.reviews | map(select(.author.login == $MY_GIT_USER and .state == "APPROVED")) | length')" |
| 43 | + if [ "$existing_approvals" != "0" ]; then |
| 44 | + echo "✅ https://github.com/apple/$repo/pull/$pr_number already approved" |
| 45 | + return 0 |
| 46 | + fi |
| 47 | + |
| 48 | + echo "🔧 Approve https://github.com/apple/$repo/pull/$pr_number? Files changed:" |
| 49 | + GH_PAGER='' gh pr diff --name-only --repo "apple/$repo" "$pr_number" |
| 50 | + echo |
| 51 | + read -p "Press enter to approve or ^C to quit" |
| 52 | + gh pr review --repo "apple/$repo" "$pr_number" --approve |
| 53 | + echo "" |
| 54 | +} |
| 55 | + |
| 56 | +for repo in "${REPOS[@]}"; do |
| 57 | + find_pr_and_approve "$repo" |
| 58 | +done |
0 commit comments