Skip to content

Commit

Permalink
chore!: remove old naming compliance [DEVOP-143] (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccaulonque authored Mar 11, 2024
1 parent 8a1c5e4 commit 552cfe5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 91 deletions.
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,
};
66 changes: 36 additions & 30 deletions lib/branch.test.js
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);
});
});
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,
};
45 changes: 17 additions & 28 deletions lib/pullRequest.test.js
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);
});
});

0 comments on commit 552cfe5

Please sign in to comment.