File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed
__tests__/unit/validators Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,44 @@ test('oldest_only sub option', async () => {
76
76
expect ( validation . status ) . toBe ( 'pass' )
77
77
} )
78
78
79
+ test ( 'newest_only sub option' , async ( ) => {
80
+ const commit = new Commit ( )
81
+ const settings = {
82
+ do : 'commit' ,
83
+ message : {
84
+ regex : 'feat:' ,
85
+ newest_only : true
86
+ }
87
+ }
88
+ const date = Date . now ( )
89
+ const commits = [
90
+ {
91
+ commit : {
92
+ author : {
93
+ date
94
+ } ,
95
+ message : 'fix: that'
96
+ }
97
+ } ,
98
+ {
99
+ commit : {
100
+ author : {
101
+ date : date + 1
102
+ } ,
103
+ message : 'fix: this'
104
+ }
105
+ }
106
+ ]
107
+
108
+ let validation = await commit . processValidate ( createMockContext ( commits ) , settings )
109
+ expect ( validation . status ) . toBe ( 'fail' )
110
+
111
+ commits [ 1 ] . commit . message = 'feat: this'
112
+
113
+ validation = await commit . processValidate ( createMockContext ( commits ) , settings )
114
+ expect ( validation . status ) . toBe ( 'pass' )
115
+ } )
116
+
79
117
test ( 'skip_merge sub option' , async ( ) => {
80
118
const commit = new Commit ( )
81
119
const settings = {
Original file line number Diff line number Diff line change 1
1
CHANGELOG
2
2
=====================================
3
- | August 20, 2022: fix: supported events for `request_review` action `#623 <https://github.com/mergeability/mergeable/pull/651>`
3
+ | August 20, 2022: fix: supported events for `request_review` action `#623 <https://github.com/mergeability/mergeable/pull/651>`_
4
+ | August 2, 2022: feat: Add newest_only commit validation setting `#649 <https://github.com/mergeability/mergeable/pull/649>`_
4
5
| April 7, 2022: feat: Support adding deployment labels from values `#631 <https://github.com/mergeability/mergeable/pull/631>`_
5
6
| March 22, 2022: fix: pass comment instance to removeErrorComments `#626 <https://github.com/mergeability/mergeable/pull/626>`_
6
7
| February 24, 2022: fix: correct indentation on documentation `#623 <https://github.com/mergeability/mergeable/pull/623>`_
Original file line number Diff line number Diff line change 9
9
message: 'Custom message' # Semantic release conventions must be followed
10
10
skip_merge: true # Optional, Default is true. Will skip commit with message that includes 'Merge'
11
11
oldest_only: false # Optional, Default is false. Only check the regex against the oldest commit
12
+ newest_only: false # Optional, Default is false. Only check the regex against the newest commit
12
13
single_commit_only: false # Optional, Default is false. only process this validator if there is one commit
13
14
jira:
14
15
regex: '[A-Z][A-Z0-9]+-\d+'
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ class Commit extends Validator {
28
28
message : 'string' ,
29
29
skip_merge : 'boolean' ,
30
30
oldest_only : 'boolean' ,
31
+ newest_only : 'boolean' ,
31
32
single_commit_only : 'boolean'
32
33
}
33
34
}
@@ -39,6 +40,7 @@ class Commit extends Validator {
39
40
40
41
const messageSettings = validationSettings . message
41
42
const oldestCommitOnly = _ . isUndefined ( messageSettings . oldest_only ) ? false : messageSettings . oldest_only
43
+ const newestCommitOnly = _ . isUndefined ( messageSettings . newest_only ) ? false : messageSettings . newest_only
42
44
const skipMerge = _ . isUndefined ( messageSettings . skip_merge ) ? true : messageSettings . skip_merge
43
45
const singleCommitOnly = _ . isUndefined ( messageSettings . single_commit_only ) ? false : messageSettings . single_commit_only
44
46
@@ -67,6 +69,10 @@ class Commit extends Validator {
67
69
orderedCommits = [ orderedCommits [ 0 ] ]
68
70
}
69
71
72
+ if ( newestCommitOnly ) {
73
+ orderedCommits = [ orderedCommits [ orderedCommits . length - 1 ] ]
74
+ }
75
+
70
76
const commitMessages = orderedCommits . map ( commit => commit . message )
71
77
72
78
const result = await mustInclude . process ( validatorContext , commitMessages , {
You can’t perform that action at this time.
0 commit comments