-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
8a1c5e4
commit 552cfe5
Showing
4 changed files
with
61 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,42 @@ | ||
const { isBranchNameValid } = require("./branch"); | ||
|
||
describe("branch", () => { | ||
test("recognize valid branch names", () => { | ||
expect(isBranchNameValid("core/foo")).toBe(true); | ||
expect(isBranchNameValid("feature/foo")).toBe(true); | ||
expect(isBranchNameValid("fix/foo")).toBe(true); | ||
expect(isBranchNameValid("hotfix/foo")).toBe(true); | ||
expect(isBranchNameValid("asset/foo")).toBe(true); | ||
expect(isBranchNameValid("rework/foo")).toBe(true); | ||
expect(isBranchNameValid("rework/DriveFooterBar")).toBe(true); | ||
expect(isBranchNameValid("documentation/foo")).toBe(true); | ||
expect(isBranchNameValid("dependabot/foo")).toBe(true); | ||
expect(isBranchNameValid("dependabot/npm_and_yarn/axios-0.21.1")).toBe( | ||
true | ||
); | ||
expect(isBranchNameValid("mobsuccessbot/foo")).toBe(true); | ||
expect(isBranchNameValid("mobsuccessbot/foo@foo")).toBe(true); | ||
expect(isBranchNameValid("mobsuccessbot/foo@foo/foo")).toBe(true); | ||
expect(isBranchNameValid("foo/foo-bar")).toBe(false); | ||
expect(isBranchNameValid("core/foo--bar")).toBe(true); | ||
expect(isBranchNameValid("core/foo--bar--z")).toBe(true); | ||
expect(isBranchNameValid("feature/branch-name_from_linear")).toBe(true); | ||
test.each([ | ||
"feat/foo", | ||
"fix/foo", | ||
"refactor/foo", | ||
"docs/foo", | ||
"chore/foo--bar", | ||
"chore/foo--bar--z", | ||
"feat/branch-name_from_linear", | ||
"mobsuccessbot/foo", | ||
"mobsuccessbot/foo@foo", | ||
"mobsuccessbot/foo@foo/foo", | ||
"dependabot/foo", | ||
"dependabot/npm_and_yarn/axios-0.21.1", | ||
"dependabot/npm_and_yarn/axios-0.21.1", | ||
])("Test branch %s should be valid", (branch) => { | ||
expect(isBranchNameValid(branch)).toBe(true); | ||
}); | ||
test("recognize invalid branch names", () => { | ||
expect(isBranchNameValid("core/npm_and_yarn/axios-0.21.1")).toBe(false); | ||
expect(isBranchNameValid("core")).toBe(false); | ||
expect(isBranchNameValid("core/")).toBe(false); | ||
expect(isBranchNameValid("core/FOO")).toBe(false); | ||
expect(isBranchNameValid("foo/foo")).toBe(false); | ||
expect(isBranchNameValid("foo/foo/bar")).toBe(false); | ||
expect(isBranchNameValid("fix/DriveFooterBar")).toBe(false); | ||
expect(isBranchNameValid("rework/fooDriveFooterBar")).toBe(false); | ||
expect(isBranchNameValid("core//foo")).toBe(false); | ||
test.each([ | ||
"core/foo--bar", | ||
"core/foo--bar--z", | ||
"foo/foo-bar", | ||
"feature/foo", | ||
"hotfix/foo", | ||
"core/foo", | ||
"asset/foo", | ||
"documentation/foo", | ||
"chore", | ||
"chore/", | ||
"chore/FOO", | ||
"foo/foo", | ||
"foo/foo/bar", | ||
"fix/DriveFooterBar", | ||
"refactor/DriveFooterBar", | ||
"rework/fooDriveFooterBar", | ||
"chore//foo", | ||
])("Test branch %s should be invalid", (branch) => { | ||
expect(isBranchNameValid(branch)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,9 @@ | ||
exports.isPullRequestTitleValid = (pullRequestName) => | ||
isPullRequestTitleValid(pullRequestName) || | ||
isPullRequestTitleValidLegacy(pullRequestName); | ||
|
||
function isPullRequestTitleValidLegacy(pullRequestName) { | ||
return ( | ||
!!pullRequestName.match( | ||
/^(Add|Clean|Fix|Improve|Remove|Update|Rework|Ignore|Bump|Switch|Migrate) .+$/ | ||
/* remember to edit the Notion when changing this value: | ||
https://www.notion.so/mobsuccess/Git-Guidelines-41996ef576cb4f29b7737772b74289c5 | ||
*/ | ||
) || !!pullRequestName.match(/^Revert ".*"$/) | ||
); | ||
} | ||
|
||
// commit convention: prefix([optional scope]): description | ||
function isPullRequestTitleValid(pullRequestName) { | ||
return !!pullRequestName.match( | ||
/^(feat|fix|chore|docs|refactor|test|revert|build|ci|perf|style|change|remove|poc)(?:\(.+\))?!?:.+/ | ||
); | ||
} | ||
|
||
module.exports = { | ||
isPullRequestTitleValid, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,23 @@ | ||
const { isPullRequestTitleValid } = require("./pullRequest"); | ||
|
||
describe("pull request", () => { | ||
test("recognize pull request branch names", () => { | ||
expect(isPullRequestTitleValid("Add feature")).toBe(true); | ||
expect(isPullRequestTitleValid("chore: remove base files")).toBe(true); | ||
expect( | ||
isPullRequestTitleValid( | ||
"fix(design-system): update color palette for accessibility compliance" | ||
) | ||
).toBe(true); | ||
expect( | ||
isPullRequestTitleValid( | ||
"feat!: send an email to the customer when a product is shipped" | ||
) | ||
).toBe(true); | ||
expect( | ||
isPullRequestTitleValid( | ||
"feat(api)!: send an email to the customer when a product is shipped" | ||
) | ||
).toBe(true); | ||
test.each([ | ||
"chore: remove base files", | ||
"fix(design-system): update color palette for accessibility compliance", | ||
"feat!: send an email to the customer when a product is shipped", | ||
"feat(api)!: send an email to the customer when a product is shipped", | ||
])("Test pull request title %s should be valid", (title) => { | ||
expect(isPullRequestTitleValid(title)).toBe(true); | ||
}); | ||
test("recognize invalid branch names", () => { | ||
expect(isPullRequestTitleValid("add feature")).toBe(false); | ||
expect(isPullRequestTitleValid("chore remove base files")).toBe(false); | ||
expect(isPullRequestTitleValid("chore(): remove base files")).toBe(false); | ||
expect(isPullRequestTitleValid("add: add new project")).toBe(false); | ||
expect( | ||
isPullRequestTitleValid( | ||
"feat!(api): send an email to the customer when a product is shipped" | ||
) | ||
).toBe(false); | ||
test.each([ | ||
"Add feature", | ||
"Remove feature", | ||
"add feature", | ||
"chore remove base files", | ||
"chore(): remove base files", | ||
"add: add new project", | ||
"feat!(api): send an email to the customer when a product is shipped", | ||
])("Test pull request title %s should be invalid", (title) => { | ||
expect(isPullRequestTitleValid(title)).toBe(false); | ||
}); | ||
}); |