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

refactor: consolidate version normalization logic #3448

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Jan 31, 2025

Deduplicate the version ensurePrefix logic into the constant package.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced version normalization across the application
    • Introduced consistent version string formatting with 'v' prefix
  • Improvements

    • Standardized version retrieval and comparison mechanisms
    • Added default version handling for builds without explicit versioning
  • Technical Updates

    • Updated version management in multiple components
    • Simplified version string processing logic

@gartnera gartnera added the no-changelog Skip changelog CI check label Jan 31, 2025
@gartnera gartnera requested a review from a team as a code owner January 31, 2025 19:35
Copy link
Contributor

coderabbitai bot commented Jan 31, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This pull request introduces a comprehensive revision of version handling across multiple components of the system. The changes centralize version normalization logic within the constant package, specifically focusing on ensuring a consistent "v" prefix for version strings. By introducing new functions like GetNormalizedVersion() and NormalizeVersion(), the PR standardizes version representation and provides a default version for scenarios where no explicit version is available.

Changes

File Change Summary
app/setup_handlers.go Updated version retrieval to use constant.GetNormalizedVersion()
e2e/runner/runner.go Replaced local ensurePrefix with constant.NormalizeVersion() for version handling
pkg/constant/version.go Added new version-related functions and constants for normalized version management
zetaclient/maintenance/shutdown_listener.go Removed local ensurePrefix function, updated version retrieval method
zetaclient/maintenance/shutdown_listener_test.go Updated test cases to use version strings with "v" prefix

Sequence Diagram

sequenceDiagram
    participant Constant as constant.Version
    participant Handler as GetDefaultUpgradeHandlerVersion
    participant Runner as E2ERunner
    participant Client as ZetaClient

    Constant->>Handler: Provide Version
    Handler->>Constant: Call GetNormalizedVersion()
    Constant-->>Handler: Return Normalized Version

    Constant->>Runner: Provide Version
    Runner->>Constant: Call NormalizeVersion()
    Constant-->>Runner: Return Normalized Version

    Constant->>Client: Provide Version
    Client->>Constant: Call GetNormalizedVersion()
    Constant-->>Client: Return Normalized Version
Loading

Possibly Related PRs

Suggested Labels

ci, UPGRADE_TESTS, UPGRADE_LIGHT_TESTS

Suggested Reviewers

  • swift1337
  • lumtis
  • kingpinXD
  • fbac

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gartnera gartnera force-pushed the refactor-version-normalization branch from c3815d0 to 0219a3e Compare January 31, 2025 19:37
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 53.33333% with 7 lines in your changes missing coverage. Please review.

Project coverage is 64.39%. Comparing base (1375375) to head (2bf3cdc).
Report is 5 commits behind head on develop.

Files with missing lines Patch % Lines
pkg/constant/version.go 53.84% 6 Missing ⚠️
zetaclient/maintenance/shutdown_listener.go 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3448      +/-   ##
===========================================
- Coverage    64.42%   64.39%   -0.03%     
===========================================
  Files          436      437       +1     
  Lines        30368    30386      +18     
===========================================
+ Hits         19565    19568       +3     
- Misses        9962     9977      +15     
  Partials       841      841              
Files with missing lines Coverage Δ
zetaclient/maintenance/shutdown_listener.go 75.23% <50.00%> (-0.44%) ⬇️
pkg/constant/version.go 53.84% <53.84%> (ø)

... and 1 file with indirect coverage changes

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1375375 and 0219a3e.

📒 Files selected for processing (5)
  • app/setup_handlers.go (1 hunks)
  • e2e/runner/runner.go (2 hunks)
  • pkg/constant/version.go (1 hunks)
  • zetaclient/maintenance/shutdown_listener.go (2 hunks)
  • zetaclient/maintenance/shutdown_listener_test.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
app/setup_handlers.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

pkg/constant/version.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/runner/runner.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/maintenance/shutdown_listener_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/maintenance/shutdown_listener.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

🪛 GitHub Check: codecov/patch
pkg/constant/version.go

[warning] 16-21: pkg/constant/version.go#L16-L21
Added lines #L16 - L21 were not covered by tests


[warning] 25-26: pkg/constant/version.go#L25-L26
Added lines #L25 - L26 were not covered by tests


[warning] 29-33: pkg/constant/version.go#L29-L33
Added lines #L29 - L33 were not covered by tests

zetaclient/maintenance/shutdown_listener.go

[warning] 166-166: zetaclient/maintenance/shutdown_listener.go#L166
Added line #L166 was not covered by tests

🪛 GitHub Check: lint
pkg/constant/version.go

[failure] 19-19:
ineffectual assignment to version (ineffassign)

🪛 GitHub Actions: Linters and SAST
pkg/constant/version.go

[error] 19-19: ineffectual assignment to version (ineffassign)

🔇 Additional comments (6)
pkg/constant/version.go (1)

14-34: Add test coverage for version normalization functions.

The version normalization functions lack test coverage. Since these functions handle critical version string manipulation, they should be thoroughly tested.

Consider adding the following test cases:

  1. GetNormalizedVersion:
    • Empty version string
    • Version without 'v' prefix
    • Version with 'v' prefix
  2. NormalizeVersion:
    • Version without 'v' prefix
    • Version with 'v' prefix
  3. ensurePrefix:
    • String without prefix
    • String with prefix
    • Empty string

Would you like me to generate the test implementation?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 16-21: pkg/constant/version.go#L16-L21
Added lines #L16 - L21 were not covered by tests


[warning] 25-26: pkg/constant/version.go#L25-L26
Added lines #L25 - L26 were not covered by tests


[warning] 29-33: pkg/constant/version.go#L29-L33
Added lines #L29 - L33 were not covered by tests

🪛 GitHub Check: lint

[failure] 19-19:
ineffectual assignment to version (ineffassign)

🪛 GitHub Actions: Linters and SAST

[error] 19-19: ineffectual assignment to version (ineffassign)

app/setup_handlers.go (1)

21-21: LGTM: Version handling update is consistent.

The change correctly uses the new centralized version normalization logic.

zetaclient/maintenance/shutdown_listener.go (1)

Line range hint 153-166: LGTM: Version comparison logic is robust.

The implementation correctly uses normalized versions for comparison, ensuring consistent version checks across the codebase.

zetaclient/maintenance/shutdown_listener_test.go (1)

110-110: LGTM: Test cases properly updated.

The test cases have been correctly updated to use version strings with the 'v' prefix, maintaining consistency with the new version normalization approach.

Also applies to: 138-138

e2e/runner/runner.go (2)

41-41: LGTM!

The addition of the constant package import aligns with the PR objective to consolidate version normalization logic.


440-440: LGTM!

The implementation correctly uses the consolidated constant.NormalizeVersion function and maintains the caching behavior.

Let's verify that all version normalization logic has been consolidated:

✅ Verification successful

Version normalization logic is properly consolidated

All semantic version normalization in the codebase correctly uses the centralized constant.NormalizeVersion function. Other version-related code serves different purposes (protocol versions, API versions, etc.) and is correctly separated.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining version normalization logic that should be consolidated
# Test: Search for any remaining version normalization patterns
rg -g '*.go' -i '(ensurePrefix|normalizeVersion|versionPrefix)' --type go

Length of output: 627


Script:

#!/bin/bash
# Search for any other version-related string manipulations
rg -g '*.go' -i 'version.*string|strings.*version' --type go -A 2

Length of output: 7237

pkg/constant/version.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Skip changelog CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants