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 revert commit titles that were elongated by git #99

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/rules/title-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = {
max_length: 72
},
validate: (context, rule) => {
const max = rule.options.max_length
const isRevertCommit = /^Revert ".*"$/.test(context.title)
const max = rule.options.max_length + (isRevertCommit ? 'Revert ""'.length : 0)
if (context.title.length > max) {
context.report({
id: id,
Expand All @@ -31,7 +32,7 @@ module.exports = {
return
}

const len = rule.options.length
const len = rule.options.length + (isRevertCommit ? 'Revert ""'.length : 0)
if (context.title.length > len) {
context.report({
id: id,
Expand Down
81 changes: 80 additions & 1 deletion test/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const str2 = `commit b6475b9a9d0da0971eec7eb5559dff4d18a0e721
Author: Evan Lucas <[email protected]>
Date: Tue Mar 29 08:09:37 2016 -0500

Revert "tty: don't read from console stream upon creation"
Revert "tty: do not read from the console stream upon creation"

This reverts commit 461138929498f31bd35bea61aa4375a2f56cceb7.

Expand Down Expand Up @@ -127,6 +127,42 @@ Date: Thu Mar 3 10:10:46 2016 -0600
test: Check memoryUsage properties.
`

const str10 = `commit b04fe688d5859f707cf1a5e0206967268118bf7a
Author: Darshan Sen <[email protected]>
Date: Sun May 1 21:10:21 2022 +0530

Revert "bootstrap: delay the instantiation of maps in per-context scripts"

The linked issue, https://bugs.chromium.org/p/v8/issues/detail?id=6593,
is marked as "Fixed", so I think we can revert this now.

This reverts commit 08a9c4a996964aca909cd75fa8ecafd652c54885.

Signed-off-by: Darshan Sen <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/42934
Refs: https://bugs.chromium.org/p/v8/issues/detail?id=9187
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
`

const str11 = `commit b04fe688d5859f707cf1a5e0206967268118bf7a
Author: Darshan Sen <[email protected]>
Date: Sun May 1 21:10:21 2022 +0530

Revert "bootstrap: delay the instantiation of all maps in the per-context scripts"

The linked issue, https://bugs.chromium.org/p/v8/issues/detail?id=6593,
is marked as "Fixed", so I think we can revert this now.

This reverts commit 08a9c4a996964aca909cd75fa8ecafd652c54885.

Signed-off-by: Darshan Sen <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/42934
Refs: https://bugs.chromium.org/p/v8/issues/detail?id=9187
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
`

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

Expand Down Expand Up @@ -215,6 +251,49 @@ test('Validator - real commits', (t) => {
})
})

t.test('accept revert commit titles that are elongated by git', (tt) => {
const v = new Validator()
v.lint(str10)
v.on('commit', (data) => {
const c = data.commit.toJSON()
tt.equal(c.sha, 'b04fe688d5859f707cf1a5e0206967268118bf7a', 'sha')
tt.equal(c.date, 'Sun May 1 21:10:21 2022 +0530', 'date')
tt.deepEqual(c.subsystems, ['bootstrap'], 'subsystems')
tt.equal(c.prUrl, 'https://github.com/nodejs/node/pull/42934', 'pr')
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('reject revert commit titles whose original titles are really long', (tt) => {
const v = new Validator()
v.lint(str11)
v.on('commit', (data) => {
const c = data.commit.toJSON()
tt.equal(c.sha, 'b04fe688d5859f707cf1a5e0206967268118bf7a', 'sha')
tt.equal(c.date, 'Sun May 1 21:10:21 2022 +0530', 'date')
tt.deepEqual(c.subsystems, ['bootstrap'], 'subsystems')
tt.equal(c.prUrl, 'https://github.com/nodejs/node/pull/42934', 'pr')
tt.equal(c.revert, true, 'revert')
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 1, 'messages.length')
const ids = filtered.map((item) => {
return item.id
})
const exp = ['title-length']
tt.deepEqual(ids.sort(), exp.sort(), 'message ids')
tt.end()
})
})

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