Skip to content

Commit 7739b32

Browse files
authored
rules: accept "deps: V8" as the subsystem for revert commits (#102)
The commit, nodejs/node@cbb4045, was being flagged as invalid by core-validate-commit because of this error: ```txt Error: not ok 6 title-format: First word after subsystem(s) in title should be lowercase. (Revert "deps: V8: forward declaration of `Rtl*FunctionTable`") ``` This is incorrect because "deps: V8" is a valid subsystem. This change makes sure that revert commits with such a subsystem is accepted. Signed-off-by: Darshan Sen <raisinten@gmail.com> Signed-off-by: Darshan Sen <raisinten@gmail.com>
1 parent 758f3d7 commit 7739b32

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

lib/rules/title-format.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ module.exports = {
99
recommended: true
1010
},
1111
validate: (context, rule) => {
12+
const isRevertCommit = /^Revert ".*"$/.test(context.title)
13+
const revertPrefixLength = 'Revert "'.length
14+
const titleWithoutRevertPrefix = isRevertCommit
15+
? context.title.substr(revertPrefixLength,
16+
context.title.length - revertPrefixLength - 1) : context.title
1217
let pass = true
13-
if (/[.?!]$/.test(context.title)) {
18+
if (/[.?!]$/.test(titleWithoutRevertPrefix)) {
1419
context.report({
1520
id: id,
1621
message: 'Do not use punctuation at end of title.',
@@ -23,7 +28,7 @@ module.exports = {
2328
}
2429

2530
{
26-
const result = /^([^:]+:)[^ ]/.exec(context.title)
31+
const result = /^([^:]+:)[^ ]/.exec(titleWithoutRevertPrefix)
2732
if (result) {
2833
context.report({
2934
id: id,
@@ -38,7 +43,7 @@ module.exports = {
3843
}
3944

4045
{
41-
const result = /\s\s/.exec(context.title)
46+
const result = /\s\s/.exec(titleWithoutRevertPrefix)
4247
if (result) {
4348
context.report({
4449
id: id,
@@ -52,9 +57,9 @@ module.exports = {
5257
}
5358
}
5459

55-
const isV8 = context.title.startsWith('deps: V8:')
60+
const isV8 = titleWithoutRevertPrefix.startsWith('deps: V8:')
5661
if (!isV8) {
57-
const result = /^([^:]+?): [A-Z]/.exec(context.title)
62+
const result = /^([^:]+?): [A-Z]/.exec(titleWithoutRevertPrefix)
5863
if (result) {
5964
context.report({
6065
id: id,

test/validator.js

+29
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ Date: Sun May 1 21:10:21 2022 +0530
163163
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
164164
`
165165

166+
const str12 = `commit cbb404503c9df13aaeb3dd8b345cb3f34c8c07e4
167+
Author: Michaël Zasso <targos@protonmail.com>
168+
Date: Sat Oct 22 10:22:43 2022 +0200
169+
170+
Revert "deps: V8: forward declaration of \`Rtl*FunctionTable\`"
171+
172+
This reverts commit 01bc8e6fd81314e76c7fb0d09e5310f609e48bee.
173+
`
174+
166175
test('Validator - misc', (t) => {
167176
const v = new Validator()
168177

@@ -294,6 +303,26 @@ test('Validator - real commits', (t) => {
294303
})
295304
})
296305

306+
t.test('accept deps: V8 as the subsystem for revert commits', (tt) => {
307+
const v = new Validator({
308+
'validate-metadata': false
309+
})
310+
v.lint(str12)
311+
v.on('commit', (data) => {
312+
const c = data.commit.toJSON()
313+
tt.equal(c.sha, 'cbb404503c9df13aaeb3dd8b345cb3f34c8c07e4', 'sha')
314+
tt.equal(c.date, 'Sat Oct 22 10:22:43 2022 +0200', 'date')
315+
tt.deepEqual(c.subsystems, ['deps'], 'subsystems')
316+
tt.equal(c.revert, true, 'revert')
317+
const msgs = data.messages
318+
const filtered = msgs.filter((item) => {
319+
return item.level === 'fail'
320+
})
321+
tt.equal(filtered.length, 0, 'messages.length')
322+
tt.end()
323+
})
324+
})
325+
297326
t.test('invalid pr-url, missing subsystem', (tt) => {
298327
const v = new Validator()
299328
v.lint(str4)

0 commit comments

Comments
 (0)