bendera / vscode-commit-message-editor

Edit commit messages in a convenient way.
https://marketplace.visualstudio.com/items?itemName=adam-bender.commit-message-editor
MIT License
73 stars 13 forks source link

feat: message -> regex -> form #100

Open martinhoess opened 1 year ago

martinhoess commented 1 year ago

Nice extension! There is only one thing I "miss":

It would be great if you could define a regex that breaks down the current message and fills the form with the values from the regex.

This would also allow you to display the n most recent commits on the form page and, when selected, run it through the regex and fill the form.

so for my case something like this https://regex101.com/r/Y5LNaQ/2 image

bendera commented 1 year ago

Thank you for your feedback!

This would be a cool feature and actually, I was thinking about it. However, I have no idea how could be implemented. Since a commit message is plain text, not a programming language it's impossible to distinguish the values in the generated text. Or at least my knowledge is not enough for that. For example, the body of the message is a multi-line text, it can contain multiple paragraphs. How could be isolated from other paragraphs?

martinhoess commented 1 year ago

This is something that the person who defines the RegEx has to take care of himself. The only thing you can do is to assign the named groups from the regex result to the defined tokens.

So like in my example there is a named group "TYPE" (defined by the ?<TYPE>) and so then there must be a token "type" in the extension config. if there is no token the named group will be ignored and if there is no named group the token will behave as if it was defined normally.

I have no idea how the VSCode extensions work (internally). But I think you "just" need to run the regex on the message and then map the result of the regex (the named groups) to the defined tokens.

bendera commented 1 year ago

So, if I understand correctly, the person who defines the form configuration could assign a "restore pattern" regexp to every token. It would make sense.

martinhoess commented 1 year ago

Yes. The more strictly the message is defined, the easier it is to define the regular expression for it. The multi-line part is of course difficult or impossible, depending on whether there is a logical way to split it up. Also, there will always be cases where something is wrong or not recognised.

For example, if instead of fix my special service: ... I write fixing my special service: ... then fix is still recognized as "type". This could be solved in the expression by saying that a space must necessarily follow the type.

But I think for the simple/short commit messages that (in my experience) most people/projects use, this would help/work.

https://regex101.com/r/I67Ss6/1 image