From 7003a141aee11719a6238109b3f5567464b1ccc1 Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 27 Oct 2022 13:29:12 +0330 Subject: [PATCH 01/17] commitlintplugings.test: add one failing test --- commitlintplugins.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/commitlintplugins.test.ts b/commitlintplugins.test.ts index 2ff758c54..f7c191dce 100644 --- a/commitlintplugins.test.ts +++ b/commitlintplugins.test.ts @@ -422,6 +422,15 @@ test('proper-issue-refs3', () => { }); +test('proper-revert-message1', () => { + let commitMsgWithoutProperRevertMessage = + 'Revert "add abbreviations.ts"\n\n' + + 'This reverts commit 0272f587c7eece147e8d1756116b0b43e11c34ac.'; + let properRevertMessage1 = runCommitLintOnMsg(commitMsgWithoutProperRevertMessage); + expect(properRevertMessage1.status).not.toBe(0); +}); + + test('subject-lowercase1', () => { let commitMsgWithUppercaseAfterColon = "foo: Bar baz"; let subjectLowerCase1 = runCommitLintOnMsg(commitMsgWithUppercaseAfterColon); From d2a3a0b3409c54cb0d976baf5d2a3c980e457b13 Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 27 Oct 2022 14:16:46 +0330 Subject: [PATCH 02/17] commitlint.config: add proper-revert-message rule --- commitlint.config.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/commitlint.config.ts b/commitlint.config.ts index 6df5f392b..8793cddfc 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -356,6 +356,7 @@ module.exports = { 'too-many-spaces': [RuleStatus.Error, 'always'], 'commit-hash-alone': [RuleStatus.Error, 'always'], 'title-uppercase': [RuleStatus.Error, 'always'], + 'proper-revert-message': [RuleStatus.Error, 'always'], }, plugins: [ // TODO (ideas for more rules): @@ -602,6 +603,29 @@ module.exports = { `Please use full URLs instead of #XYZ refs.` ]; }, + + 'proper-revert-message': ({body}: {body:any}) => { + let offence = false; + // does msg have a body? + if (body !== null) { + let bodyStr = convertAnyToString(body, "body").trim(); + let lines = bodyStr.split('\n'); + console.log(lines) + if (lines.length == 1) { + if (lines[0].match('This reverts commit ') !== null) { + offence = true; + } + } + + } else { + offence = true; + } + + return [ + !offence, + `Please explain why you're reverting` + ]; + }, 'title-uppercase': ({header}: {header:any}) => { let headerStr = convertAnyToString(header, "header"); @@ -625,6 +649,7 @@ module.exports = { `Please watch out for too many whitespaces in the text` ]; }, + 'type-space-after-colon': ({header}: {header:any}) => { let headerStr = convertAnyToString(header, "header"); From ec11d60afb9f4bb27a9e58d5735a7f0c5554a10b Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 15 Nov 2022 14:04:06 +0330 Subject: [PATCH 03/17] commitlint.config: fix the rule --- commitlint.config.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/commitlint.config.ts b/commitlint.config.ts index 8793cddfc..90963c095 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -610,15 +610,7 @@ module.exports = { if (body !== null) { let bodyStr = convertAnyToString(body, "body").trim(); let lines = bodyStr.split('\n'); - console.log(lines) - if (lines.length == 1) { - if (lines[0].match('This reverts commit ') !== null) { - offence = true; - } - } - - } else { - offence = true; + offence = lines[0].match('This reverts commit ') !== null && lines.length == 1; } return [ From ec8a40c8ea31c09d55dc80ada6583c422ea5e92b Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 10 Nov 2022 18:11:29 +0330 Subject: [PATCH 04/17] commitlint.config: set defaultIgnores to false --- commitlint.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/commitlint.config.ts b/commitlint.config.ts index 90963c095..04a2252d0 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -358,6 +358,7 @@ module.exports = { 'title-uppercase': [RuleStatus.Error, 'always'], 'proper-revert-message': [RuleStatus.Error, 'always'], }, + defaultIgnores: false, plugins: [ // TODO (ideas for more rules): // * Detect if paragraphs in body have been cropped too shortly (less than 64 chars), and suggest same auto-wrap command that body-soft-max-line-length suggests, since it unwraps and wraps (both). From 0a362626d547013b23b0330adda227279afed5e7 Mon Sep 17 00:00:00 2001 From: realmarv Date: Mon, 14 Nov 2022 16:47:34 +0330 Subject: [PATCH 05/17] commitlintplugins.test: add another test --- commitlintplugins.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/commitlintplugins.test.ts b/commitlintplugins.test.ts index f7c191dce..5df4db52d 100644 --- a/commitlintplugins.test.ts +++ b/commitlintplugins.test.ts @@ -431,6 +431,16 @@ test('proper-revert-message1', () => { }); +test('proper-revert-message2', () => { + let commitMsgWithProperRevertMessage = + 'Revert "add abbreviations.ts"\n\n' + + 'This reverts commit 0272f587c7eece147e8d1756116b0b43e11c34ac\n' + + 'because/otherwise bla bla.' + let properRevertMessage2 = runCommitLintOnMsg(commitMsgWithProperRevertMessage); + expect(properRevertMessage2.status).toBe(0); +}); + + test('subject-lowercase1', () => { let commitMsgWithUppercaseAfterColon = "foo: Bar baz"; let subjectLowerCase1 = runCommitLintOnMsg(commitMsgWithUppercaseAfterColon); From 1687ccdd59ca92aa4c56cb78f15542ff4dc8ffe5 Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 15 Nov 2022 15:39:34 +0330 Subject: [PATCH 06/17] commitlintplugins.test: add another failing test --- commitlintplugins.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/commitlintplugins.test.ts b/commitlintplugins.test.ts index 5df4db52d..9d3dd9abe 100644 --- a/commitlintplugins.test.ts +++ b/commitlintplugins.test.ts @@ -441,6 +441,13 @@ test('proper-revert-message2', () => { }); +test('proper-revert-message3', () => { + let commitMsgWithProperRevertMessage = 'Revert "add abbreviations.ts"'; + let properRevertMessage3 = runCommitLintOnMsg(commitMsgWithProperRevertMessage); + expect(properRevertMessage3.status).not.toBe(0); +}); + + test('subject-lowercase1', () => { let commitMsgWithUppercaseAfterColon = "foo: Bar baz"; let subjectLowerCase1 = runCommitLintOnMsg(commitMsgWithUppercaseAfterColon); From 8432956097a137e802d66551486608781e986c9f Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 15 Nov 2022 15:50:03 +0330 Subject: [PATCH 07/17] commitlint.config: fix the rule We need to make sure that the commit message is a revert commit message. --- commitlint.config.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/commitlint.config.ts b/commitlint.config.ts index 04a2252d0..628fb5948 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -605,13 +605,19 @@ module.exports = { ]; }, - 'proper-revert-message': ({body}: {body:any}) => { + 'proper-revert-message': ({header, body}: {header: any, body: any}) => { let offence = false; + // does msg have a body? - if (body !== null) { - let bodyStr = convertAnyToString(body, "body").trim(); - let lines = bodyStr.split('\n'); - offence = lines[0].match('This reverts commit ') !== null && lines.length == 1; + if (header.match(/[Rr]evert/) !== null) { + if (body !== null) { + let bodyStr = convertAnyToString(body, "body").trim(); + let lines = bodyStr.split('\n'); + offence = lines[0].match('This reverts commit ') !== null && lines.length == 1; + } + else { + offence = true; + } } return [ From 9869a8c9bf5e91b14fce52848d84e3a3a6809a17 Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 15 Nov 2022 17:09:36 +0330 Subject: [PATCH 08/17] commitlint.config: fix the rule --- commitlint.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitlint.config.ts b/commitlint.config.ts index 628fb5948..e5b1e1c48 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -609,7 +609,7 @@ module.exports = { let offence = false; // does msg have a body? - if (header.match(/[Rr]evert/) !== null) { + if (header.match(/^[Rr]evert/) !== null) { if (body !== null) { let bodyStr = convertAnyToString(body, "body").trim(); let lines = bodyStr.split('\n'); From 8a1867acd7773ce6d020835c3b3bf30f99dbfe44 Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 17 Nov 2022 13:29:35 +0330 Subject: [PATCH 09/17] commitlint.config: move the comment line --- commitlint.config.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commitlint.config.ts b/commitlint.config.ts index e5b1e1c48..95de55abe 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -608,8 +608,9 @@ module.exports = { 'proper-revert-message': ({header, body}: {header: any, body: any}) => { let offence = false; - // does msg have a body? if (header.match(/^[Rr]evert/) !== null) { + + // does msg have a body? if (body !== null) { let bodyStr = convertAnyToString(body, "body").trim(); let lines = bodyStr.split('\n'); From 367513df681f66acf5d487c936d54d98d8da07d0 Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 17 Nov 2022 13:46:32 +0330 Subject: [PATCH 10/17] commitlintplugins.test: add one failing test The user may explain the reason of reverting in the title. --- commitlintplugins.test.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/commitlintplugins.test.ts b/commitlintplugins.test.ts index 9d3dd9abe..23384bbf4 100644 --- a/commitlintplugins.test.ts +++ b/commitlintplugins.test.ts @@ -442,12 +442,19 @@ test('proper-revert-message2', () => { test('proper-revert-message3', () => { - let commitMsgWithProperRevertMessage = 'Revert "add abbreviations.ts"'; - let properRevertMessage3 = runCommitLintOnMsg(commitMsgWithProperRevertMessage); + let commitMsgWithoutProperRevertMessage = 'Revert "add abbreviations.ts"'; + let properRevertMessage3 = runCommitLintOnMsg(commitMsgWithoutProperRevertMessage); expect(properRevertMessage3.status).not.toBe(0); }); +test('proper-revert-message4', () => { + let commitMsgWithProperRevertMessage = 'Revert .NET6 upd as it broke CI'; + let properRevertMessage4 = runCommitLintOnMsg(commitMsgWithProperRevertMessage); + expect(properRevertMessage4.status).toBe(0); +}); + + test('subject-lowercase1', () => { let commitMsgWithUppercaseAfterColon = "foo: Bar baz"; let subjectLowerCase1 = runCommitLintOnMsg(commitMsgWithUppercaseAfterColon); From 0b3443cafee7a1ae76497eaa87f5d7ca5e258152 Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 17 Nov 2022 13:59:05 +0330 Subject: [PATCH 11/17] commitlint.config: fix the detection pattern --- commitlint.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitlint.config.ts b/commitlint.config.ts index 95de55abe..fc5e154e7 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -608,7 +608,7 @@ module.exports = { 'proper-revert-message': ({header, body}: {header: any, body: any}) => { let offence = false; - if (header.match(/^[Rr]evert/) !== null) { + if (header.match(/^[Rr]evert ".+"/) !== null) { // does msg have a body? if (body !== null) { From 4cf624c90351a9c7954d1a6372186ad626ee924b Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 17 Nov 2022 14:07:40 +0330 Subject: [PATCH 12/17] commitlintplugins.test: add one failing test The reason of reverting might be at the end of the first line. --- commitlintplugins.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/commitlintplugins.test.ts b/commitlintplugins.test.ts index 23384bbf4..51119fe3b 100644 --- a/commitlintplugins.test.ts +++ b/commitlintplugins.test.ts @@ -455,6 +455,16 @@ test('proper-revert-message4', () => { }); +test('proper-revert-message5', () => { + let commitMsgWithoutProperRevertMessage = + 'Revert "add abbreviations.ts"\n\n' + + 'This reverts commit 0272f587 because bla bla.\n'; + + let properRevertMessage5 = runCommitLintOnMsg(commitMsgWithoutProperRevertMessage); + expect(properRevertMessage5.status).toBe(0); +}); + + test('subject-lowercase1', () => { let commitMsgWithUppercaseAfterColon = "foo: Bar baz"; let subjectLowerCase1 = runCommitLintOnMsg(commitMsgWithUppercaseAfterColon); From 8b19dbcf11064265bcb5757ac37f1976df3f1b79 Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 17 Nov 2022 14:18:27 +0330 Subject: [PATCH 13/17] commitlint.config: fix the regex pattern --- commitlint.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitlint.config.ts b/commitlint.config.ts index fc5e154e7..755cde131 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -614,7 +614,7 @@ module.exports = { if (body !== null) { let bodyStr = convertAnyToString(body, "body").trim(); let lines = bodyStr.split('\n'); - offence = lines[0].match('This reverts commit ') !== null && lines.length == 1; + offence = lines[0].match(/^This reverts commit [^ ]{40}.$/) !== null && lines.length == 1; } else { offence = true; From 488a60f89a2cb16e6dc1abd2ff3da80e06666ffb Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 17 Nov 2022 15:17:58 +0330 Subject: [PATCH 14/17] commitlintplugins.test: add one failing test The reason of reverting might be in the title. --- commitlintplugins.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/commitlintplugins.test.ts b/commitlintplugins.test.ts index 51119fe3b..6ca200434 100644 --- a/commitlintplugins.test.ts +++ b/commitlintplugins.test.ts @@ -465,6 +465,15 @@ test('proper-revert-message5', () => { }); +test('proper-revert-message6', () => { + let commitMsgWithProperRevertMessage = + 'Revert "process overhaul" to fix CI\n\n'; + + let properRevertMessage6 = runCommitLintOnMsg(commitMsgWithProperRevertMessage); + expect(properRevertMessage6.status).toBe(0); +}); + + test('subject-lowercase1', () => { let commitMsgWithUppercaseAfterColon = "foo: Bar baz"; let subjectLowerCase1 = runCommitLintOnMsg(commitMsgWithUppercaseAfterColon); From 9ffc85b55ebabf4293daf59d188a20c9505388cc Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 17 Nov 2022 15:24:49 +0330 Subject: [PATCH 15/17] commitlint.config: fix the regex pattern --- commitlint.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitlint.config.ts b/commitlint.config.ts index 755cde131..4c06fc4d7 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -608,7 +608,7 @@ module.exports = { 'proper-revert-message': ({header, body}: {header: any, body: any}) => { let offence = false; - if (header.match(/^[Rr]evert ".+"/) !== null) { + if (header.match(/^[Rr]evert ".+"$/) !== null) { // does msg have a body? if (body !== null) { From a9d83fd9a5c4140d1aeca08c47ea26271378e2fe Mon Sep 17 00:00:00 2001 From: realmarv Date: Fri, 18 Nov 2022 12:28:42 +0330 Subject: [PATCH 16/17] commitlint.config: fix regex --- commitlint.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitlint.config.ts b/commitlint.config.ts index 4c06fc4d7..2e2b5c185 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -614,7 +614,7 @@ module.exports = { if (body !== null) { let bodyStr = convertAnyToString(body, "body").trim(); let lines = bodyStr.split('\n'); - offence = lines[0].match(/^This reverts commit [^ ]{40}.$/) !== null && lines.length == 1; + offence = lines[0].match(/^This reverts commit [^ ]{40}\.$/) !== null && lines.length == 1; } else { offence = true; From 4eee1966c0931818fd019bd564aa74cbe9f71f62 Mon Sep 17 00:00:00 2001 From: realmarv Date: Fri, 18 Nov 2022 12:33:17 +0330 Subject: [PATCH 17/17] commitlint.config: comment for defaultIgnores --- commitlint.config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commitlint.config.ts b/commitlint.config.ts index 2e2b5c185..0e147c568 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -358,6 +358,8 @@ module.exports = { 'title-uppercase': [RuleStatus.Error, 'always'], 'proper-revert-message': [RuleStatus.Error, 'always'], }, + // Commitlint automatically ignores some kinds of commits like Revert commit messages. + // We need to set this value to false to apply our rules on these messages. defaultIgnores: false, plugins: [ // TODO (ideas for more rules):