Skip to content

Instantly share code, notes, and snippets.

@ArsenArsen
Created July 3, 2022 19:49
Show Gist options
  • Save ArsenArsen/f4ad55b302b962067ed2a190bb08dacf to your computer and use it in GitHub Desktop.
Save ArsenArsen/f4ad55b302b962067ed2a190bb08dacf to your computer and use it in GitHub Desktop.
name: Mark PRs as drafts
on:
pull_request:
jobs:
mark-as-draft:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
set -e
git fetch origin "${HEAD_REF}:headref"
git fetch origin "${GITHUB_REF}:otherref"
statusfile="$(mktemp)"
trap 'rm "$statusfile"' EXIT
chmod 0 -- "$statusfile"
# hopefully that gives us all the commits needed
gh api \
-H "Accept: application/vnd.github+json" \
"/repos/$REPO/pulls/$PRNUM/commits" \
| jq -r 'map(.sha)|join("\n")' \
| while read -r COMMIT; do
printf 'pondering commit %s\n' "$COMMIT"
git show -s "$COMMIT"
git show -s --format='%s' "$COMMIT" | grep -q '^fixup! ' || continue
gh pr edit "$PR" --add-label 'has fixups'
chmod +r -- "$statusfile"
done
[ -r "$statusfile" ] || gh pr edit "$PR" --remove-label 'has fixups'
env:
HEAD_REF: ${{ github.head_ref }}
PR: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
PRNUM: ${{ github.event.number }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment