Skip to content

Add dependency freshness metrics - #212

Merged
andrew merged 3 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/freshness-staleness-20
May 28, 2026
Merged

andrew merged 3 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/freshness-staleness-20

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Closes #20

Summary

Adds a new git pkgs freshness command for release-age freshness metrics.

The command compares installed dependency versions with registry version publish dates and reports:

  • average days behind latest
  • maximum days behind latest
  • number of lagging dependencies
  • dependencies with the largest release-date lag

Options

Supports:

  • --limit
  • --ecosystem
  • --commit
  • --branch
  • --format json

Notes

This complements git pkgs stale:

  • stale measures how long a dependency has been unchanged in the repo
  • freshness measures how far installed versions lag behind latest registry releases

Tests

  • go build ./...
  • go test ./...
  • go test -race ./...
  • go tool golangci-lint run ./...
  • git diff --check

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new git pkgs freshness command to measure release-age lag between installed dependency versions and registry-published versions, complementing existing stale/outdated dependency analysis.

Changes:

  • Registers and documents the new freshness command.
  • Implements freshness metric computation, cache/API version loading, JSON/text output, and limiting.
  • Adds command tests covering summary output and JSON limiting.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Adds user-facing freshness command examples and explanation.
docs/internals.md Notes freshness as an enrichment-backed command.
cmd/root.go Registers the freshness subcommand.
cmd/pager_test.go Adds freshness to pager flag coverage.
cmd/freshness.go Implements freshness command logic, metrics, enrichment lookup, and output.
cmd/freshness_test.go Adds tests for text and JSON freshness output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/freshness.go Resolved

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is in good shape. It uses the cache layer properly via db.GetCachedVersions / db.SaveVersions and reuses the existing PublishedAt data that outdated already populates, so no schema changes needed.

Two small things before merging:

The 60s context in loadFreshnessVersions wraps the whole sequential loop over missing. On a cold cache with a couple of hundred packages the later fetches will start hitting context deadline exceeded and quietly fall into the unmeasured bucket. Either give each client.GetVersions call its own timeout, or bump the shared one to something like five minutes to match the other enrichment commands.

When there are no resolved dependencies and --format json is set, the command prints No lockfile dependencies found. as plain text. JSON output should always be JSON; emit an empty FreshnessResult instead. Same fix just went in for list in #208.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

This is in good shape. It uses the cache layer properly via db.GetCachedVersions / db.SaveVersions and reuses the existing PublishedAt data that outdated already populates, so no schema changes needed.

Two small things before merging:

The 60s context in loadFreshnessVersions wraps the whole sequential loop over missing. On a cold cache with a couple of hundred packages the later fetches will start hitting context deadline exceeded and quietly fall into the unmeasured bucket. Either give each client.GetVersions call its own timeout, or bump the shared one to something like five minutes to match the other enrichment commands.

When there are no resolved dependencies and --format json is set, the command prints No lockfile dependencies found. as plain text. JSON output should always be JSON; emit an empty FreshnessResult instead. Same fix just went in for list in #208.

thanks, fixed..

loadFreshnessVersions now creates a fresh 60s timeout for each GetVersions call, so a cold cache no longer shares one deadline across the whole missing-package loop...

i also fixed the no-resolved-dependencies JSON path to emit an empty FreshnessResult instead of plain text and added test coverage for that case...

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Both points addressed: per-call timeout in the fetch loop and JSON output for the empty case (with a regression test). Thanks.

@andrew
andrew merged commit b9235b4 into git-pkgs:main May 28, 2026
4 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.

Freshness/staleness metrics

3 participants