mooltiverse / nyx

The one stop semantic release tool
https://github.com/mooltiverse/nyx
Apache License 2.0
116 stars 8 forks source link

Removing complying prefixes from commits #259

Closed ennioVisco closed 1 year ago

ennioVisco commented 1 year ago

I was curious whether there is a way (I didn't get it from the docs) to remove the prefixes of the commits complying to the commits policy (I'm thinking in particular about the prefixes as shown in the following screenshot from nyx releases):

Screenshot 2023-08-29 at 15 18 38

flelli commented 1 year ago

Hi @ennioVisco ,

no, there's no such option as of now. What you can use, at most, is substitutions so you can mangle each line by using regular expressions.

Would this be a feature for you?

ennioVisco commented 1 year ago

Hi @ennioVisco ,

no, there's no such option as of now. What you can use, at most, is substitutions so you can mangle each line by using regular expressions.

Would this be a feature for you?

I was thinking about the substitutions indeed. I wouldn't say I need this feature. Perhaps a substitution is fine as of now, and maybe one day a preset can be made available if others also seem to prefer this option 😊

flelli commented 1 year ago

Wait @ennioVisco , there's a better option than substitutions. . Regular expressions need a try but you can achieve that with standard features.

Use a custom changelog template and use some function like capture to mangle the commit row title.

For example, replace the default changelog template lines:

{{#commits}}
* [{{#short5}}{{SHA}}{{/short5}}] {{message.shortMessage}} ({{authorAction.identity.name}})

with:

{{#commits}}
* [{{#short5}}{{SHA}}{{/short5}}] {{#capture expression="(?<type>[a-zA-Z0-9_]+)(!)?(\((?<scope>[a-z ]+)\))?:( (?<title>.+))" group="title"}}{{message.shortMessage}}{{/capture}} ({{authorAction.identity.name}})

This function extracts the title named group from the {{message.shortMessage}} so it's exactly what you need here. Again, I haven't tested this expression but all the features are there.

ennioVisco commented 1 year ago

Wait @ennioVisco , there's a better option than substitutions. . Regular expressions need a try but you can achieve that with standard features.

Use a custom changelog template and use some function like capture to mangle the commit row title.

For example, replace the default changelog template lines:

{{#commits}}
* [{{#short5}}{{SHA}}{{/short5}}] {{message.shortMessage}} ({{authorAction.identity.name}})

with:

{{#commits}}
* [{{#short5}}{{SHA}}{{/short5}}] {{#capture expression="(?<type>[a-zA-Z0-9_]+)(!)?(\((?<scope>[a-z ]+)\))?:( (?<title>.+))" group="title"}}{{message.shortMessage}}{{/capture}} ({{authorAction.identity.name}})

This function extracts the title named group from the {{message.shortMessage}} so it's exactly what you need here. Again, I haven't tested this expression but all the features are there.

Thanks, I am already using a custom template, so this is a good idea, I didn't think about it! One question though, just because I am not sure whether it is a bug: by using your line I get this: https://github.com/ennioVisco/webmonitor/releases/tag/v1.1.0-internal.1.beta.12 (notice the broken commit links)... Could it be the capturing does not happen just on the inner message.shortMessage but changes the whole line?

flelli commented 1 year ago

That's weird, I need to test.

Are you using the Java/Gradle or the Go/Command Line version?

ennioVisco commented 1 year ago

There is a difference with the latest release, where {{SHA}} was previously case insensitive while it now needs to be lower case {{sha}}. Fixing this it works as expected