Skip to content

Refactor licenses command - #321

Merged
andrew merged 1 commit into
mainfrom
cleanup/licenses-command
Aug 14, 2026
Merged

andrew merged 1 commit into
mainfrom
cleanup/licenses-command

Conversation

@andrew

@andrew andrew commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Breaks the licenses command into focused helpers for option parsing, package lookup, license policy evaluation, result building, output, caching, and API fetching.

Removes the unused dependency map parameter from license metadata lookup. Adds coverage for policy and output paths, plus a command benchmark to guard performance.

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

Refactors the licenses command implementation into smaller helpers to separate concerns (flag parsing, dependency selection, lookup/caching, policy evaluation, and output), while updating the license metadata lookup API and expanding coverage (tests + benchmark) to protect behavior and performance.

Changes:

  • Introduces licenseOptions, licensePolicy, and helper functions to modularize licenses and drift handling.
  • Refactors license metadata lookup to remove the unused dependency-map parameter and split cache vs API fetching paths.
  • Adds internal tests for policy/output paths and a benchmark for the licenses command.

Reviewed changes

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

File Description
cmd/licenses.go Refactors licenses into focused helpers; updates license lookup/caching and policy/output orchestration.
cmd/licenses_internal_test.go Adds unit tests for policy evaluation and output formatting (plus drift output coverage).
cmd/licenses_benchmark_test.go Adds a benchmark guarding licenses command performance in offline mode.
Suppressed comments (1)

cmd/licenses.go:546

  • licenseDataFromPackage duplicates license normalization logic and doesn’t trim whitespace before calling spdx.Normalize. Using the existing normalizeLicenseString helper keeps behavior consistent with other license paths (e.g., version licenses and drift) and avoids cache-vs-fetch formatting differences.
	data.License = pkg.License

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cmd/licenses.go
}
for purl, pkg := range cached {
result[purl] = &licenseData{
License: pkg.License,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The cache/fetch mismatch predates this refactor: main returns cached license values verbatim and normalizes only API results. This PR preserves that behavior. Normalizing cached values would be a separate behavior change, so I would keep it out of this cleanup and cover it with targeted tests in a follow-up.

@andrew
andrew merged commit aeb17d4 into main Aug 14, 2026
8 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