-
Notifications
You must be signed in to change notification settings - Fork 12
A new rule that makes sure the user have explained the reason of reverting #68
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { abbr } from "./abbreviations"; | ||
| import { Helpers } from "./helpers"; | ||
| import { Helpers, When } from "./helpers"; | ||
|
|
||
| export abstract class Plugins { | ||
| public static bodyProse(rawStr: string) { | ||
|
|
@@ -278,6 +278,44 @@ export abstract class Plugins { | |
| ]; | ||
| } | ||
|
|
||
| public static defaultRevertMessage( | ||
| headerStr: string, | ||
| bodyStr: string | null, | ||
| when: When | ||
| ) { | ||
| let offence = false; | ||
| let isRevertCommitMessage = headerStr.toLowerCase().includes("revert"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @realmarv shouldn't it be "startsWith" instead of "includes"?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone changes the commit title isn't it possible that "revert" word comes somewhere else in the title?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, in which would mean that the revert message used is not default, so if when=never, then offence should be false in this case.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test for this case
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool, but why do I still see the use of includes()?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this variable is checking if the commit message is a revert commit message not if it's a default revert message |
||
|
|
||
| const negated = when === "never"; | ||
|
|
||
| if (isRevertCommitMessage) { | ||
| let isDefaultRevertHeader = | ||
| headerStr.match(/^[Rr]evert ".+"$/) !== null; | ||
|
|
||
| if (isDefaultRevertHeader) { | ||
| if (bodyStr !== null) { | ||
| let lines = bodyStr.split("\n"); | ||
| offence = | ||
| lines.length == 1 && | ||
| // 40 is the length of git commit hash. | ||
| lines[0].match(/^This reverts commit [^ ]{40}\.$/) !== | ||
| null; | ||
| } else { | ||
| offence = true; | ||
| } | ||
| } | ||
|
|
||
| offence = negated ? offence : !offence; | ||
| } | ||
| return [ | ||
| !offence, | ||
| (negated | ||
| ? `Please explain why you're reverting.` | ||
| : `Please don't change the default revert commit message.`) + | ||
| Helpers.errMessageSuffix, | ||
tehraninasab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ]; | ||
| } | ||
|
|
||
| public static titleUppercase(headerStr: string) { | ||
| let firstWord = headerStr.split(" ")[0]; | ||
| let offence = | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.