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

Add ability to configure branch color patterns #4130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mtrajano
Copy link

  • PR Description

Add ability to specify prefix patterns in the branchColors config, ex. JIRA-58. Maintains backwards compatibility by giving preference to previous behavior and only checking if specified color name has a * in it. I'm still learning go so let me know if there's a better way of writing this.

Example config:

gui:
  branchColors:
    'docs': '#11aaff'
    'master': 'red'
    'IEA-*': 'green'
Screenshot 2024-12-26 at 7 37 58 PM
  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@stefanhaller
Copy link
Collaborator

This only seems to support a * at the end, and manually matches prefixes before it. If we want to do pattern matching with wildcards in this way, we should use the Glob package to support the full globbing syntax.

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. BranchColorPatterns) and use that instead of the old one as soon as it has at least one entry. Note that Nikita's branch here doesn't do that quite the way I think it should be: he first checks if there is a match with the new config, and if there isn't, he still falls back to the old config. That's not how I would do it: check the new config (and only the new one) if it has any entries, and only fall back to the old one if it doesn't. This way we can properly deprecate the old one and eventually remove it after some time.

@castlele
Copy link

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'

@mtrajano
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants