File tree 3 files changed +65
-1
lines changed
3 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -192,7 +192,7 @@ See the [open issues](https://github.com/lumapps/commit-msg-validator/issues) fo
192
192
- [x] enforce the commit scope
193
193
- [x] enforce the commit subject
194
194
- [x] enforce the commit body length
195
- - [ ] enforce the JIRA reference
195
+ - [x ] enforce the JIRA reference
196
196
- [ ] enforce the BROKEN part
197
197
- [ ] avoid trailing space
198
198
- [ ] allow automated revert commit
Original file line number Diff line number Diff line change @@ -395,6 +395,31 @@ LUM-2345'
395
395
[[ " $status " -eq 0 ]]
396
396
}
397
397
398
+ @test " features and fixes commits need jira reference" {
399
+ [[ ` need_jira " feat" ` -eq 1 ]]
400
+ [[ ` need_jira " fix" ` -eq 1 ]]
401
+ }
402
+
403
+ @test " other commits don't need jira reference" {
404
+ [[ ` need_jira " docs" ` -eq 0 ]]
405
+ [[ ` need_jira " test" ` -eq 0 ]]
406
+ }
407
+
408
+ @test " feat without jira ref should be rejected" {
409
+ run validate_jira " feat" " "
410
+ [[ " $status " -eq $ERROR_JIRA ]]
411
+ }
412
+
413
+ @test " lint without jira ref should be validated" {
414
+ run validate_jira " lint" " "
415
+ [[ " $status " -eq 0 ]]
416
+ }
417
+
418
+ @test " feat with jira ref should be validated" {
419
+ run validate_jira " feat" " ABC-123"
420
+ [[ " $status " -eq 0 ]]
421
+ }
422
+
398
423
@test " overall validation invalid structure" {
399
424
MESSAGE=' plop
400
425
plop'
@@ -461,6 +486,17 @@ LUM-2345'
461
486
[[ " $status " -eq $ERROR_BODY_LENGTH ]]
462
487
}
463
488
489
+ @test " overall validation missing jira" {
490
+ MESSAGE=' feat(scope1): subject
491
+
492
+ Commit about stuff\"plop \"
493
+
494
+ 2345'
495
+
496
+ run validate " $MESSAGE "
497
+ [[ " $status " -eq $ERROR_JIRA ]]
498
+ }
499
+
464
500
@test " overall validation" {
465
501
MESSAGE=' feat(scope1): subject
466
502
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ readonly ERROR_TYPE=4
14
14
readonly ERROR_SCOPE=5
15
15
readonly ERROR_SUBJECT=6
16
16
readonly ERROR_BODY_LENGTH=7
17
+ readonly ERROR_JIRA=8
17
18
18
19
GLOBAL_HEADER=" "
19
20
GLOBAL_BODY=" "
@@ -176,6 +177,31 @@ validate_body_length() {
176
177
done <<< " $BODY"
177
178
}
178
179
180
+ need_jira () {
181
+ local TYPE=$1
182
+
183
+ case $TYPE in
184
+ feat)
185
+ echo 1
186
+ ;;
187
+ fix)
188
+ echo 1
189
+ ;;
190
+ * )
191
+ echo 0
192
+ esac
193
+ }
194
+
195
+ validate_jira () {
196
+ local TYPE=$1
197
+ local JIRA=$2
198
+
199
+ if [[ ` need_jira " $TYPE " ` -eq 1 && $JIRA = " " ]]; then
200
+ echo -e " ${TYPE} need a jira reference"
201
+ exit $ERROR_JIRA
202
+ fi
203
+ }
204
+
179
205
validate () {
180
206
local COMMIT_MSG=" $1 "
181
207
@@ -198,4 +224,6 @@ validate() {
198
224
validate_subject " $SUBJECT "
199
225
200
226
validate_body_length " $BODY "
227
+
228
+ validate_jira " $TYPE " " $JIRA "
201
229
}
You can’t perform that action at this time.
0 commit comments