Skip to content

Commit

Permalink
chore: adds commit validation via husky (fluidd-core#533)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas authored Feb 22, 2022
1 parent 0166fff commit 42a092f
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 34 deletions.
18 changes: 14 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
root = true

[*]
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js,jsx,ts,tsx,vue}]
indent_style = space
max_line_length = 100

[*.{md,markdown}]
max_line_length = 0
trim_trailing_whitespace = false
32 changes: 32 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

die () {
cat <<'EOF'
Error: Commit messages should follow the conventional commits standard, and should have a Signed-off-by line, for example:
```
feat: My feature.
Some description.
Signed-off-by: Your Name <your email address>
```
EOF

exit 1
}

COMMIT_MESSAGE=$(cat $1)

COMMIT_HEAD="^merge.+|(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|types)(\(.+\))?: .{1,50}"
COMMIT_SIGNED_OFF="signed-off-by: .*<.*@.*>"

if ! echo "$COMMIT_MESSAGE" | grep -iqE "$COMMIT_HEAD"; then
die
fi

if ! echo "$COMMIT_MESSAGE" | grep -iqE "$COMMIT_SIGNED_OFF"; then
die
fi
8 changes: 8 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

FILES_TO_LINT=$(git diff --cached --name-only --diff-filter=ACM | grep -iE "\.(js|jsx|ts|tsx|vue)$" || true)

if [ -n "$FILES_TO_LINT" ]; then
npx --no-install vue-cli-service lint --no-fix $FILES_TO_LINT
fi
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ Fluidd is built on VueJS, using TypeScript.

- By signing off on commits, you acknowledge that you agree to the [developer certificate of origin](/developer-certificate-of-origin).
This must contain your real name and a current email address.

After cloning the repo and running `npm install`, we recommend running `npm run bootstrap` to install a couple of git hooks that will pre-validate all new commits.
82 changes: 52 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"test:unit": "vue-cli-service test:unit",
"test:e2e": "vue-cli-service test:e2e",
"lint": "vue-cli-service lint",
"bootstrap": "husky install",
"copy:host:config": "shx cp -f ./server/config.json ./dist/config.json",
"deploy:host": "potato -s dist -u -b app.fluidd.xyz -a \"$AWS_ACCESS_KEY_ID\" -t \"$AWS_SECRET_ACCESS_KEY\"",
"deploy:host:dev": "potato -s dist -u -b dev-app.fluidd.xyz",
Expand Down Expand Up @@ -101,6 +102,7 @@
"eslint-plugin-vue": "^6.2.2",
"file-loader": "^6.2.0",
"generate-file-webpack-plugin": "^1.0.1",
"husky": "^7.0.4",
"jest-junit": "^12.0.0",
"json-loader": "^0.5.7",
"mockdate": "^3.0.5",
Expand Down

0 comments on commit 42a092f

Please sign in to comment.