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

Output current rather than latest version in up-to-date messages #164

Merged
merged 1 commit into from
Jun 27, 2024
Merged

Output current rather than latest version in up-to-date messages #164

merged 1 commit into from
Jun 27, 2024

Conversation

scop
Copy link
Contributor

@scop scop commented Jun 26, 2024

Latest can actually be older than current, especially when comparing a snapshot against the latest release, and current is what was compared against latest anyway.

While at it, add a test case for similar occurrence with Go versions (they were already showing correct info though).

Summary by CodeRabbit

  • Bug Fixes

    • Corrected version display to show the current version instead of the latest version in status messages.
  • Tests

    • Added tests to verify the correct display of package and Go versions when they are up-to-date.

Latest can actually be older than current, especially when comparing a
snapshot against the latest release, and current is what was compared
against latest anyway.

While at it, add a test case for similar occurrence with Go versions
(they were already showing correct info though).
Copy link
Contributor

coderabbitai bot commented Jun 26, 2024

Walkthrough

This update corrects the display of version information within the CurrentToLatestStr and VersionCheckResultStr functions of the Package struct in goutil.go, ensuring it shows the current version instead of the latest one. Additionally, new test functions were introduced in goutil_test.go to validate the proper functionality of these version checks for packages and Go versions, confirming they are up-to-date.

Changes

Files Change Summary
internal/goutil/goutil.go Updated CurrentToLatestStr and VersionCheckResultStr to show current versions.
internal/goutil/goutil_test.go Added tests: TestPackage_CurrentToLatestStr_up_to_date, TestPackage_VersionCheckResultStr_up_to_date, and TestPackage_VersionCheckResultStr_go_up_to_date.

Poem

🐇
Up-to-date, we rise and gleam,
Code like rivers in a dream.
Versions current, bright, and green,
In tests and truth, our joy is seen.
With every change, a better flow,
Our code will dance and surely grow.
🐇


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@scop scop mentioned this pull request Jun 26, 2024
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: 0

Outside diff range and nitpick comments (4)
internal/goutil/goutil.go (3)

Line range hint 144-144: Consider making "unknown" a constant.

The string "unknown" is used multiple times across the file, which could be made a constant to avoid repetition and potential errors in future modifications.

+ const unknownVersion = "unknown"
- if current == "unknown" || available == "unknown" {
+ if current == unknownVersion || available == unknownVersion {

Line range hint 178-178: Refactor if-else chains to switch statements.

Switch statements can improve readability and maintainability of the code by replacing multiple if-else conditions.

- if current == "unknown" || available == "unknown" {
+ switch {
+ case current == "unknown", available == "unknown":

Also applies to: 203-203


Line range hint 24-24: Consider encapsulating global variables.

Global variables can lead to issues with code maintainability and testing. Consider encapsulating these into a struct or providing getter/setter functions to control their access.

Also applies to: 26-26, 28-28, 30-30

internal/goutil/goutil_test.go (1)

Line range hint 167-167: Consider making "echo" a constant.

The string "echo" is used multiple times, particularly in tests mocking the behavior of the go command. Defining it as a constant would improve maintainability.

+ const mockCommand = "echo"
- goExe = "echo"
+ goExe = mockCommand
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 09a63e3 and 4c28986.

Files selected for processing (2)
  • internal/goutil/goutil.go (2 hunks)
  • internal/goutil/goutil_test.go (4 hunks)
Additional context used
golangci-lint
internal/goutil/goutil.go

144-144: string unknown has 7 occurrences, make it a constant (goconst)


178-178: ifElseChain: rewrite if-else to switch statement (gocritic)


203-203: ifElseChain: rewrite if-else to switch statement (gocritic)


24-24: goExe is a global variable (gochecknoglobals)


26-26: keyGoBin is a global variable (gochecknoglobals)


28-28: keyGoPath is a global variable (gochecknoglobals)


30-30: osMkdirTemp is a global variable (gochecknoglobals)

internal/goutil/goutil_test.go

549-549: Error return value of os.Setenv is not checked (errcheck)


550-550: Error return value of os.Setenv is not checked (errcheck)


167-167: string echo has 3 occurrences, make it a constant (goconst)

Additional comments not posted (5)
internal/goutil/goutil.go (2)

81-81: Update to display the current version is correct.

This change aligns with the PR's objective to display the current version instead of the latest when the package is up-to-date. This is particularly important for clarity and accuracy in version reporting.


99-99: Correct version information displayed.

The modification ensures that the "Already up-to-date" message reflects the current version rather than the latest. This change is crucial for accuracy, especially in scenarios where the latest version might not necessarily be the most recent.

internal/goutil/goutil_test.go (3)

677-699: Good test coverage for CurrentToLatestStr function.

This test ensures that the function correctly displays the "up-to-date" message with the current version. It's essential for verifying the changes made in the associated function.


725-747: Effective testing for VersionCheckResultStr.

The test verifies that the function outputs the correct "up-to-date" message when the package version is current. This aligns well with the PR's goals and ensures the functionality behaves as expected.


773-795: Regex usage in test is appropriate.

The use of regex to match the expected output string in VersionCheckResultStr is a robust method to ensure the correctness of the output, especially when dealing with dynamic values in strings.

@nao1215
Copy link
Owner

nao1215 commented Jun 27, 2024

@scop
You checked the code very thoroughly. Thank you!!

@nao1215 nao1215 merged commit 4f0f644 into nao1215:main Jun 27, 2024
19 checks passed
@scop scop deleted the fix/current-uptodate-version branch June 28, 2024 14:08
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.

2 participants