Skip to content

Commit

Permalink
Merge pull request #50 from sasjs/git-hooks
Browse files Browse the repository at this point in the history
feat(git): enabled git hook enforcing conventional commits
  • Loading branch information
YuryShkoda authored May 20, 2021
2 parents 9daf8f8 + fa9e413 commit 5a35833
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
18 changes: 18 additions & 0 deletions .git-hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
RED="\033[1;31m"
GREEN="\033[1;32m"

# Get the commit message (the parameter we're given is just the path to the
# temporary file which holds the message).
commit_message=$(cat "$1")

if (echo "$commit_message" | grep -Eq "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z \-]+\))?!?: .+$") then
echo "${GREEN} ✔ Commit message meets Conventional Commit standards"
exit 0
fi

echo "${RED}❌ Commit message does not meet the Conventional Commit standard!"
echo "An example of a valid message is:"
echo " feat(login): add the 'remember me' button"
echo "ℹ More details at: https://www.conventionalcommits.org/en/v1.0.0/#summary"
exit 1
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"postpublish": "git clean -fd",
"package:lib": "npm run build && cp ./package.json build && cp README.md build && cd build && npm version \"5.0.0\" && npm pack",
"lint:fix": "npx prettier --write '{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}'",
"lint": "npx prettier --check '{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}'"
"lint": "npx prettier --check '{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}'",
"postinstall": "[ -d .git ] && git config core.hooksPath ./.git-hooks || true"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion src/rules/file/hasDoxygenHeader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('hasDoxygenHeader - test', () => {
it('should return an array with a single diagnostic when the file is undefined', () => {
const content = undefined

expect(hasDoxygenHeader.test((content as unknown) as string)).toEqual([
expect(hasDoxygenHeader.test(content as unknown as string)).toEqual([
{
message: 'File missing Doxygen header',
lineNumber: 1,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/file/hasMacroNameInMend.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('hasMacroNameInMend - test', () => {
it('should return an empty array when the file is undefined', () => {
const content = undefined

expect(hasMacroNameInMend.test((content as unknown) as string)).toEqual([])
expect(hasMacroNameInMend.test(content as unknown as string)).toEqual([])
})

describe('nestedMacros', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/file/hasMacroParentheses.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('hasMacroParentheses', () => {
it('should return an empty array when the file is undefined', () => {
const content = undefined

expect(hasMacroParentheses.test((content as unknown) as string)).toEqual([])
expect(hasMacroParentheses.test(content as unknown as string)).toEqual([])
})

describe('with extra spaces and comments', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/file/noNestedMacros.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('noNestedMacros', () => {
it('should return an empty array when the file is undefined', () => {
const content = undefined

expect(noNestedMacros.test((content as unknown) as string)).toEqual([])
expect(noNestedMacros.test(content as unknown as string)).toEqual([])
})

it('should use the configured line ending while testing content', () => {
Expand Down

0 comments on commit 5a35833

Please sign in to comment.