A commit policy is a set of automated rules evaluated against every new version-control commit. Passing commits are accepted; failing commits are rejected with an explanatory message. section 8.8
Use commit policies to govern API source changes:
- Require traceability from individual commits to work tickets or user stories. section 8.8
- Run checks eagerly before commit creation for fail-fast feedback, or run them server-side when commits are pushed. section 8.8
- Implement the rules with customizable Git hooks, such as pre-commit or server-side hooks. section 8.8
Require a Jira reference
A hook can reject a commit unless its message contains a Jira issue reference matching DEV-XXXX, then print an actionable correction message. section 8.8
#!/bin/bash
commit_msg_file=$1
# Read the commit message file
commit_msg=$(cat "$commit_msg_file")
# Pattern to match Jira issue reference (DEV-XXXX)
Pattern="DEV-[0-9]{4}"
# Check if the commit message contains the Jira issue reference
if [[ ! $commit_msg =~ $pattern ]]; then
echo "Error: Commit message does not contain a valid
Jira issue reference in the format DEV-XXXX."
echo "Please include a Jira issue reference in your commit message."
exit 1
fi
Inspect the shell hook that reads the commit message, checks the DEV-XXXX pattern, and exits with an error when the reference is missing. section 8.8
