-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: Support multiple commit prefixes #4261
feat: Support multiple commit prefixes #4261
Conversation
# See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-commit-message-prefix | ||
commitPrefix: | ||
# pattern to match on. E.g. for 'feature/AB-123' to match on the AB-123 use "^\\w+\\/(\\w+-\\w+).*" | ||
pattern: "" | ||
|
||
# Replace directive. E.g. for 'feature/AB-123' to start the commit message with 'AB-123 ' use "[$1] " | ||
replace: "" | ||
|
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.
Once again, go generate
removed this. I guess it just doesn't support sequences?
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.
Yes, that's true. The config doc is generated from the default values specified in the schema, and arrays don't have the concept of a default value.
It's actually a good thing that this is removed from the docs. We had several cases of people copying the entire defaults section from the docs to their config file, and then it doesn't work as expected; see here for more information.
The failed integration test |
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.
This is really nice, great work. I like the added tests. Just two minor things below.
# See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-commit-message-prefix | ||
commitPrefix: | ||
# pattern to match on. E.g. for 'feature/AB-123' to match on the AB-123 use "^\\w+\\/(\\w+-\\w+).*" | ||
pattern: "" | ||
|
||
# Replace directive. E.g. for 'feature/AB-123' to start the commit message with 'AB-123 ' use "[$1] " | ||
replace: "" | ||
|
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.
Yes, that's true. The config doc is generated from the default values specified in the schema, and arrays don't have the concept of a default value.
It's actually a good thing that this is removed from the docs. We had several cases of people copying the entire defaults section from the docs to their config file, and then it doesn't work as expected; see here for more information.
pattern: "^\\w+\\/(\\w+-\\w+).*" | ||
replace: '[$1] ' | ||
- pattern: "^\\w+\\/(\\w+-\\w+).*" | ||
replace: '[$1] ' |
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.
It would be good to have an example with multiple entries here (like you have for commitPrefixes below), and maybe say explicitly that they are tried in order, first match wins.
The reason why I prefer to have this here rather than below is that I'd like to deprecate (and eventually remove) commitPrefixes; now that we have repo-local config files, it's no longer needed.
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.
Added an example with multiple prefixes!
I left the example down below as well, want me to remove?
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.
No, it's fine to keep them. We'll remove that section at some point anyway.
@@ -99,14 +99,55 @@ func lookupKey(node *yaml.Node, key string) (*yaml.Node, *yaml.Node) { | |||
return nil, nil | |||
} | |||
|
|||
func TransformNode(yamlBytes []byte, path []string, transform func(node *yaml.Node) (bool, error)) ([]byte, error) { |
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.
Some brief documentation would be nice; e.g. what the path parameter means, and what the bool return value of the callback means.
Would it maybe be useful to add a test with some simple transformation like converting int values to string values to illustrate the usage?
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.
Added some docs, and a test. The test didn't end up being as simple as I would like because of the complexity of expressing the conversion of int values to string, but it is a test!
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.
Very nice. I pushed a fixup (1ea96eb) to address a linter error; yaml.Node.Value
is a string no matter whether the type is int or str, so it's unnecessary to sprintf it again.
8ab32f2
to
c9d6f2f
Compare
c9d6f2f
to
1ea96eb
Compare
Cool, happy with this now. I had to push one more fixup (d81cf52) to remove some trailing whitespace that triggered my OCD. 😄 Merging. |
This implementation, unlike that proposed in jesseduffield#4253 keeps the yaml schema easy, and does a migration from the single elements to a sequence of elements.
1ea96eb
to
2fa4ee2
Compare
This implementation, unlike that proposed in Allow multiple commit prefixes #4253 keeps the yaml schema easy, and does a migration from the single elements to a sequence of elements.
Addresses #4194
go generate ./...
)