File tree 3 files changed +55
-3
lines changed
3 files changed +55
-3
lines changed Original file line number Diff line number Diff line change @@ -188,12 +188,13 @@ See the [open issues](https://github.com/lumapps/commit-msg-validator/issues) fo
188
188
- [x] enforce the overall commit message structure
189
189
- [x] enforce the overall commit header structure
190
190
- [x] enforce the overall commit header lenght
191
- - [ ] enforce the commit body length
192
- - [ ] enforce the JIRA reference
193
- - [ ] enforce the BROKEN part
194
191
- [x] enforce the commit type
195
192
- [x] enforce the commit scope
196
193
- [x] enforce the commit subject
194
+ - [x] enforce the commit body length
195
+ - [ ] enforce the JIRA reference
196
+ - [ ] enforce the BROKEN part
197
+ - [ ] avoid trailing space
197
198
- [ ] allow automated revert commit
198
199
- [ ] allow fixup! and squash! commit with an option
199
200
Original file line number Diff line number Diff line change @@ -373,6 +373,28 @@ BROKEN:
373
373
[ " $status " -eq 0 ]
374
374
}
375
375
376
+ @test " body with 101 line length should be rejected" {
377
+ MESSAGE='
378
+ 12345678 012345678 012345678 012345678 012345678 012345678 012345678 012345678 012345678 012345678 01
379
+
380
+ LUM-2345'
381
+
382
+ run validate_body_length " $MESSAGE "
383
+ [[ " $status " -eq $ERROR_BODY_LENGTH ]]
384
+ }
385
+ @test " body with 100 line length should be valid" {
386
+ MESSAGE='
387
+ 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
388
+ 12345678 012345678 012345678 012345678 012345678 012345678 012345678 012345678 012345678 012345678 0
389
+
390
+ 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
391
+
392
+ LUM-2345'
393
+
394
+ run validate_body_length " $MESSAGE "
395
+ [[ " $status " -eq 0 ]]
396
+ }
397
+
376
398
@test " overall validation invalid structure" {
377
399
MESSAGE=' plop
378
400
plop'
@@ -428,6 +450,17 @@ LUM-2345'
428
450
[[ " $status " -eq $ERROR_SUBJECT ]]
429
451
}
430
452
453
+ @test " overall validation invalid body length" {
454
+ MESSAGE=' feat(scope1): subject
455
+
456
+ 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
457
+
458
+ LUM-2345'
459
+
460
+ run validate " $MESSAGE "
461
+ [[ " $status " -eq $ERROR_BODY_LENGTH ]]
462
+ }
463
+
431
464
@test " overall validation" {
432
465
MESSAGE=' feat(scope1): subject
433
466
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ readonly ERROR_HEADER_LENGTH=3
13
13
readonly ERROR_TYPE=4
14
14
readonly ERROR_SCOPE=5
15
15
readonly ERROR_SUBJECT=6
16
+ readonly ERROR_BODY_LENGTH=7
16
17
17
18
GLOBAL_HEADER=" "
18
19
GLOBAL_BODY=" "
@@ -160,6 +161,21 @@ validate_subject() {
160
161
fi
161
162
}
162
163
164
+ validate_body_length () {
165
+ local BODY=$1
166
+ local LINE=" "
167
+
168
+ while IFS= read -r LINE ;
169
+ do
170
+ local LENGTH=` echo -n " $LINE " | wc -c`
171
+
172
+ if [ $LENGTH -gt 100 ]; then
173
+ echo -e " body message line length is more than 100 charaters"
174
+ exit $ERROR_BODY_LENGTH
175
+ fi
176
+ done <<< " $BODY"
177
+ }
178
+
163
179
validate () {
164
180
local COMMIT_MSG=" $1 "
165
181
@@ -180,4 +196,6 @@ validate() {
180
196
validate_type " $TYPE "
181
197
validate_scope " $SCOPE "
182
198
validate_subject " $SUBJECT "
199
+
200
+ validate_body_length " $BODY "
183
201
}
You can’t perform that action at this time.
0 commit comments