refactor: remove 'version.Get()' and only use 'version.Raw()'#445
refactor: remove 'version.Get()' and only use 'version.Raw()'#445
Conversation
Move the v-prefix enforcement from Get() into init(), ensuring Version is normalized at startup. This eliminates the confusing Get() vs Raw() distinction — Raw() is now the single way to access the version.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #445 +/- ##
==========================================
- Coverage 70.34% 70.33% -0.01%
==========================================
Files 220 220
Lines 18506 18506
==========================================
- Hits 13018 13017 -1
- Misses 4309 4312 +3
+ Partials 1179 1177 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mwbrooks
left a comment
There was a problem hiding this comment.
A few notes for the semantic minded versioners 🔢
| if envVersion := getVersionFromEnv(); envVersion != "" { | ||
| Version = envVersion | ||
| } | ||
| Version = ensurePrefix(Version) |
There was a problem hiding this comment.
note: We now enforce the v prefix on init() so that all version-pathways will now have a v prefix.
There was a problem hiding this comment.
🦠 thought: I like this approach! It keeps the ctx corrent and commands are well structured for this I believe!
zimeg
left a comment
There was a problem hiding this comment.
@mwbrooks The version package gets good updates 🎁 ✨
I'm approving with a few suggestions and no blockers 🚢 I'm most curious about using slackcontext.Version as much as possible to keep the version package imports few?
Do we want to rename
version.Raw()toversion.Version()?
This is a solid change also and matches what I'd expect! I like the follow up to semantic version parsings 🤓
| ctx := cmd.Context() | ||
| updateNotification := update.New(clients, version.Get(), "SLACK_SKIP_UPDATE") | ||
| updateNotification := update.New(clients, version.Raw(), "SLACK_SKIP_UPDATE") |
There was a problem hiding this comment.
🎁 suggestion(non-blocking): In later changes to upgrade do we want to prefer slackcontext packages instead of importing version here?
slack-cli/internal/slackcontext/slackcontext.go
Lines 174 to 184 in e114959
There was a problem hiding this comment.
Good suggestion. During this PR, I was surprised to see so many version.Raw() calls still remain. In the follow-up PR, I'll aim to replace these - it's less dangerous now that slackcontext.Version(ctx) fallsback on the raw version. 👍🏻
| version = "v" + version | ||
| // ensurePrefix ensures that the version string has a "v" prefix. | ||
| func ensurePrefix(v string) string { | ||
| if match, _ := regexp.MatchString(`^[^v]`, v); match { |
There was a problem hiding this comment.
| if match, _ := regexp.MatchString(`^[^v]`, v); match { | |
| if !strings.HasPrefix(v, "v") { |
🌚 suggestion: While we're improving this we might import from string instead?
There was a problem hiding this comment.
Good suggestion! Thanks for keeping an eye out for opportunities to reduce our regex-foo!
Commit 218fa43 replaces regexp.MatchString with strings.HasPrefix. The ensurePrefix method must also now handle the empty string use-case, which our unit tests already cover.
| original := Version | ||
| defer func() { Version = original }() | ||
| Version = tc.version | ||
| assert.Equal(t, tc.expected, Get()) |
| if envVersion := getVersionFromEnv(); envVersion != "" { | ||
| Version = envVersion | ||
| } | ||
| Version = ensurePrefix(Version) |
There was a problem hiding this comment.
🦠 thought: I like this approach! It keeps the ctx corrent and commands are well structured for this I believe!
|
Thanks for the review @zimeg! Thorough as always the PR is walking away better because of your thoughts 🧠 I've addressed your suggest to swap the regex for
|
Changelog
Summary
This pull request removes
version.Get()and only usesversion.Raw(). The motivation is the simplify version handling to be 1 method instead of 2 methods.Context:
PR #429 consolidated version handling to prefer
version.Raw()andslackcontext.Version(ctx). A follow-up task was to removeversion.Get()entirely since it creates confusion about which function to use. The only difference is that.Get()prepends avprefix if missing - but we can guarantee thevprefix is always present without requiring.Get().Why it's Safe to Remove:
The
vprefix is already guaranteed in all code paths that set Version:git describe --tags --match 'v*.*.*'- the--matchpattern requires a v-prefixed tag, and git describe outputs the matching tag name, so the result always starts withv."v0.0.0-dev"- already has the prefix.SLACK_TEST_VERSION- this is the one gap. QA testers could set it without av. This PR adds validation by moving the v-prefix enforcement from.Get()intoinit(), ensuring Version is normalized at startup.Open Question 🧠
version.Raw()toversion.Version()?version.Major(),version.Minor(), etc to get specific elements of the version.Requirements