Last active
December 28, 2020 22:22
-
-
Save annarailton/3a2b738fe451c79216f31b144ece10ae to your computer and use it in GitHub Desktop.
GitHub Action that checks PRs for commits with messages containing `fixup!` and `squash!`
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
name: PR commit checker | |
on: pull_request | |
jobs: | |
get-commits: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get PR commits | |
run: | | |
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o out.json ${{ github.event.pull_request.commits_url }} | |
- name: Check PR commit messages | |
run: | | |
echo -e 'import json\ncommits = set((d["sha"], d["commit"]["message"]) for d in json.load(open("out.json", "r")))\nbad_commits = {s for s in commits if s[1].startswith("fixup!") or s[1].startswith("squash!")}\nif bad_commits:\n raise ValueError(f"There are some bad commits: {bad_commits}")' | python3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment