-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add ability to configure branch color patterns using regex #4130
base: master
Are you sure you want to change the base?
Conversation
This only seems to support a However, I'm unsure if globbing is the best solution here. I'd rather thought we'd use regular expressions; they are more powerful and flexible, and we already use them for other things in the user config, e.g. commit prefixes. With regular expressions, however, it's a bit harder to maintain backward compatibility transparently. I think for clarity we should add a new config (e.g. |
I'm agree that it would be better to use regular expressions here. On my current place of work we have strict rules about branch naming. So, with power of regular expressions I achieved behavior, when only correctly named branches are highlighted: gui:
branchColorPatterns:
"IDS+-[0-9]+-[^']+$": '#29d1f7' |
Thank you for the feedback @stefanhaller @castlele I'll adjust the pr accordingly. I agree that using regex will give the user a better ability on how to specify the branch rules. |
952535e
to
93bba0a
Compare
pkg/gui/presentation/branches.go
Outdated
var branchPrefixColorCache = make(map[string]style.TextStyle) | ||
type colorMatcher struct { | ||
patterns map[string]style.TextStyle | ||
isRegex bool |
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.
Since the new config is replacing the old one I needed a way to know whether a regex pattern was passed or wether I should attempt to match using the old way (by branchType). Once the old method of matching is deprecated this can be removed
pkg/gui/presentation/branches.go
Outdated
} | ||
|
||
// Default colors for common branch types | ||
branchType := strings.Split(name, "/")[0] |
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.
keeping the old default behavior
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.
@jesseduffield How do you feel about removing this default behavior? I find it surprising and annoying. I don't want it, but it's not obvious how to disable it; previously I had to use this to disable it:
gui:
branchColors:
feature: default
bugfix: default
hotfix: default
but if I want to use the new regex patterns now, I have to say
gui:
branchColorPatterns:
"mypattern": "#ff0000"
"^feature/": default
"^bugfix/": default
"^hotfix/": default
This is very non-obvious, and I feel like I shouldn't have to do that.
93bba0a
to
ce827b3
Compare
Had some free time today and updated this pr, let me know if this is closer to what you were imagining @stefanhaller. Given that we have to account for both the new behavior while keeping the old way unchanged it might be a little messy until we deprecate the old behavior. Feel free to suggest any changes, thanks! Here is an image of what it looks like with a sample config: |
For what it's worth, that approach looks good to me (code just needs some more documentation, and to be explicit about the old option being deprecated) |
8f1c64b
to
925e161
Compare
@jesseduffield Added some more documentation and deprecation warnings, let me know if you think anything is missing clarity |
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.
Great work @mtrajano. A few thoughts below, looks good to me otherwise.
pkg/gui/presentation/branches.go
Outdated
} | ||
|
||
// Default colors for common branch types | ||
branchType := strings.Split(name, "/")[0] |
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.
@jesseduffield How do you feel about removing this default behavior? I find it surprising and annoying. I don't want it, but it's not obvious how to disable it; previously I had to use this to disable it:
gui:
branchColors:
feature: default
bugfix: default
hotfix: default
but if I want to use the new regex patterns now, I have to say
gui:
branchColorPatterns:
"mypattern": "#ff0000"
"^feature/": default
"^bugfix/": default
"^hotfix/": default
This is very non-obvious, and I feel like I shouldn't have to do that.
@stefanhaller Those feature/bugfix/hotfix things are based on 'gitflow' which is now considered legacy by many, so I'm happy to remove those defaults. |
925e161
to
b1620c1
Compare
We used to automatically color branches starting with "feature/", "bugfix/", or "hotfix/". For those who don't want this, it's a bit non-obvious to turn off, but it's actually pretty easy to configure manually for those who want this, so we just remove this default coloring.
b1620c1
to
6919b04
Compare
Nice. I took the liberty of separating the removal of the default coloring into a commit of its own, and I added a commit that adds a "breaking changes" popup for the deprecation of the old config and the removal of the default coloring. This looks good to me now; @jesseduffield Any thoughts about deprecation comments? |
I added another fixup (e6fa89c) to fix a test failure. I'm not sure this is the best way to fix it; alternatively we could put an @mtrajano This makes me realize that |
@mtrajano Oh, and could you update the PR description please? It is out of date. |
Yes I also thought the naming choice was weird (nothing to do with caching) but kept it the same since it has the same behavior as before. I can rename this to |
Works for me. |
e6fa89c
to
1834be5
Compare
Updated the PR description and renamed the variable let me know if that looks good |
I'm sorry it's possible I overwrote this commit with my last push, let me see if I can add the same |
Was there anything else you changed or just the test? |
You lost all my work, which is a bit annoying to be honest. I did this to save time, not to waste time. 😉 Maybe it's unexpected for contributors to get stuff pushed to their branch by maintainers, but we actually do this all the time, so you need to be careful not to blindly force-push. I'll recover my things from the reflog and force-push again, hang on a minute... |
1834be5
to
ac71ae4
Compare
Ok, I force-pushed again, please pull. My changes are:
(I mentioned all of these above...) |
Looks good now, thankfully wasn't a huge set of changes but yes reflog always does the trick 🙏 Let me know if there's anything else needed to get this merged, thanks for the helpful comments |
I added another fixup for updating the config schema (CI failed because of this). One thing I'm wondering is whether we should explicitly mention that the regex patterns are not anchored, and that users need to do that themselves if they want an exact match for example. |
Yes I think it's worth mentioning, this behavior felt counter intuitive to me as mentioned here #4130 (comment). |
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.
Everything here looks good to me except for the tense of 'deprecation': the comments say that the old config will be deprecated in the future but in reality it's deprecated as of right now: it will be removed in the future.
As an aside, I wonder if it would be good to rename BranchColors to DeprecatedBranchColors (and do the same in future for other deprecated config values) so that it's borderline impossible for a contributor to accidentally use the wrong one. Consider that in gui.go in this PR, the comment wouldn't be necessary if it was called DeprecatedBranchColors
@jesseduffield I don't think the config rename is a good idea, it will break a bunch of users configs unexpectedly with a simple commit change. They can keep using the current version until a major version is released in which case the old config value can be just be removed entirely. IMO having the notice as part of a changelog or some sort of upgrade guide is enough and is usually the standard other applications follow. Thoughts @stefanhaller ? |
To be clear I'm not suggesting that we change the name that the user uses (i.e. |
Oh yes in that case it can make sense to serve as a reminder for the maintainers in the future 👍 |
I'm mildly opposed to renaming the field. It's always slightly confusing when a config variable has a name that's different from the user-facing yaml name, and I would only do that if there's a really strong reason for it. In this case, I don't see a big risk that future contributors will continue to use the old field for new code; I'm having a hard time imagining what kind of code that would be. Not a super strong opinion, so if you both think we should rename it, I'd be fine with that. |
I don't have a strong opinion, so happy to leave the code as-is |
Add ability to specify color patterns in the
branchColorPatterns
config using regex, ex.JIRA-\d+
would match all branch names in the formJIRA-456
.Example config:
go generate ./...
)