Skip to content

Commit 856db65

Browse files
committed
feat(git): add comprehensive conventional commit type detection
Enhance generateCommitMessage to support all conventional commit types: - perf: for performance improvements (optimize, speed) - chore: for maintenance tasks (dependencies, upgrade, bump) - ci: for CI/CD changes (workflow, pipeline) - build: for build system changes (compile, bundle) - style: for formatting changes (format, lint) - refactor: enhanced with cleanup, reorganize patterns Also moved 'improve' check to refactor category for better categorization. Updated tests to reflect that 'Update dependencies' now correctly maps to 'chore' instead of defaulting to 'feat'. Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent 39b812a commit 856db65

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/git.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,57 @@ export function generateCommitMessage(taskDescription: string): string {
8585
lowerDesc.includes("refactor") ||
8686
lowerDesc.includes("rewrite") ||
8787
lowerDesc.includes("restructure") ||
88-
lowerDesc.includes("improve")
88+
lowerDesc.includes("reorganize") ||
89+
lowerDesc.includes("cleanup") ||
90+
lowerDesc.includes("clean up")
8991
) {
9092
return `refactor: ${taskDescription}`
9193
}
9294

95+
if (
96+
lowerDesc.includes("perf") ||
97+
lowerDesc.includes("performance") ||
98+
lowerDesc.includes("optimize") ||
99+
lowerDesc.includes("speed")
100+
) {
101+
return `perf: ${taskDescription}`
102+
}
103+
104+
if (
105+
lowerDesc.includes("chore") ||
106+
lowerDesc.includes("dependency") ||
107+
lowerDesc.includes("dependencies") ||
108+
lowerDesc.includes("upgrade") ||
109+
lowerDesc.includes("bump")
110+
) {
111+
return `chore: ${taskDescription}`
112+
}
113+
114+
if (
115+
lowerDesc.includes("ci") ||
116+
lowerDesc.includes("workflow") ||
117+
lowerDesc.includes("pipeline")
118+
) {
119+
return `ci: ${taskDescription}`
120+
}
121+
122+
if (
123+
lowerDesc.includes("build") ||
124+
lowerDesc.includes("compile") ||
125+
lowerDesc.includes("bundle")
126+
) {
127+
return `build: ${taskDescription}`
128+
}
129+
130+
if (lowerDesc.includes("style") || lowerDesc.includes("format") || lowerDesc.includes("lint")) {
131+
return `style: ${taskDescription}`
132+
}
133+
134+
// Improvement is a common word that could be refactor or perf, default to refactor
135+
if (lowerDesc.includes("improve")) {
136+
return `refactor: ${taskDescription}`
137+
}
138+
93139
// Generic feature patterns last
94140
if (
95141
lowerDesc.includes("feat") ||

tests/git.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ describe("git", () => {
158158
})
159159

160160
test("defaults to feat for unrecognized patterns", () => {
161-
expect(generateCommitMessage("Update dependencies")).toBe("feat: Update dependencies")
162161
expect(generateCommitMessage("Some random task")).toBe("feat: Some random task")
162+
expect(generateCommitMessage("Random work")).toBe("feat: Random work")
163163
})
164164

165165
test("is case insensitive", () => {

0 commit comments

Comments
 (0)