Skip to content

Commit

Permalink
chore: Very basic commit message validation for semantic-release
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-polk committed Sep 23, 2024
1 parent fb7a144 commit 0b6e40b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
23 changes: 23 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
. "$(dirname "$0")/_/husky.sh"

# Ideally, we might want to use a package like commitizen or commitlint,
# but as far as I can tell, those don't work with GUI git clients like GitKraken.
# And they are actually overkill for what we need here (though we could custom configure them).

# Read the commit message from the file passed as an argument
COMMIT_MSG=$(cat "$1")

# Check if the commit message contains a colon.
# This is a super basic validation and could certainly be improved.
if ! echo "$COMMIT_MSG" | grep -q ":"; then
echo "Improper commit message for semantic-release."
echo "Please use the format 'type: message'"
echo "e.g. chore: Updated README"
echo "e.g. fix: Made a repair"
echo "e.g. feat: Added a new thing"
exit 1
fi

# If we reach here, the commit message is valid
exit 0
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"build-dev": "shx rm -rf dist/ && webpack --config webpack.config.js",
"tslint": "tslint --project tsconfig.json",
"test": "jest",
"test-storybook": "test-storybook --url http://localhost:9009"
"test-storybook": "test-storybook --url http://localhost:9009",
"prepare": "husky install"
},
"dependencies": {
"@material-ui/core": "^4.12.3",
Expand Down Expand Up @@ -77,6 +78,7 @@
"file-loader": "^3.0.1",
"globule": "^1.2.1",
"html-webpack-plugin": "^3.2.0",
"husky": "8",
"jest": "^27.4.7",
"jest-teamcity-reporter": "^0.9.0",
"jest-transform-css": "^3.0.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10235,6 +10235,11 @@ humanize-ms@^1.2.1:
dependencies:
ms "^2.0.0"

husky@8:
version "8.0.3"
resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.3.tgz#4936d7212e46d1dea28fef29bb3a108872cd9184"
integrity sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==

hyphenate-style-name@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/hyphenate-style-name/-/hyphenate-style-name-1.0.3.tgz#097bb7fa0b8f1a9cf0bd5c734cf95899981a9b48"
Expand Down

0 comments on commit 0b6e40b

Please sign in to comment.