Repository navigation
Refactor licenses command - #321
Conversation
There was a problem hiding this comment.
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 modularizelicensesand 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
licensescommand.
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.
| } | ||
| for purl, pkg := range cached { | ||
| result[purl] = &licenseData{ | ||
| License: pkg.License, |
There was a problem hiding this comment.
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.
Breaks the
licensescommand 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.