Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

root=$(git rev-parse --show-toplevel) || exit 1
exec "$root/.githooks/validate-commit-message" "$1"
26 changes: 26 additions & 0 deletions .githooks/validate-commit-message
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

awk '
BEGIN {
allowed = "co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>"
}
/^[[:space:]]*[Cc][Oo]-[Aa][Uu][Tt][Hh][Oo][Rr][Ee][Dd]-[Bb][Yy][[:space:]]*:/ {
line = tolower($0)
sub(/\r$/, "", line)
sub(/^[[:space:]]+/, "", line)
if (line != allowed) {
exit 42
}
}
' "$1"
status=$?

if [ "$status" -eq 42 ]; then
echo "Commit rejected: only Dependabot may be a co-author." >&2
exit 1
fi

if [ "$status" -ne 0 ]; then
echo "Commit rejected: could not validate co-author trailers." >&2
exit 1
fi
33 changes: 33 additions & 0 deletions .github/workflows/commit-policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Commit policy

on:
pull_request:
merge_group:

permissions:
contents: read

jobs:
commit-messages:
name: Commit messages
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Check out repository
uses: actions/checkout@v7.0.1
with:
fetch-depth: 0

- name: Validate co-author trailers
env:
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha }}
run: |
message_file=$(mktemp)
trap 'rm -f "$message_file"' EXIT

while IFS= read -r commit; do
git log -1 --format=%B "$commit" > "$message_file"
.githooks/validate-commit-message "$message_file"
done < <(git rev-list "$BASE_SHA..$HEAD_SHA")
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Contributing

## Git hooks

Enable the repository hooks after cloning:

```shell
git config core.hooksPath .githooks
```

Commit messages may not contain `Co-authored-by:` trailers. The canonical Dependabot co-author trailer is the only exception. Pull requests run the same validation on GitHub, so the policy applies even when a contributor has not enabled local hooks.
Loading