Skip to content
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

[Feature Request] Custom formatter #57

Closed
thlmenezes opened this issue Aug 16, 2022 · 7 comments
Closed

[Feature Request] Custom formatter #57

thlmenezes opened this issue Aug 16, 2022 · 7 comments
Assignees
Labels
enhancement New feature or request next version Plan for next version

Comments

@thlmenezes
Copy link

💭 Describe the feature

I've been using commitizen-emoji for a while now, and found this library as a way to remove duplicated configs between commitzen and commitlint.

But, currently I see you only support the angular output; and with no clear way, in my testing, to replace or omit the type output.

the commit format I'm targeting is as follows:

<gitmoji>(<scope>): <subject>

scope being optional

Compared to Default Angular Commits
<type>(<scope>): <subject>

Currently with cz-git I've managed to create commits like

feat: ✨ <subject>
feat(<scope>): ✨ <subject>

But I'm aiming for something like

✨ <subject>
✨ (<scope>): <subject>

💡 Proposed Solution

Enable users to customize their formatter with:

  • sending their own custom function: receiving arguments corresponding to answers from the form view, and returning a string (title);
  • implement a boolean argument conventionalFormat with default true, to enable the user to opt out of angular commit style

Example:

formatTitle.ts

export const formatTitle: FormatTitleType = ({ type, scope, subject }, config) => {
  const formattedScope = formatScopeOption(scope)
  const prelude = config.conventionalFormat
    ? `${type.emoji} ${type.name}${formattedScope}:`
    : `${type.emoji}${formattedScope ? ' ' + formattedScope + ':' : ''}`

  return `${prelude} ${subject}`
}

Example usage

const arguments = {
  type: {
    emoji: '✨',
    name: 'feat',
  },
  scope: 'mobile',
  subject: 'login screen'
}

console.log(formatTitle(arguments, {conventionalFormat: true}))  // ✨ feat (mobile): login screen
console.log(formatTitle(arguments, {conventionalFormat: false})) // ✨ (mobile): login screen

I believe there's some work to do on field type....type (ts typing) and fine-tuning, but I'm open to help in the conversation

@thlmenezes thlmenezes added the enhancement New feature or request label Aug 16, 2022
@Zhengqbbb
Copy link
Owner

Zhengqbbb commented Aug 17, 2022

Hi, Thank you for your attention ❤️️
my personal understanding 🤔 is feat => ✨


Maybe custom options types can help u if so~
https://cz-git.qbb.sh/config/show.html#types
Have try ~

types: [
      {value: '✨', name: '✨ feat:     A new feature'},
       ...
],

image

@Zhengqbbb
Copy link
Owner

Zhengqbbb commented Aug 17, 2022

  • The above solution may have problems in search
    because the current search is based on value, and a switch needs to be provided to search for name
    I will support it in this weekend release

But need to provide format message option I need to think about it over the weekend 🤔

Anyway u can try this way, See if it solves your problem, just tell me ~ 🤗

@thlmenezes
Copy link
Author

I appreciate the answer, this solves the issue; with the tradeoff being losing the search capabilities (my current cz search selects ✨ when typing 'feat'). Found that solution, but seemed like a hack, so I figured I should open the issue.

I will wait for the search update to try again, with this solved I'll move my setup to using cz-git.

@Zhengqbbb
Copy link
Owner

Zhengqbbb commented Aug 17, 2022

I will wait for the search update to try again, with this solved I'll move my setup to using cz-git.

I will do it in weekend~

types: [
      {value: '✨', name: '✨ feat:     A new feature'},
       ...
],

current:

  • fuzzy search in value

next version:

  • add switch option can support fuzzy search in name

@Zhengqbbb Zhengqbbb added the next version Plan for next version label Aug 17, 2022
Zhengqbbb added a commit that referenced this issue Aug 18, 2022
add `typesSearchValueKey` option
default types list fuzzy search types `value` options.
if choose `false` will search `name` options

link #57
Zhengqbbb added a commit that referenced this issue Aug 19, 2022
add `formatMessageCB` option that is a callback function
provide use custom finally commit message

link #57

Co-authored-by: Zhengqbbb <1074059947@qq.com>
Zhengqbbb added a commit that referenced this issue Aug 19, 2022
add `Co-authored-by` after footer

link #57

Co-authored-by: Zhengqbbb <1074059947@qq.com>
Zhengqbbb added a commit that referenced this issue Aug 20, 2022
link #57

Co-authored-by: Zhengqbbb <1074059947@qq.com>
Zhengqbbb added a commit that referenced this issue Aug 20, 2022
link #57

Co-authored-by: Zhengqbbb <1074059947@qq.com>
@Zhengqbbb
Copy link
Owner

Zhengqbbb commented Aug 21, 2022

@thlmenezes
⭐️ v1.3.11 ⭐️ has been released 🥳

There are two way can realize u issue request:

  1. emoji as to type value
types: [
      {value: '✨', name: '✨ feat:     A new feature'},
       ...
],
typesSearchValueKey: false
  1. you can use formatMessageCB callback fn to custom finally message
formatMessageCB: ({ emoji, scope, subject }) => {
          return scope
            ? `${emoji}(${scope}): ${subject}`
            : `${emoji} ${subject}`
        }

please have a try. 💪
👀 Let me know if there are still any issues. Thanks for you work! 🎉
Thanks again for your advice!!!

@thlmenezes
Copy link
Author

Will test the new release this week for sure and provide feedback

@thlmenezes
Copy link
Author

thlmenezes commented Aug 22, 2022

Thank youuuuuu, it works like a charm; the issue can be closed now.

Made the change today from my old dependency and hope to provide more feedback in the future 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request next version Plan for next version
Projects
None yet
Development

No branches or pull requests

2 participants