Skip to content

Fix go modules error in package details fetcher due to subpath issue#15096

Merged
AbhishekBhaskar merged 9 commits into
mainfrom
abhishekbhaskar/fix-go-subpath-issue
May 21, 2026
Merged

Fix go modules error in package details fetcher due to subpath issue#15096
AbhishekBhaskar merged 9 commits into
mainfrom
abhishekbhaskar/fix-go-subpath-issue

Conversation

@AbhishekBhaskar
Copy link
Copy Markdown
Contributor

What are you trying to accomplish?

Fixes #15027

Go-based pre-commit additional_dependencies that use sub-package paths (e.g., github.com/wasilibs/go-shellcheck/cmd/shellcheck@v0.10.0) fail to find newer versions. The PackageDetailsFetcher passes the full package path to go list -m -versions -json, but this command expects a module path, not a package path. The Go proxy returns 404 for the sub-package path, causing Dependabot to incorrectly report the current version as the latest.

This change adds a fallback mechanism: when no versions are found for the full path, progressively shorter paths are tried (e.g., github.com/wasilibs/go-shellcheck/cmdgithub.com/wasilibs/go-shellcheck) until the actual module root is found.

Anything you want to highlight for special attention from reviewers?

  • The fallback only triggers when the initial query returns no versions (nil), so existing behavior for valid module paths is unchanged.
  • The minimum path length is 3 segments (e.g., github.com/owner/repo), which is the standard for well-known hosts. This prevents unnecessary queries for paths that can't be valid Go modules.

How will you know you've accomplished your goal?

  • If the correct latest available version for the dependency is fetched even when the subpath is specified
  • Added unit tests for: sub-package path falling back to module root, direct module path working without fallback, and graceful degradation when no path returns versions.
  • All 8 tests in package_details_fetcher_spec.rb pass.

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

@AbhishekBhaskar AbhishekBhaskar self-assigned this May 21, 2026
@AbhishekBhaskar AbhishekBhaskar requested a review from a team as a code owner May 21, 2026 06:15
Copilot AI review requested due to automatic review settings May 21, 2026 06:15
@github-actions github-actions Bot added the L: go:modules Golang modules label May 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Go Modules PackageDetailsFetcher behavior for dependencies specified as sub-package import paths (e.g., .../cmd/tool), by attempting to resolve available versions from progressively shorter paths when the initial go list -m -versions query yields no versions.

Changes:

  • Refactors version retrieval into fetch_module_versions and introduces resolve_module_versions_from_subpath fallback logic.
  • Adds specs covering sub-package fallback, module-root behavior, and the “no versions anywhere” case.
Show a summary per file
File Description
go_modules/lib/dependabot/go_modules/package/package_details_fetcher.rb Adds version-fetch helper and subpath-to-module-root fallback logic.
go_modules/spec/dependabot/go_modules/package/package_details_fetcher_spec.rb Adds unit tests for the new fallback behavior and edge cases.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 3

Comment thread go_modules/lib/dependabot/go_modules/package/package_details_fetcher.rb Outdated
Comment thread go_modules/lib/dependabot/go_modules/package/package_details_fetcher.rb Outdated
Comment thread go_modules/lib/dependabot/go_modules/package/package_details_fetcher.rb Outdated
@AbhishekBhaskar AbhishekBhaskar merged commit ef40a79 into main May 21, 2026
105 checks passed
@AbhishekBhaskar AbhishekBhaskar deleted the abhishekbhaskar/fix-go-subpath-issue branch May 21, 2026 20:01
Copy link
Copy Markdown

@albertoblue87-netizen albertoblue87-netizen left a comment

Choose a reason for hiding this comment

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

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L: go:modules Golang modules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go-based pre-commit additional_dependencies do not find new versions

4 participants