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

chore!: remove old naming compliance [DEVOP-143] #91

Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 4 additions & 17 deletions lib/branch.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
exports.isBranchNameValid = (branchName) =>
isBranchNameValid(branchName) || isBranchNameValidLegacy(branchName);

function isBranchNameValidLegacy(branchName) {
return (
(!!branchName.match(
/^(core|feature|fix|hotfix|asset|rework|documentation|mobsuccessbot|dependabot)\/([a-z][a-z0-9._-]*)$/
) ||
!!branchName.match(/^(mobsuccessbot)\/([a-z0-9_\-@./_-]*)$/) ||
!!branchName.match(/^(dependabot)\/([a-z][a-zA-Z0-9./_-]*)$/) ||
!!branchName.match(/^revert-[0-9]+-/) ||
!!branchName.match(/^(rework)\/([A-Z][a-zA-Z0-9.-]*)$/)) &&
!branchName.match(/---/) &&
!branchName.match(/\/\//)
);
}

function isBranchNameValid(branchName) {
return (
!!branchName.match(
Expand All @@ -24,3 +7,7 @@ function isBranchNameValid(branchName) {
!!branchName.match(/^(dependabot)\/([a-z][a-zA-Z0-9./_-]*)$/)
);
}

module.exports = {
isBranchNameValid,
};
41 changes: 22 additions & 19 deletions lib/branch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,38 @@ 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("feat/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("refactor/foo")).toBe(true);
expect(isBranchNameValid("docs/foo")).toBe(true);
expect(isBranchNameValid("chore/foo--bar")).toBe(true);
expect(isBranchNameValid("chore/foo--bar--z")).toBe(true);
expect(isBranchNameValid("feat/branch-name_from_linear")).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("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("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("core/foo--bar")).toBe(false);
pierresisson marked this conversation as resolved.
Show resolved Hide resolved
expect(isBranchNameValid("core/foo--bar--z")).toBe(false);
expect(isBranchNameValid("foo/foo-bar")).toBe(false);
expect(isBranchNameValid("feature/foo")).toBe(false);
expect(isBranchNameValid("hotfix/foo")).toBe(false);
expect(isBranchNameValid("core/foo")).toBe(false);
expect(isBranchNameValid("asset/foo")).toBe(false);
expect(isBranchNameValid("documentation/foo")).toBe(false);
expect(isBranchNameValid("chore")).toBe(false);
expect(isBranchNameValid("chore/")).toBe(false);
expect(isBranchNameValid("chore/FOO")).toBe(false);
expect(isBranchNameValid("foo/foo")).toBe(false);
expect(isBranchNameValid("foo/foo/bar")).toBe(false);
expect(isBranchNameValid("fix/DriveFooterBar")).toBe(false);
expect(isBranchNameValid("refactor/DriveFooterBar")).toBe(false);
expect(isBranchNameValid("rework/fooDriveFooterBar")).toBe(false);
expect(isBranchNameValid("core//foo")).toBe(false);
expect(isBranchNameValid("chore//foo")).toBe(false);
});
});
20 changes: 4 additions & 16 deletions lib/pullRequest.js
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,
};
3 changes: 2 additions & 1 deletion lib/pullRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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(
Expand All @@ -21,6 +20,8 @@ describe("pull request", () => {
).toBe(true);
});
test("recognize invalid branch names", () => {
expect(isPullRequestTitleValid("Add feature")).toBe(false);
expect(isPullRequestTitleValid("Remove feature")).toBe(false);
expect(isPullRequestTitleValid("add feature")).toBe(false);
expect(isPullRequestTitleValid("chore remove base files")).toBe(false);
expect(isPullRequestTitleValid("chore(): remove base files")).toBe(false);
Expand Down
Loading