Skip to content

Commit 2d6afc9

Browse files
authored
refactor: added pre-commit tests (#22)
1 parent fa1e54e commit 2d6afc9

8 files changed

+66
-1
lines changed

.env.template

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# It will force the user to add an e-mail for this project, before committing.
2+

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ dist/
1414
source/js/*.min.js*
1515
tests/backstop_data/html_report/
1616
tests/backstop_data/bitmaps_test/
17+
18+
.env

.husky/pre-commit

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
. "$(dirname "$0")/_/husky.sh"
55

66
npx --yes pretty-quick --staged
7+
npm run lint
8+
node ./scripts/check-commit-mail.mjs

.prettierrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"trailingComma": "none"
2+
"trailingComma": "none",
3+
"singleQuote": true
34
}

CONTRIBUTING.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Contributing
2+
13
Thanks for your interest in our project. Contributions are welcome. Feel free to [open an issue](https://github.com/db-ui/core/issues/new) with questions or reporting ideas and bugs, or [open pull requests](https://github.com/db-ui/core/compare) to contribute code.
24

35
We are committed to fostering a welcoming, respectful, and harassment-free environment. Be kind!
6+
7+
## Before you commit
8+
9+
Please make sure that husky is installed correctly to validate your changes.
10+
11+
Moreover, you need to duplicate `.env.template` as `.env` and type your own email address. This ensures that you have the correct email set for this project.

package-lock.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"cpr": "^3.0.1",
7474
"details-element-polyfill": "^2.4.0",
7575
"dialog-polyfill": "^0.5.6",
76+
"dotenv": "^16.0.2",
7677
"html-validate": "^6.4.0",
7778
"html5-boilerplate": "^8.0.0",
7879
"husky": "^7.0.4",

scripts/check-commit-mail.mjs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
import * as ChildProcess from 'node:child_process';
3+
import * as process from 'node:process';
4+
import * as dotenv from 'dotenv';
5+
6+
dotenv.config();
7+
8+
const checkCommitMail = () => {
9+
console.log(`Check COMMIT_MAIL`);
10+
if (!process.env.COMMIT_MAIL) {
11+
console.error(
12+
`No COMMIT_MAIL set in .env, please look at the file '.env.template'`
13+
);
14+
process.exit(1);
15+
}
16+
17+
const currentMail = ChildProcess.execSync('git config user.email')
18+
.toString()
19+
.trim()
20+
.toLowerCase();
21+
const commitMail = process.env.COMMIT_MAIL.trim().toLowerCase();
22+
if (currentMail !== commitMail) {
23+
console.error(
24+
`currentMail: ${currentMail} !== initialMail: ${commitMail}`
25+
);
26+
console.error(
27+
`Please set your commit user mail for this project like: 'git config user.email "${commitMail}"'`
28+
);
29+
process.exit(1);
30+
}
31+
};
32+
33+
checkCommitMail();

0 commit comments

Comments
 (0)