From 79f946e88e79f5063bbe775380a418bd8ab0b881 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 9 Nov 2018 11:24:33 -0500 Subject: [PATCH 1/5] lib: skip fixup! and squash! commits --- lib/index.js | 12 ++++-- lib/rules/skip-fixup-squash.js | 43 +++++++++++++++++++++ test/validator.js | 70 ++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 lib/rules/skip-fixup-squash.js diff --git a/lib/index.js b/lib/index.js index c9327f2..3e50c2c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -30,6 +30,7 @@ module.exports = class ValidateCommit extends EE { this.disableRule('reviewers') this.disableRule('metadata-end') } + this.disableRule('skip-fixup-squash') } disableRule(id) { @@ -47,9 +48,14 @@ module.exports = class ValidateCommit extends EE { } } else { const commit = new Parser(str, this) - for (const rule of this.rules.values()) { - if (rule.disabled) continue - rule.validate(commit) + if (commit.title.startsWith('fixup!') || + commit.title.startsWith('squash!')) { + this.rules.get('skip-fixup-squash').validate(commit) + } else { + for (const rule of this.rules.values()) { + if (rule.disabled) continue + rule.validate(commit) + } } setImmediate(() => { diff --git a/lib/rules/skip-fixup-squash.js b/lib/rules/skip-fixup-squash.js new file mode 100644 index 0000000..bc8812e --- /dev/null +++ b/lib/rules/skip-fixup-squash.js @@ -0,0 +1,43 @@ +'use strict' + +const id = 'skip-fixup-squash' + +module.exports = { + id: id +, meta: { + description: 'skip fixup! and squash! commits' + , recommended: true + } +, defaults: { } +, options: { } +, validate: (context, rule) => { + if (context.title.startsWith('fixup!')) { + context.report({ + id: id + , message: 'Skipping fixup! commit.' + , string: context.title + , level: 'pass' + }) + return + } + + if (context.title.startsWith('squash!')) { + context.report({ + id: id + , message: 'Skipping squash! commit.' + , string: context.title + , level: 'pass' + }) + return + } + + context.report({ + id: id + , message: 'Commit is neither fixup! nor squash!.' + , string: context.title + , line: 0 + , column: 0 + , level: 'fail' + }) + } +} diff --git a/test/validator.js b/test/validator.js index b126bd9..4a0ce9e 100644 --- a/test/validator.js +++ b/test/validator.js @@ -127,6 +127,27 @@ Date: Thu Mar 3 10:10:46 2016 -0600 test: Check memoryUsage properties. ` +const str10 = `commit 9af419a04237c3d158e71ecde9e04bbc2e77de1f +Author: Richard Lau +Date: Fri Nov 9 11:24:33 2018 -0500 + + skip fixup! and squash! commits +` + +const str11 = `commit 1fd0e4375ea3ecb62d847827365d95e63bfe03f2 +Author: Richard Lau +Date: Fri Nov 9 11:26:11 2018 -0500 + + fixup! skip fixup! and squash! commits +` + +const str12 = `commit 1fd0e4375ea3ecb62d847827365d95e63bfe03f2 +Author: Richard Lau +Date: Fri Nov 9 11:26:11 2018 -0500 + + squash! skip fixup! and squash! commits +` + test('Validator - misc', (t) => { const v = new Validator() @@ -344,5 +365,54 @@ test('Validator - real commits', (t) => { }) }) + t.test('title contains but does not start with fixup! and squash!', (tt) => { + const v = new Validator({ + 'validate-metadata': false + }) + v.lint(str10) + v.on('commit', (data) => { + const msgs = data.messages + const filtered = msgs.filter((item) => { + return item.level === 'fail' + }) + tt.equal(filtered.length, 1, 'messages.length') + tt.equal(filtered[0].message, 'Missing subsystem.') + tt.end() + }) + }) + + t.test('fixup! commits are skipped', (tt) => { + const v = new Validator({ + 'validate-metadata': false + }) + v.lint(str11) + v.on('commit', (data) => { + const msgs = data.messages + const filtered = msgs.filter((item) => { + return item.level === 'fail' + }) + tt.equal(filtered.length, 0, 'reported failures') + tt.equal(msgs.length, 1, 'messages.length') + tt.equal(msgs[0].message, 'Skipping fixup! commit.') + tt.end() + }) + }) + + t.test('squash! commits are skipped', (tt) => { + const v = new Validator({ + 'validate-metadata': false + }) + v.lint(str12) + v.on('commit', (data) => { + const msgs = data.messages + const filtered = msgs.filter((item) => { + return item.level === 'fail' + }) + tt.equal(filtered.length, 0, 'reported failures') + tt.equal(msgs.length, 1, 'messages.length') + tt.equal(msgs[0].message, 'Skipping squash! commit.') + tt.end() + }) + }) t.end() }) From d07d94439be43a65d6e57ec2ee1d8c93676e8d55 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 9 Nov 2018 19:44:48 -0500 Subject: [PATCH 2/5] squash! lib: skip fixup! and squash! commits --- bin/cmd.js | 2 ++ bin/usage.txt | 1 + lib/index.js | 10 +++--- ...fixup-squash.js => skip-autosquashable.js} | 4 +-- test/validator.js | 34 +++++++++++++++++++ 5 files changed, 45 insertions(+), 6 deletions(-) rename lib/rules/{skip-fixup-squash.js => skip-autosquashable.js} (88%) diff --git a/bin/cmd.js b/bin/cmd.js index be5660e..e827dd6 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -20,6 +20,7 @@ const knownOpts = { help: Boolean , tap: Boolean , out: path , list: Boolean +, 'check-autosquashable': Boolean } const shortHand = { h: ['--help'] , v: ['--version'] @@ -27,6 +28,7 @@ const shortHand = { h: ['--help'] , t: ['--tap'] , o: ['--out'] , l: ['--list'] +, a: ['--check-autosquashable'] } const parsed = nopt(knownOpts, shortHand) diff --git a/bin/usage.txt b/bin/usage.txt index 9e68603..7a3dd1d 100644 --- a/bin/usage.txt +++ b/bin/usage.txt @@ -8,6 +8,7 @@ core-validate-commit - Validate the commit message for a particular commit in no -V, --validate-metadata validate PR-URL and reviewers (on by default) -t, --tap output in tap format -l, --list list rules and their descriptions + -a, --check-autosquashable check autosquashable commits (on by default) examples: Validate a single sha: diff --git a/lib/index.js b/lib/index.js index 3e50c2c..c7aeb04 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,6 +11,7 @@ module.exports = class ValidateCommit extends EE { this.opts = Object.assign({ 'validate-metadata': true + , 'check-autosquashable': true }, options) this.messages = new Map() @@ -30,7 +31,7 @@ module.exports = class ValidateCommit extends EE { this.disableRule('reviewers') this.disableRule('metadata-end') } - this.disableRule('skip-fixup-squash') + this.disableRule('skip-autosquashable') } disableRule(id) { @@ -48,9 +49,10 @@ module.exports = class ValidateCommit extends EE { } } else { const commit = new Parser(str, this) - if (commit.title.startsWith('fixup!') || - commit.title.startsWith('squash!')) { - this.rules.get('skip-fixup-squash').validate(commit) + if (!this.opts['check-autosquashable'] && + (commit.title.startsWith('fixup!') || + commit.title.startsWith('squash!'))) { + this.rules.get('skip-autosquashable').validate(commit) } else { for (const rule of this.rules.values()) { if (rule.disabled) continue diff --git a/lib/rules/skip-fixup-squash.js b/lib/rules/skip-autosquashable.js similarity index 88% rename from lib/rules/skip-fixup-squash.js rename to lib/rules/skip-autosquashable.js index bc8812e..4d34514 100644 --- a/lib/rules/skip-fixup-squash.js +++ b/lib/rules/skip-autosquashable.js @@ -1,11 +1,11 @@ 'use strict' -const id = 'skip-fixup-squash' +const id = 'skip-autosquashable' module.exports = { id: id , meta: { - description: 'skip fixup! and squash! commits' + description: 'skip autosquashable fixup! and squash! commits' , recommended: true } , defaults: { } diff --git a/test/validator.js b/test/validator.js index 4a0ce9e..312dd3d 100644 --- a/test/validator.js +++ b/test/validator.js @@ -381,9 +381,42 @@ test('Validator - real commits', (t) => { }) }) + t.test('fixup! commits are not skipped by default', (tt) => { + const v = new Validator({ + 'validate-metadata': false + }) + v.lint(str11) + v.on('commit', (data) => { + const msgs = data.messages + const filtered = msgs.filter((item) => { + return item.level === 'fail' + }) + tt.equal(filtered.length, 1, 'messages.length') + tt.equal(filtered[0].message, 'Missing subsystem.') + tt.end() + }) + }) + + t.test('squash! commits are not skipped by default', (tt) => { + const v = new Validator({ + 'validate-metadata': false + }) + v.lint(str12) + v.on('commit', (data) => { + const msgs = data.messages + const filtered = msgs.filter((item) => { + return item.level === 'fail' + }) + tt.equal(filtered.length, 1, 'messages.length') + tt.equal(filtered[0].message, 'Missing subsystem.') + tt.end() + }) + }) + t.test('fixup! commits are skipped', (tt) => { const v = new Validator({ 'validate-metadata': false + , 'check-autosquashable': false }) v.lint(str11) v.on('commit', (data) => { @@ -401,6 +434,7 @@ test('Validator - real commits', (t) => { t.test('squash! commits are skipped', (tt) => { const v = new Validator({ 'validate-metadata': false + , 'check-autosquashable': false }) v.lint(str12) v.on('commit', (data) => { From 25e5398728b59ab0fdf141d1676a68969204c60a Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 9 Nov 2018 20:04:41 -0500 Subject: [PATCH 3/5] fixup! lib: skip fixup! and squash! commits --- lib/index.js | 1 - lib/rules/skip-autosquashable.js | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index c7aeb04..b57d202 100644 --- a/lib/index.js +++ b/lib/index.js @@ -31,7 +31,6 @@ module.exports = class ValidateCommit extends EE { this.disableRule('reviewers') this.disableRule('metadata-end') } - this.disableRule('skip-autosquashable') } disableRule(id) { diff --git a/lib/rules/skip-autosquashable.js b/lib/rules/skip-autosquashable.js index 4d34514..06806a2 100644 --- a/lib/rules/skip-autosquashable.js +++ b/lib/rules/skip-autosquashable.js @@ -8,6 +8,7 @@ module.exports = { description: 'skip autosquashable fixup! and squash! commits' , recommended: true } +, disabled: true , defaults: { } , options: { } , validate: (context, rule) => { From 47f98de992fe1c75626139e42a9ff54d950d704e Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 9 Nov 2018 20:45:24 -0500 Subject: [PATCH 4/5] fixup! lib: skip fixup! and squash! commits --- test/fixtures/autosquashable-pr.json | 239 +++++++++++++++++++++++++++ test/validator.js | 84 ++++++++++ 2 files changed, 323 insertions(+) create mode 100644 test/fixtures/autosquashable-pr.json diff --git a/test/fixtures/autosquashable-pr.json b/test/fixtures/autosquashable-pr.json new file mode 100644 index 0000000..7a8916f --- /dev/null +++ b/test/fixtures/autosquashable-pr.json @@ -0,0 +1,239 @@ +[ + { + "sha": "79f946e88e79f5063bbe775380a418bd8ab0b881", + "node_id": "MDY6Q29tbWl0MTU1ODE5NzI2Ojc5Zjk0NmU4OGU3OWY1MDYzYmJlNzc1MzgwYTQxOGJkOGFiMGI4ODE=", + "commit": { + "author": { + "name": "Richard Lau", + "email": "riclau@uk.ibm.com", + "date": "2018-11-09T16:24:33Z" + }, + "committer": { + "name": "Richard Lau", + "email": "riclau@uk.ibm.com", + "date": "2018-11-09T18:19:29Z" + }, + "message": "lib: skip fixup! and squash! commits", + "tree": { + "sha": "0117c48bf2beff44676b0fa8c4e652860d67e833", + "url": "https://api.github.com/repos/nodejs/core-validate-commit/git/trees/0117c48bf2beff44676b0fa8c4e652860d67e833" + }, + "url": "https://api.github.com/repos/nodejs/core-validate-commit/git/commits/79f946e88e79f5063bbe775380a418bd8ab0b881", + "comment_count": 0, + "verification": { + "verified": false, + "reason": "unsigned", + "signature": null, + "payload": null + } + }, + "url": "https://api.github.com/repos/nodejs/core-validate-commit/commits/79f946e88e79f5063bbe775380a418bd8ab0b881", + "html_url": "https://github.com/nodejs/core-validate-commit/commit/79f946e88e79f5063bbe775380a418bd8ab0b881", + "comments_url": "https://api.github.com/repos/nodejs/core-validate-commit/commits/79f946e88e79f5063bbe775380a418bd8ab0b881/comments", + "author": { + "login": "richardlau", + "id": 5445507, + "node_id": "MDQ6VXNlcjU0NDU1MDc=", + "avatar_url": "https://avatars0.githubusercontent.com/u/5445507?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/richardlau", + "html_url": "https://github.com/richardlau", + "followers_url": "https://api.github.com/users/richardlau/followers", + "following_url": "https://api.github.com/users/richardlau/following{/other_user}", + "gists_url": "https://api.github.com/users/richardlau/gists{/gist_id}", + "starred_url": "https://api.github.com/users/richardlau/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/richardlau/subscriptions", + "organizations_url": "https://api.github.com/users/richardlau/orgs", + "repos_url": "https://api.github.com/users/richardlau/repos", + "events_url": "https://api.github.com/users/richardlau/events{/privacy}", + "received_events_url": "https://api.github.com/users/richardlau/received_events", + "type": "User", + "site_admin": false + }, + "committer": { + "login": "richardlau", + "id": 5445507, + "node_id": "MDQ6VXNlcjU0NDU1MDc=", + "avatar_url": "https://avatars0.githubusercontent.com/u/5445507?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/richardlau", + "html_url": "https://github.com/richardlau", + "followers_url": "https://api.github.com/users/richardlau/followers", + "following_url": "https://api.github.com/users/richardlau/following{/other_user}", + "gists_url": "https://api.github.com/users/richardlau/gists{/gist_id}", + "starred_url": "https://api.github.com/users/richardlau/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/richardlau/subscriptions", + "organizations_url": "https://api.github.com/users/richardlau/orgs", + "repos_url": "https://api.github.com/users/richardlau/repos", + "events_url": "https://api.github.com/users/richardlau/events{/privacy}", + "received_events_url": "https://api.github.com/users/richardlau/received_events", + "type": "User", + "site_admin": false + }, + "parents": [ + { + "sha": "4e64157b6a87267fd4b9f0598159eeb968e04e21", + "url": "https://api.github.com/repos/nodejs/core-validate-commit/commits/4e64157b6a87267fd4b9f0598159eeb968e04e21", + "html_url": "https://github.com/nodejs/core-validate-commit/commit/4e64157b6a87267fd4b9f0598159eeb968e04e21" + } + ] + }, + { + "sha": "d07d94439be43a65d6e57ec2ee1d8c93676e8d55", + "node_id": "MDY6Q29tbWl0MTU1ODE5NzI2OmQwN2Q5NDQzOWJlNDNhNjVkNmU1N2VjMmVlMWQ4YzkzNjc2ZThkNTU=", + "commit": { + "author": { + "name": "Richard Lau", + "email": "riclau@uk.ibm.com", + "date": "2018-11-10T00:44:48Z" + }, + "committer": { + "name": "Richard Lau", + "email": "riclau@uk.ibm.com", + "date": "2018-11-10T00:44:48Z" + }, + "message": "squash! lib: skip fixup! and squash! commits", + "tree": { + "sha": "b37fb650a27feaddb950d153a7085fec2347ec7d", + "url": "https://api.github.com/repos/nodejs/core-validate-commit/git/trees/b37fb650a27feaddb950d153a7085fec2347ec7d" + }, + "url": "https://api.github.com/repos/nodejs/core-validate-commit/git/commits/d07d94439be43a65d6e57ec2ee1d8c93676e8d55", + "comment_count": 0, + "verification": { + "verified": false, + "reason": "unsigned", + "signature": null, + "payload": null + } + }, + "url": "https://api.github.com/repos/nodejs/core-validate-commit/commits/d07d94439be43a65d6e57ec2ee1d8c93676e8d55", + "html_url": "https://github.com/nodejs/core-validate-commit/commit/d07d94439be43a65d6e57ec2ee1d8c93676e8d55", + "comments_url": "https://api.github.com/repos/nodejs/core-validate-commit/commits/d07d94439be43a65d6e57ec2ee1d8c93676e8d55/comments", + "author": { + "login": "richardlau", + "id": 5445507, + "node_id": "MDQ6VXNlcjU0NDU1MDc=", + "avatar_url": "https://avatars0.githubusercontent.com/u/5445507?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/richardlau", + "html_url": "https://github.com/richardlau", + "followers_url": "https://api.github.com/users/richardlau/followers", + "following_url": "https://api.github.com/users/richardlau/following{/other_user}", + "gists_url": "https://api.github.com/users/richardlau/gists{/gist_id}", + "starred_url": "https://api.github.com/users/richardlau/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/richardlau/subscriptions", + "organizations_url": "https://api.github.com/users/richardlau/orgs", + "repos_url": "https://api.github.com/users/richardlau/repos", + "events_url": "https://api.github.com/users/richardlau/events{/privacy}", + "received_events_url": "https://api.github.com/users/richardlau/received_events", + "type": "User", + "site_admin": false + }, + "committer": { + "login": "richardlau", + "id": 5445507, + "node_id": "MDQ6VXNlcjU0NDU1MDc=", + "avatar_url": "https://avatars0.githubusercontent.com/u/5445507?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/richardlau", + "html_url": "https://github.com/richardlau", + "followers_url": "https://api.github.com/users/richardlau/followers", + "following_url": "https://api.github.com/users/richardlau/following{/other_user}", + "gists_url": "https://api.github.com/users/richardlau/gists{/gist_id}", + "starred_url": "https://api.github.com/users/richardlau/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/richardlau/subscriptions", + "organizations_url": "https://api.github.com/users/richardlau/orgs", + "repos_url": "https://api.github.com/users/richardlau/repos", + "events_url": "https://api.github.com/users/richardlau/events{/privacy}", + "received_events_url": "https://api.github.com/users/richardlau/received_events", + "type": "User", + "site_admin": false + }, + "parents": [ + { + "sha": "79f946e88e79f5063bbe775380a418bd8ab0b881", + "url": "https://api.github.com/repos/nodejs/core-validate-commit/commits/79f946e88e79f5063bbe775380a418bd8ab0b881", + "html_url": "https://github.com/nodejs/core-validate-commit/commit/79f946e88e79f5063bbe775380a418bd8ab0b881" + } + ] + }, + { + "sha": "25e5398728b59ab0fdf141d1676a68969204c60a", + "node_id": "MDY6Q29tbWl0MTU1ODE5NzI2OjI1ZTUzOTg3MjhiNTlhYjBmZGYxNDFkMTY3NmE2ODk2OTIwNGM2MGE=", + "commit": { + "author": { + "name": "Richard Lau", + "email": "riclau@uk.ibm.com", + "date": "2018-11-10T01:04:41Z" + }, + "committer": { + "name": "Richard Lau", + "email": "riclau@uk.ibm.com", + "date": "2018-11-10T01:04:41Z" + }, + "message": "fixup! lib: skip fixup! and squash! commits", + "tree": { + "sha": "c4f1faf780d28fce67c7d1ec0a7e0617f43bc79a", + "url": "https://api.github.com/repos/nodejs/core-validate-commit/git/trees/c4f1faf780d28fce67c7d1ec0a7e0617f43bc79a" + }, + "url": "https://api.github.com/repos/nodejs/core-validate-commit/git/commits/25e5398728b59ab0fdf141d1676a68969204c60a", + "comment_count": 0, + "verification": { + "verified": false, + "reason": "unsigned", + "signature": null, + "payload": null + } + }, + "url": "https://api.github.com/repos/nodejs/core-validate-commit/commits/25e5398728b59ab0fdf141d1676a68969204c60a", + "html_url": "https://github.com/nodejs/core-validate-commit/commit/25e5398728b59ab0fdf141d1676a68969204c60a", + "comments_url": "https://api.github.com/repos/nodejs/core-validate-commit/commits/25e5398728b59ab0fdf141d1676a68969204c60a/comments", + "author": { + "login": "richardlau", + "id": 5445507, + "node_id": "MDQ6VXNlcjU0NDU1MDc=", + "avatar_url": "https://avatars0.githubusercontent.com/u/5445507?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/richardlau", + "html_url": "https://github.com/richardlau", + "followers_url": "https://api.github.com/users/richardlau/followers", + "following_url": "https://api.github.com/users/richardlau/following{/other_user}", + "gists_url": "https://api.github.com/users/richardlau/gists{/gist_id}", + "starred_url": "https://api.github.com/users/richardlau/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/richardlau/subscriptions", + "organizations_url": "https://api.github.com/users/richardlau/orgs", + "repos_url": "https://api.github.com/users/richardlau/repos", + "events_url": "https://api.github.com/users/richardlau/events{/privacy}", + "received_events_url": "https://api.github.com/users/richardlau/received_events", + "type": "User", + "site_admin": false + }, + "committer": { + "login": "richardlau", + "id": 5445507, + "node_id": "MDQ6VXNlcjU0NDU1MDc=", + "avatar_url": "https://avatars0.githubusercontent.com/u/5445507?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/richardlau", + "html_url": "https://github.com/richardlau", + "followers_url": "https://api.github.com/users/richardlau/followers", + "following_url": "https://api.github.com/users/richardlau/following{/other_user}", + "gists_url": "https://api.github.com/users/richardlau/gists{/gist_id}", + "starred_url": "https://api.github.com/users/richardlau/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/richardlau/subscriptions", + "organizations_url": "https://api.github.com/users/richardlau/orgs", + "repos_url": "https://api.github.com/users/richardlau/repos", + "events_url": "https://api.github.com/users/richardlau/events{/privacy}", + "received_events_url": "https://api.github.com/users/richardlau/received_events", + "type": "User", + "site_admin": false + }, + "parents": [ + { + "sha": "d07d94439be43a65d6e57ec2ee1d8c93676e8d55", + "url": "https://api.github.com/repos/nodejs/core-validate-commit/commits/d07d94439be43a65d6e57ec2ee1d8c93676e8d55", + "html_url": "https://github.com/nodejs/core-validate-commit/commit/d07d94439be43a65d6e57ec2ee1d8c93676e8d55" + } + ] + } +] diff --git a/test/validator.js b/test/validator.js index 312dd3d..f5cc50a 100644 --- a/test/validator.js +++ b/test/validator.js @@ -368,6 +368,7 @@ test('Validator - real commits', (t) => { t.test('title contains but does not start with fixup! and squash!', (tt) => { const v = new Validator({ 'validate-metadata': false + , 'check-autosquashable': false }) v.lint(str10) v.on('commit', (data) => { @@ -448,5 +449,88 @@ test('Validator - real commits', (t) => { tt.end() }) }) + + t.test('autosquashable commits are not skipped by default', (tt) => { + const v = new Validator({ + 'validate-metadata': false + }) + v.lint(require('./fixtures/autosquashable-pr')) + v.on('commit', (data) => { + switch (data.commit.sha) { + case '79f946e88e79f5063bbe775380a418bd8ab0b881': { + const msgs = data.messages + const filtered = msgs.filter((item) => { + return item.level === 'fail' + }) + tt.equal(filtered.length, 0, 'reported failures') + break + } + case 'd07d94439be43a65d6e57ec2ee1d8c93676e8d55': { + const msgs = data.messages + const filtered = msgs.filter((item) => { + return item.level === 'fail' + }) + tt.equal(filtered.length, 1, 'reported failures') + tt.equal(filtered[0].message, 'Invalid subsystem: "squash! lib"') + break + } + case '25e5398728b59ab0fdf141d1676a68969204c60a': { + const msgs = data.messages + const filtered = msgs.filter((item) => { + return item.level === 'fail' + }) + tt.equal(filtered.length, 1, 'reported failures') + tt.equal(filtered[0].message, 'Invalid subsystem: "fixup! lib"') + tt.end() + break + } + default: + tt.fail(`unexpected commit sha ${data.commit.sha}`) + } + }) + }) + + t.test('autosquashable commits are skipped', (tt) => { + const v = new Validator({ + 'validate-metadata': false + , 'check-autosquashable': false + }) + v.lint(require('./fixtures/autosquashable-pr')) + v.on('commit', (data) => { + switch (data.commit.sha) { + case '79f946e88e79f5063bbe775380a418bd8ab0b881': { + const msgs = data.messages + const filtered = msgs.filter((item) => { + return item.level === 'fail' + }) + tt.equal(filtered.length, 0, 'reported failures') + break + } + case 'd07d94439be43a65d6e57ec2ee1d8c93676e8d55': { + const msgs = data.messages + const filtered = msgs.filter((item) => { + return item.level === 'fail' + }) + tt.equal(filtered.length, 0, 'reported failures') + tt.equal(msgs.length, 1, 'messages.length') + tt.equal(msgs[0].message, 'Skipping squash! commit.') + break + } + case '25e5398728b59ab0fdf141d1676a68969204c60a': { + const msgs = data.messages + const filtered = msgs.filter((item) => { + return item.level === 'fail' + }) + tt.equal(filtered.length, 0, 'reported failures') + tt.equal(msgs.length, 1, 'messages.length') + tt.equal(msgs[0].message, 'Skipping fixup! commit.') + tt.end() + break + } + default: + tt.fail(`unexpected commit sha ${data.commit.sha}`) + } + }) + }) t.end() }) From 229ba0cf9be618c8efaa0bcf265f5a9d38c3c92f Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 9 Nov 2018 20:53:53 -0500 Subject: [PATCH 5/5] fixup! lib: skip fixup! and squash! commits --- lib/rules/skip-autosquashable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rules/skip-autosquashable.js b/lib/rules/skip-autosquashable.js index 06806a2..4598f01 100644 --- a/lib/rules/skip-autosquashable.js +++ b/lib/rules/skip-autosquashable.js @@ -17,7 +17,7 @@ module.exports = { id: id , message: 'Skipping fixup! commit.' , string: context.title - , level: 'pass' + , level: 'warn' }) return } @@ -27,7 +27,7 @@ module.exports = { id: id , message: 'Skipping squash! commit.' , string: context.title - , level: 'pass' + , level: 'warn' }) return }