Skip to content

Commit 7a9a586

Browse files
ccaulonqueCyril
andauthored
Update pr & branch naming compliance (#79)
Co-authored-by: Cyril <[email protected]>
1 parent 9f6b46a commit 7a9a586

File tree

3 files changed

+69
-15
lines changed

3 files changed

+69
-15
lines changed

lib/branch.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
exports.isBranchNameValid = (branchName) =>
2-
(!!branchName.match(
3-
/^(core|feature|fix|hotfix|asset|rework|documentation|mobsuccessbot|dependabot)\/([a-z][a-z0-9._-]*)$/
4-
) ||
2+
isBranchNameValid(branchName) || isBranchNameValidLegacy(branchName);
3+
4+
function isBranchNameValidLegacy(branchName) {
5+
return (
6+
(!!branchName.match(
7+
/^(core|feature|fix|hotfix|asset|rework|documentation|mobsuccessbot|dependabot)\/([a-z][a-z0-9._-]*)$/
8+
) ||
9+
!!branchName.match(/^(mobsuccessbot)\/([a-z0-9_\-@./_-]*)$/) ||
10+
!!branchName.match(/^(dependabot)\/([a-z][a-zA-Z0-9./_-]*)$/) ||
11+
!!branchName.match(/^revert-[0-9]+-/) ||
12+
!!branchName.match(/^(rework)\/([A-Z][a-zA-Z0-9.-]*)$/)) &&
13+
!branchName.match(/---/) &&
14+
!branchName.match(/\/\//)
15+
);
16+
}
17+
18+
function isBranchNameValid(branchName) {
19+
return (
20+
!!branchName.match(
21+
/^(feat|fix|chore|docs|refactor|change|remove|test|revert|poc|mobsuccessbot|dependabot)\/([a-z][a-z0-9._-]*)$/
22+
) ||
523
!!branchName.match(/^(mobsuccessbot)\/([a-z0-9_\-@./_-]*)$/) ||
6-
!!branchName.match(/^(dependabot)\/([a-z][a-zA-Z0-9./_-]*)$/) ||
7-
!!branchName.match(/^revert-[0-9]+-/) ||
8-
!!branchName.match(/^(rework)\/([A-Z][a-zA-Z0-9.-]*)$/)) &&
9-
!branchName.match(/---/) &&
10-
!branchName.match(/\/\//);
24+
!!branchName.match(/^(dependabot)\/([a-z][a-zA-Z0-9./_-]*)$/)
25+
);
26+
}

lib/pullRequest.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
exports.isPullRequestTitleValid = (pullRequestName) =>
2-
!!pullRequestName.match(
3-
/^(Add|Clean|Fix|Improve|Remove|Update|Rework|Ignore|Bump|Switch|Migrate) .+$/
4-
/* remember to edit the Notion when changing this value:
5-
https://www.notion.so/mobsuccess/Git-Guidelines-41996ef576cb4f29b7737772b74289c5
6-
*/
7-
) || !!pullRequestName.match(/^Revert ".*"$/);
2+
isPullRequestTitleValid(pullRequestName) ||
3+
isPullRequestTitleValidLegacy(pullRequestName);
4+
5+
function isPullRequestTitleValidLegacy(pullRequestName) {
6+
return (
7+
!!pullRequestName.match(
8+
/^(Add|Clean|Fix|Improve|Remove|Update|Rework|Ignore|Bump|Switch|Migrate) .+$/
9+
/* remember to edit the Notion when changing this value:
10+
https://www.notion.so/mobsuccess/Git-Guidelines-41996ef576cb4f29b7737772b74289c5
11+
*/
12+
) || !!pullRequestName.match(/^Revert ".*"$/)
13+
);
14+
}
15+
16+
// commit convention: prefix([optional scope]): description
17+
function isPullRequestTitleValid(pullRequestName) {
18+
return !!pullRequestName.match(
19+
/^(feat|fix|chore|docs|refactor|change|remove|test|revert|poc)(?:\(.+\))?!?:.+/
20+
);
21+
}

lib/pullRequest.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
const { isPullRequestTitleValid } = require("./pullRequest");
22

3-
describe("pul request", () => {
3+
describe("pull request", () => {
44
test("recognize pull request branch names", () => {
55
expect(isPullRequestTitleValid("Add feature")).toBe(true);
6+
expect(isPullRequestTitleValid("chore: remove base files")).toBe(true);
7+
expect(
8+
isPullRequestTitleValid(
9+
"fix(design-system): update color palette for accessibility compliance"
10+
)
11+
).toBe(true);
12+
expect(
13+
isPullRequestTitleValid(
14+
"feat!: send an email to the customer when a product is shipped"
15+
)
16+
).toBe(true);
17+
expect(
18+
isPullRequestTitleValid(
19+
"feat(api)!: send an email to the customer when a product is shipped"
20+
)
21+
).toBe(true);
622
});
723
test("recognize invalid branch names", () => {
824
expect(isPullRequestTitleValid("add feature")).toBe(false);
25+
expect(isPullRequestTitleValid("chore remove base files")).toBe(false);
26+
expect(isPullRequestTitleValid("chore(): remove base files")).toBe(false);
27+
expect(isPullRequestTitleValid("add: add new project")).toBe(false);
28+
expect(
29+
isPullRequestTitleValid(
30+
"feat!(api): send an email to the customer when a product is shipped"
31+
)
32+
).toBe(false);
933
});
1034
});

0 commit comments

Comments
 (0)