Skip to content

Extract portable RubyGems metadata transformations - #803

Open
simonchrz wants to merge 2 commits into
git-pkgs:mainfrom
simonchrz:refactor/metadata-gem
Open

simonchrz wants to merge 2 commits into
git-pkgs:mainfrom
simonchrz:refactor/metadata-gem

Conversation

@simonchrz

@simonchrz simonchrz commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Part of #501, the RubyGems step.

As in #612 for npm, the RubyGems metadata transformations move out of internal/handler into internal/metadata/gem:

  • FilterIndex, which drops the compact index lines of the versions cooldown holds back and returns the versions it kept
  • IndexVersions, which lists a compact index's versions as the versions API names them
  • PublishTimes and Version, which read publish times from /api/v1/versions/{name}.json, keyed with the platform as the compact index writes it
  • FilenameIdentity, the gem filename parser

The compact index carries no publish times; they come from the versions API document fetched alongside it. FilterIndex takes the same kind of Options as the npm, PyPI and Composer packages: a CooldownPolicy, the evaluation time and an OnWithheld callback, plus the publish times (Published) and WithholdUnknown, which holds back versions the times don't have when they may be older than the index. It decides per version itself. The package doesn't depend on handler.Proxy.

One behaviour change: every version of an index is now judged at one time, the proxy's clock, instead of the system time at each check. In production these are the same.

What stays in the handler: fetching, the metadata and rewrite caches, routes and downloads. The handler's functions stay as thin wrappers and gemVersion is an alias for gem.Version, so the handler tests run unchanged. internal/mirror calls gem.FilenameIdentity; handler.GemFilenameIdentity stays as a wrapper.

Portability: GOOS=wasip1 GOARCH=wasm go build ./internal/metadata/gem works. imports_test.go fails on any non-standard import outside an allowlist (cooldown, internal/packageurl and what it uses) and on net, net/http, log/slog or database/sql.

New tests in internal/metadata/gem cover the filter (versions in cooldown, no or a disabled policy, versions without a time, the callback, the evaluation time), the version listing, publish times with platforms and unparseable times, and the filename parser including its length bound. They were mutation-checked, as was the handler's wiring. TestCooldownSupportedCoversHandlers now also reads internal/metadata, as in the pub, Cargo, NuGet and Conda PRs. There are no gem benchmarks to compare. go test ./... and golangci-lint run ./... pass.

Summary by CodeRabbit

  • Refactor
    • RubyGems filenames, version listings, and publish-time information are now handled consistently. Existing cooldown filtering and artifact caching behavior remain unchanged.
  • Tests
    • Added coverage for RubyGems version filtering, publish-time parsing, and filename identification.

The compact index filter, the version listing, the versions API's
publish times and the gem filename parser move out of internal/handler
into internal/metadata/gem, which imports only the standard library and
builds for wasip1. The handler keeps fetching, caching, the cooldown
decision and downloads, and its functions stay as thin wrappers, so the
handler tests run unchanged. internal/mirror calls gem.FilenameIdentity.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

RubyGems filename and metadata operations now live in internal/metadata/gem. The handler delegates compact-index extraction, filtering, and publish-time parsing to that package. Mirror cache identity callbacks use its filename parser. Tests cover parsing, filtering, publish times, and package import constraints.

Changes: RubyGems metadata extraction

Layer / File(s) Summary
Metadata helper contracts and behavior
internal/metadata/gem/filename.go, internal/metadata/gem/metadata.go, internal/metadata/gem/*_test.go
FilenameIdentity parses gem names and versions, including platform suffixes. IndexVersions extracts compact-index versions, FilterIndex applies cooldown options and reports withheld versions, and PublishTimes parses version timestamps. Tests cover these behaviors and package import constraints.
Handler and mirror delegation
internal/handler/gem.go, internal/mirror/files.go, internal/handler/cooldown_supported_test.go
The handler delegates filename parsing, index processing, filtering, and publish-time parsing to the metadata package. It logs and records withheld versions through a callback. The mirror uses the package parser for gem cache identities, and the cooldown support test scans metadata files.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related issues

  • git-pkgs/proxy#501 — This change moves RubyGems metadata transformations and filename parsing into a package with import constraints, matching part of the issue’s portability objective.
  • git-pkgs/proxy#127 — FilterIndex reports withheld versions through a callback, which partially matches the requested filtering hook. This change does not add the generic interface or withheld-query behavior described in the issue.

Possibly related PRs

  • git-pkgs/proxy#739 — Both changes use gem filename parsing in the mirror path, so their filename identity contracts must agree.

Suggested reviewers: andrew

Merge Risk: Minimal · up to d1b09

This change moves RubyGems metadata handling into a separate package and keeps the handler and mirror behavior the same. No merge-blocking issues were found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Extract portable RubyGems metadata transformations" matches the main change. The PR moves RubyGems metadata logic (filtering, version listing, publish-time parsing, filename identity) from …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Extract portable RubyGems metadata transformations" matches the main change. The PR moves RubyGems metadata logic (filtering, version listing, publish-time parsing, filename identity) from internal/handler into a new portable internal/metadata/gem package, and the handler becomes a thin wrapper. The title is concise, specific, and omits no critical part of the primary change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3880de8c-e07e-4558-ba5e-7638533c860c
Commits

Reviewing files that changed from the base of the PR and between 1b7cced and d1b09b7.

Files selected for processing: 5

  • internal/handler/cooldown_supported_test.go
  • internal/handler/gem.go
  • internal/metadata/gem/imports_test.go
  • internal/metadata/gem/metadata.go
  • internal/metadata/gem/metadata_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

gem.FilterIndex took a callback saying which versions to leave out. It now
takes Options with a CooldownPolicy, the evaluation time and the publish
times read from the versions API, as the other metadata packages do, and
decides per version itself. The handler passes the proxy clock.
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.

1 participant