Architectural Overview
The internal logic that powers Crisp are divided into three distinct individual parts:
-
The reader which is responsible for reading the Git commit message either from STDIN (piped in) or from the
$GIT_DIR/COMMIT_EDITMSG
file (see the official Git docs). -
The
parser
which is responsible for accepting the inputted commit message and then parsing it into a Go struct for further data processing. -
The
validator
which is responsible for running some validation logic on the parsed data.
Under the hood, all three of the aforementioned components work in tandem to lint your Git commit messages. The following diagram will provide a better understanding of the underlying logic of the software.
Reader
The reader is responsible for accepting user input through either of the following means:
- Directly passed as a CLI flag,
- Read from STDIN where the data is piped into it.
- Read the
$GIT_DIR/COMMIT_EDITMSG
file.
In other words, Crisp can read a commit message if it is directly passed to it
as a argument of the message
command as shown below;
crisp message "$(git show --no-patch --format=%B)"
While that is not the recommended approach to lint a commit message, it exists
for quickly validating a single message. The recommended approach to lint a
commit message is to pass the data to Crisp through STDIN
. Crisp will read
from STDIN
if the --stdin
flag is passed to the message
command.
So, piping a commit message to Crisp is possible like this;
git show --no-patch --format=%B | crisp message --stdin
In case no commit message was piped in to Crisp, the reader will fallback to
reading from the
$GIT_DIR/COMMIT_EDITMSG
file.
The diagram below will provide a better understanding of how the reader works behind-the-scenes.
Parser
The parser is responsible for receiving content from the reader and parsing it into the following components;
- Header
- Body
- Footer
Upon successful parsing operation, the logic generates and returns a Go struct for further processing and data validation.
Validator
After Crisp has parsed and generated a “commit message” object, the validator can receive the said object for further processing and validation. The validator performs the following operations:
-
Checks whether the commit type is in accordance to the list of accepted keywords (
build
,ci
,docs
,feat
,fix
,perf
,refactor
,style
,test
,chore
). -
If the optional commit message scope is provided, check whether it is lower-cased and contains valid characters.
-
Checks whether the commit message subject is provided and does not end with a period (
.
) nor starts with a capitalised letter. -
Checks whether the length of the commit message does not exceed more than 50 characters long.
On successful validation, Crisp returns an appropriate valid commit message
prompt for the user with an exit status code of 0
.