File tree 6 files changed +79
-1
lines changed
6 files changed +79
-1
lines changed Original file line number Diff line number Diff line change
1
+ # It will force the user to add an e-mail for this project, before committing.
2
+
Original file line number Diff line number Diff line change 3
3
.idea
4
4
.vscode
5
5
.kotlin
6
+
7
+ .env
8
+
6
9
/local.properties
7
10
.DS_Store
8
11
/build
Original file line number Diff line number Diff line change @@ -3,4 +3,13 @@ plugins {
3
3
alias(libs.plugins.com.android.library) apply false
4
4
alias(libs.plugins.jetbrains.kotlin.android) apply false
5
5
alias(libs.plugins.compose.compiler) apply false
6
- }
6
+ }
7
+ task<Copy >(" installGitHook" ) {
8
+ delete(" .git/hooks/pre-commit" )
9
+
10
+ fileMode = 0x777
11
+ from(File (rootProject.rootDir, " scripts/pre-commit" ))
12
+ into(File (rootProject.rootDir, " .git/hooks" ))
13
+ }
14
+
15
+ tasks.getByPath(" :app:preBuild" ).dependsOn(" :installGitHook" )
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+ import * as ChildProcess from 'node:child_process' ;
3
+ import * as process from 'node:process' ;
4
+
5
+ const checkCommitMail = ( ) => {
6
+ console . warn ( `Check COMMIT_MAIL` ) ;
7
+ if ( ! process . env . COMMIT_MAIL ) {
8
+ console . error (
9
+ `No COMMIT_MAIL set in .env, please take a look at the file '.env.template'`
10
+ ) ;
11
+ process . exit ( 1 ) ;
12
+ }
13
+
14
+ const currentMail = ChildProcess . execSync ( 'git config user.email' )
15
+ . toString ( )
16
+ . trim ( )
17
+ . toLowerCase ( ) ;
18
+ const commitMail = process . env . COMMIT_MAIL . trim ( ) . toLowerCase ( ) ;
19
+ if ( currentMail !== commitMail ) {
20
+ console . error (
21
+ `currentMail: ${ currentMail } !== initialMail: ${ commitMail } `
22
+ ) ;
23
+ console . error (
24
+ `Please set your commit user mail for this project like: 'git config user.email '${ commitMail } ''`
25
+ ) ;
26
+ process . exit ( 1 ) ;
27
+ }
28
+ } ;
29
+
30
+ checkCommitMail ( ) ;
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+
3
+ git stash -q --keep-index
4
+
5
+ echo " Running git pre-commit hook"
6
+
7
+ ./gradlew lint &&
8
+ node --env-file=.env ./scripts/check-commit-mail.js &&
9
+ node ./scripts/validate-branch-name.js
10
+
11
+ RESULT=$?
12
+
13
+ git stash pop -q
14
+
15
+ # return 1 exit code if running checks fails
16
+ [ $RESULT -ne 0 ] && exit 1
17
+ exit 0
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+ import * as ChildProcess from 'node:child_process' ;
3
+ import * as process from 'node:process' ;
4
+
5
+ const checkValidBranchName = ( ) => {
6
+ console . warn ( `Check VALID_BRANCH_NAME` ) ;
7
+
8
+ const currentBranchName = ChildProcess . execSync ( 'git symbolic-ref --short HEAD' )
9
+ . toString ( )
10
+ . trim ( )
11
+
12
+ const regex = / ^ ( f e a t u r e | f i x | h o t f i x | r e l e a s e ) \/ .+ $ / g;
13
+ const found = currentBranchName . match ( regex ) !== null ;
14
+ process . exit ( found ? 0 : 1 ) ;
15
+ } ;
16
+
17
+ checkValidBranchName ( ) ;
You can’t perform that action at this time.
0 commit comments