Skip to content

Conversation

@mochaaP
Copy link
Contributor

@mochaaP mochaaP commented Sep 4, 2025

On my Fedora system, Go is built with GOEXPERIMENT=nodwarf5, so GoVersion includes X:nodwarf5 in the end. https://github.com/golang/go/blob/80038586ed2814a03dcb95cd6f130766f8d803c3/src/runtime/extern.go#L368-L369

Summary by CodeRabbit

  • Bug Fixes

    • Improved version normalization to more reliably strip common prefixes and ignore trailing Go metadata, reducing false “out-of-date” results and improving displayed version accuracy.
    • Better handling when Go version info is missing to avoid showing incorrect values.
  • Chores

    • Internal parsing refined to broaden version recognition without changing any public interfaces.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

Walkthrough

Update to internal/goutil/goutil.go changing version-string normalization and Go-version extraction: strings.TrimLeft replaced with strings.TrimPrefix for specific prefixes, and GetPackageInformation now sets GoVersion.Current to the left part of info.GoVersion using strings.Cut(..., " "). No public API signatures changed.

Changes

Cohort / File(s) Summary of Changes
goutil parsing changes
internal/goutil/goutil.go
- Replaced strings.TrimLeft with strings.TrimPrefix to remove a single leading "v" from version fields and a single leading "go" from Go version fields in up-to-date checks.
- GetPackageInformation now assigns GoVersion.Current using the left part from strings.Cut(info.GoVersion, " "), discarding any space-delimited trailing data.
- Adjusted internal normalization and parsing logic; no exported signatures or public declarations changed.

Sequence Diagram(s)

(Skipped — changes are localized parsing/normalization tweaks and do not introduce new control-flow interactions.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I hopped through strings and nudged a vine,
Dropped one "v", one "go" — just by design.
A cut took space, the rest went free,
Small rabbit fixes, tidy as can be. 🐇


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b99a945 and 8259398.

📒 Files selected for processing (1)
  • internal/goutil/goutil.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/goutil/goutil.go
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

CodeRabbit Configuration 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/goutil/goutil.go (1)

390-406: Don’t return the GOEXPERIMENT suffix; it breaks version parsing and up‑to‑date checks.

Including " X:…" in the returned string causes versionUpToDate(...) to feed values like "1.22.3 X:nodwarf5" to hashicorp/go-version, which fails to parse and makes tools appear out-of-date. Capture the suffix but exclude it from the returned value.

Apply this diff to keep matching the suffix while returning only the base "go..." token:

-var goVersionRegex = regexp.MustCompile(`(^|\s)(go[1-9]\S+( X:\S+)?)`)
+// capture 1: boundary, capture 2: base go version token, non-capturing optional GOEXPERIMENT tail
+var goVersionRegex = regexp.MustCompile(`(^|\s)(go[1-9]\S+)(?:\sX:\S+)?`)

No change needed below; GetInstalledGoVersion should continue to return m[2], which will now be the base version only.

🧹 Nitpick comments (2)
internal/goutil/goutil.go (2)

133-139: TrimPrefix instead of TrimLeft for version prefixes.

TrimLeft("go") removes any leading 'g'/'o' runes, not the exact "go" prefix. Same for "v". Use TrimPrefix to avoid accidental stripping.

Example:

strings.TrimPrefix(p.Version.Current, "v")
strings.TrimPrefix(p.Version.Latest, "v")
strings.TrimPrefix(p.GoVersion.Current, "go")
strings.TrimPrefix(p.GoVersion.Latest, "go")

392-409: Consider normalizing buildinfo.GoVersion too (may also include " X:…").

If info.GoVersion ever carries the GOEXPERIMENT tail, comparisons will still fail. Optionally normalize both sides.

Minimal helper (can live in this file):

func normalizeGoVersion(s string) string {
	// keep leading "go" for display elsewhere; strip for semver parsing as needed
	if i := strings.Index(s, " X:"); i >= 0 {
		s = s[:i]
	}
	return strings.TrimSpace(s)
}

Use when setting pkg.GoVersion.Current and the value returned from GetInstalledGoVersion() before comparison.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7000556 and 0b92dd3.

📒 Files selected for processing (1)
  • internal/goutil/goutil.go (1 hunks)

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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0b92dd3 and b99a945.

📒 Files selected for processing (1)
  • internal/goutil/goutil.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
internal/goutil/goutil.go (1)
internal/cmdinfo/cmdinfo.go (1)
  • Version (9-9)
🔇 Additional comments (1)
internal/goutil/goutil.go (1)

134-139: Good switch to TrimPrefix; avoids over-stripping.

Replacing TrimLeft with TrimPrefix prevents accidentally removing multiple leading characters. This is correct for both "v" and "go" prefixes.

@mochaaP mochaaP changed the title Include potential GOEXPERIMENT flag in GoVersion regex Trim potential GOEXPERIMENT flag in buildinfo Sep 4, 2025
@nao1215
Copy link
Owner

nao1215 commented Sep 4, 2025

@mochaaP
Thank you for taking the time to fix the bug. I'll merge it.

@nao1215 nao1215 merged commit b88589f into nao1215:main Sep 4, 2025
14 checks passed
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