-
Notifications
You must be signed in to change notification settings - Fork 951
feat(cz-commitlint): add emoji to title #3618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add an emoji in the title of the questions referring to the type of commit
|
@parloti thanks! Any chance you can add a test for this? |
Hi! |
| const enumDescription = enumDescriptions[enumName]?.description; | ||
| if (enumDescription) { | ||
| const emoji = enumDescriptions[enumName]?.emoji; | ||
| const prefix = emoji ? emoji + ' ' : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
will this be implemented in a near future :) ? |
|
Please re-open when this continues |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Sorry guys, after some research, I gave up on finishing this. Emojis have random, fractional sizes, and there's no easy way to find the pixel width in non-browser environments. And even if we had the width, we wouldn't be able to add a fraction of a white space to force alignment. The best solution I could find was to add a tab between the emoji and the message.
But I'm not sure if this should be set in the service or if the emoji itself should have its own alignment characters. @escapedcat if you find this solution viable I can write the tests. |
|
hey guys lets talk about this? |
|
@parloti might be better than nothing. Would you mind adjusting the docs how to use this? |
I created an issue with everything. Docs and examples |
|
you can see here |
|
Yeah, should be added to this PR |
Expected BehaviorPlease add this cz-commitlint -> lib -> services -> getRuleQuestionConfig.js : 30 enumList = enumRuleList
.sort((a, b) => enumNames.indexOf(a) - enumNames.indexOf(b))
.map((enumName) => {
const enumDescription = enumDescriptions[enumName]?.description;
const emoji = enumDescriptions[enumName]?.emoji ? enumDescriptions[enumName].emoji : '';
if (enumDescription) {
return {
name: `${emoji} ${enumName}:`.padEnd(longest + 8) + enumDescription,
value: enumName,
short: enumName,
emoji: emoji || null
};
}
else {
return enumName;
}
}
);cz-commitlint -> lib -> SectionHeader.js export function getEmojis() {
const headerRuleQuestionConfig = getRuleQuestionConfig("header");
if (!headerRuleQuestionConfig) {
return [];
}
const emojis = headerRuleQuestionConfig?.enumList?.map(item => {
if (typeof item === 'object') {
return { value: item.value, emoji: item.emoji || '' };
}
return { value: item, emoji: null };
})
return emojis || [];
}
export function combineCommitMessage(answers) {
const { type = "", scope = "", subject = "" } = answers;
const questions = getQuestions();
const emoji = questions
.find(item => item.type === 'list' && item.name === 'type')?.choices
?.find(choice => choice.value === type)?.emoji;
const prefix = `${emoji?.trim()} ${type}${scope ? `(${scope})` : ""}`;
if (subject) {
return ((prefix ? prefix + ": " : "") + subject).trim();
}
else {
return prefix.trim();
}
}Config for gitmoji .czrc |
|
I just added the git moji just for parse the emojis in the regex. But if this will be default, we can create our parse. Or just show this in the options with CZ and return separated { emoji: '✅', message: '...' }, to add later parser |
|
Hey guys... anything more about this? |
about this... we can create 2 options add some space in the emoji... with this boolean option we can do a condition for space or in the function to make the space. and need to make a parser of this. I used from gitmoji. but we can reuse the gitmoji parser and sum with the ours |
|
Working on it! |
|
another solution #!/usr/bin/env ts-node
import fs from "fs"
// get commit msg file from git
const commitMsgFile = process.argv[2]
const msg = fs.readFileSync(commitMsgFile, "utf8")
const lines = msg.split("\n")
const firstLine = lines[0]
// import commitlint.config.ts
import commitlintConfig from "../../commitlint.config.js"
const types = commitlintConfig.prompt?.questions?.type?.enum ?? {}
// Regex to get type with scope or no scope
const match = firstLine.match(/^([a-z]+)(?:\([^)]+\))?:/)
const type = match ? match[1] : null
if (type && types[type]) {
const emoji = types[type].emoji
if (emoji && !firstLine.includes(emoji)) {
// Add emoji
const newFirstLine = `${emoji} ${firstLine}`
const newMsg = [newFirstLine, ...lines.slice(1)].join("\n")
fs.writeFileSync(commitMsgFile, newMsg, "utf8")
}
}later commitlint node ./.husky/scripts/add-emoji.js "$1"Its working good and you can test creating a commit.txt and run node ./.husky/scripts/add-emoji.js commit.txtbut the problem with space keep. and i just added a space. the commitlint.config.js is here |



Description
Add an emoji in the title of the questions referring to the type of commit
Motivation and Context
Although emojis are already configured in config-conventional they are not used in cz-commitlint
TODO emoji + title
Usage examples
No need for configuration
How Has This Been Tested?
Tested in private repository
Types of changes
Checklist: