Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rules: accept "deps: V8" as the subsystem for revert commits #102

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/rules/title-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ module.exports = {
recommended: true
},
validate: (context, rule) => {
const isRevertCommit = /^Revert ".*"$/.test(context.title)
const revertPrefixLength = 'Revert "'.length
const titleWithoutRevertPrefix = isRevertCommit
? context.title.substr(revertPrefixLength,
context.title.length - revertPrefixLength - 1) : context.title
let pass = true
if (/[.?!]$/.test(context.title)) {
if (/[.?!]$/.test(titleWithoutRevertPrefix)) {
context.report({
id: id,
message: 'Do not use punctuation at end of title.',
Expand All @@ -23,7 +28,7 @@ module.exports = {
}

{
const result = /^([^:]+:)[^ ]/.exec(context.title)
const result = /^([^:]+:)[^ ]/.exec(titleWithoutRevertPrefix)
if (result) {
context.report({
id: id,
Expand All @@ -38,7 +43,7 @@ module.exports = {
}

{
const result = /\s\s/.exec(context.title)
const result = /\s\s/.exec(titleWithoutRevertPrefix)
if (result) {
context.report({
id: id,
Expand All @@ -52,9 +57,9 @@ module.exports = {
}
}

const isV8 = context.title.startsWith('deps: V8:')
const isV8 = titleWithoutRevertPrefix.startsWith('deps: V8:')
if (!isV8) {
const result = /^([^:]+?): [A-Z]/.exec(context.title)
const result = /^([^:]+?): [A-Z]/.exec(titleWithoutRevertPrefix)
if (result) {
context.report({
id: id,
Expand Down
29 changes: 29 additions & 0 deletions test/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ Date: Sun May 1 21:10:21 2022 +0530
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
`

const str12 = `commit cbb404503c9df13aaeb3dd8b345cb3f34c8c07e4
Author: Michaël Zasso <targos@protonmail.com>
Date: Sat Oct 22 10:22:43 2022 +0200

Revert "deps: V8: forward declaration of \`Rtl*FunctionTable\`"

This reverts commit 01bc8e6fd81314e76c7fb0d09e5310f609e48bee.
`

test('Validator - misc', (t) => {
const v = new Validator()

Expand Down Expand Up @@ -294,6 +303,26 @@ test('Validator - real commits', (t) => {
})
})

t.test('accept deps: V8 as the subsystem for revert commits', (tt) => {
const v = new Validator({
'validate-metadata': false
})
v.lint(str12)
v.on('commit', (data) => {
const c = data.commit.toJSON()
tt.equal(c.sha, 'cbb404503c9df13aaeb3dd8b345cb3f34c8c07e4', 'sha')
tt.equal(c.date, 'Sat Oct 22 10:22:43 2022 +0200', 'date')
tt.deepEqual(c.subsystems, ['deps'], 'subsystems')
tt.equal(c.revert, true, 'revert')
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 0, 'messages.length')
tt.end()
})
})

t.test('invalid pr-url, missing subsystem', (tt) => {
const v = new Validator()
v.lint(str4)
Expand Down