forked from insulineru/ai-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitmoji.js
More file actions
27 lines (24 loc) Β· 746 Bytes
/
gitmoji.js
File metadata and controls
27 lines (24 loc) Β· 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function addGitmojiToCommitMessage(commitMessage) {
// Define the mapping of commit types to gitmojis
const typeToGitmoji = {
feat: "β¨",
fix: "π",
docs: "π",
style: "π",
refactor: "β»οΈ",
test: "β
",
chore: "π§",
};
// Extract the first alphabetic character of the commit message
const match = commitMessage.match(/[a-zA-Z]+/);
if(!match) return commitMessage;
const type = match[0];
// If the type is valid, add the corresponding gitmoji to the message
if (typeToGitmoji[type]) {
return `${typeToGitmoji[type]} ${commitMessage}`;
} else {
// If the type is not recognized, return the original message
return commitMessage;
}
}
export { addGitmojiToCommitMessage }