Skip to content

Commit c49e4e1

Browse files
committed
chore2: add GA for branch naming convention
chore2: add GA for sematical commit messages
1 parent ce3a18f commit c49e4e1

File tree

5 files changed

+114
-2
lines changed

5 files changed

+114
-2
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Validate Branch Name
2+
3+
on:
4+
pull_request:
5+
types: [ opened, synchronize, reopened ]
6+
7+
jobs:
8+
check-branch-name:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check branch name format
12+
run: |
13+
BRANCH_NAME="${{ github.head_ref }}"
14+
echo "Checking branch name: $BRANCH_NAME"
15+
if [[ ! "$BRANCH_NAME" =~ ^(chore|feature|fix|hotfix|patch|refactor)/[a-z0-9._-]+$ ]]; then
16+
echo "❌ Invalid branch name: $BRANCH_NAME"
17+
echo "✅ Should match: feature/foo-bar, hotfix/issue-123, etc."
18+
exit 1
19+
fi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Check Commit Messages
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
lint-commits:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: wagoid/commitlint-github-action@v5

.husky/commit-msg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx commitlint --edit "$1"

commitlint.config.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const WIP_REGEX = /^wip[:]?$/i;
2+
const RULE_ERROR_LEVEL = 2;
3+
const HEADER_MAX_LENGTH = 100;
4+
const SUBJECT_MIN_LENGTH = 5;
5+
6+
module.exports = {
7+
extends: ["@commitlint/config-conventional"],
8+
rules: {
9+
"custom-subject-empty": [RULE_ERROR_LEVEL, "never"],
10+
"custom-type-enum": [RULE_ERROR_LEVEL, "always"],
11+
"custom-no-wip": [RULE_ERROR_LEVEL, "always"],
12+
"custom-no-wip-subject": [RULE_ERROR_LEVEL, "always"],
13+
"subject-min-length": [RULE_ERROR_LEVEL, "always", SUBJECT_MIN_LENGTH],
14+
"subject-case": [0], // optional: allow flexibility in subject case
15+
"header-max-length": [RULE_ERROR_LEVEL, "always", HEADER_MAX_LENGTH]
16+
},
17+
plugins: [
18+
{
19+
rules: {
20+
"custom-subject-empty": ({ subject }) =>
21+
subject && subject.trim().length > 0
22+
? [true]
23+
: [
24+
false,
25+
"The commit needs a description after the colon (:). Eg: feat: add new feature"
26+
],
27+
"custom-type-enum": ({ type }) => {
28+
const allowedTypes = [
29+
"feat",
30+
"fix",
31+
"hotfix",
32+
"docs",
33+
"style",
34+
"refactor",
35+
"test",
36+
"chore"
37+
];
38+
39+
if (!type) {
40+
return [
41+
false,
42+
"Missing type. Use: feat, fix, chore, refactor, etc."
43+
];
44+
}
45+
46+
if (!allowedTypes.includes(type)) {
47+
return [
48+
false,
49+
`Type "${type} is invalid". Allowed types: ${allowedTypes.join(
50+
", "
51+
)}`
52+
];
53+
}
54+
55+
return [true];
56+
},
57+
"custom-no-wip": ({ header }) => {
58+
const isWipOnly = WIP_REGEX.test(header.trim());
59+
return [
60+
!isWipOnly,
61+
"Commit message cannot be just \"WIP\" (use a descriptive message)."
62+
];
63+
},
64+
"custom-no-wip-subject": ({ subject }) => {
65+
if (!subject) return [true];
66+
67+
const isWipOnly = WIP_REGEX.test(subject.trim());
68+
return [
69+
!isWipOnly,
70+
"Subject cannot be just \"WIP\". Use a descriptive message like \"implement user login\" instead."
71+
];
72+
}
73+
}
74+
}
75+
]
76+
};

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
"private": true,
33
"scripts": {
44
"prod": "gulp --production",
5-
"dev": "gulp watch"
5+
"dev": "gulp watch",
6+
"prepare": "husky"
67
},
78
"devDependencies": {
89
"gulp": "^3.9.1",
910
"laravel-elixir": "^5.0.0",
10-
"bootstrap-sass": "^3.3.0"
11+
"bootstrap-sass": "^3.3.0",
12+
"@commitlint/config-conventional": "^19.8.1",
13+
"husky": "^9.0.11"
1114
}
1215
}

0 commit comments

Comments
 (0)