Created
July 3, 2022 19:49
-
-
Save ArsenArsen/f4ad55b302b962067ed2a190bb08dacf to your computer and use it in GitHub Desktop.
This file contains 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
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