Skip to content

Instantly share code, notes, and snippets.

@annarailton
Last active December 28, 2020 22:22
Show Gist options
  • Save annarailton/3a2b738fe451c79216f31b144ece10ae to your computer and use it in GitHub Desktop.
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!`
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