liveBook · Manning

Commit policy

As explained in Automating API Delivery

A commit policy is a set of automated rules evaluated against new commits to accept or reject them according to project requirements.

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

How Automating API Delivery covers it

How deep it goes
Defines automated acceptance and rejection, execution timing, and Git-hook implementation, but does not detail broader review judgment.
Examples
Uses a commit-message hook that requires a Jira reference matching DEV-XXXX and reports a corrective error.
What it assumes
Assumes version-control usage and introduces commit policies through Git hooks and commit-message validation.
What you can do after
Operate/configure Git hooks that fail fast or reject pushed commits when required commit-message rules fail.
How it connects
Connects Git hooks with pull requests, traceability, work tickets, GitOps, and APIOps.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Automating API Delivery. The section links point to the parts of the book it draws on.