Add license validation for repositories#5343
Conversation
Add a license validation check that verifies the repository has an OSI-approved open source license, using the SPDX identifier reported by the GitHub API. The set of OSI-approved licenses is fetched on each invocation from the SPDX license list (spdx/license-list-data), pinned to the v3.28.0 release commit, filtering on isOsiApproved. Deprecated SPDX IDs (such as GPL-3.0) are kept since GitHub still reports them for many repositories. The pin carries a renovate annotation comment so a custom manager can keep it updated later. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G9QQsoXZefeSfniDY9utsk
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G9QQsoXZefeSfniDY9utsk
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G9QQsoXZefeSfniDY9utsk
There was a problem hiding this comment.
Pull request overview
This pull request introduces a new HACS Action validator that enforces repositories to have an OSI-approved license by validating the repo’s detected SPDX ID against the official SPDX license list, and updates tests/snapshots to reflect the added check.
Changes:
- Added a new
licensevalidator that downloads the SPDX license list and enforcesisOsiApproved. - Added unit tests and a mocked SPDX license-list fixture for validation scenarios.
- Updated action/integration snapshots and “checks passed” totals to account for the 9th validator.
Reviewed changes
Copilot reviewed 16 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| custom_components/hacs/validate/license.py | New validator that fetches SPDX license data and validates OSI approval. |
| tests/validate/test_license.py | New tests covering missing/unrecognized/non-OSI licenses and fetch failures. |
| tests/fixtures/proxy/raw.githubusercontent.com/spdx/license-list-data/c4a7237ec8f4654e867546f9f409749300f1bf4c/json/licenses.json | Mock SPDX license list used by tests. |
| tests/action/test_hacs_action_integration.py | Updates expected “checks passed/failed” counts from 8 to 9. |
| tests/snapshots/api-usage/tests/validate/test_licensetest-spdx-license-list-fetch-failure.json | New API-usage snapshot for SPDX fetch-failure test. |
| tests/snapshots/api-usage/tests/validate/test_licensetest-repository-unrecognized-license.json | New API-usage snapshot for unrecognized license test. |
| tests/snapshots/api-usage/tests/validate/test_licensetest-repository-osi-approved-license-mit.json | New API-usage snapshot for MIT OSI-approved license test. |
| tests/snapshots/api-usage/tests/validate/test_licensetest-repository-osi-approved-license-gpl-3-0.json | New API-usage snapshot for GPL-3.0 OSI-approved license test. |
| tests/snapshots/api-usage/tests/validate/test_licensetest-repository-non-osi-license.json | New API-usage snapshot for non-OSI license test. |
| tests/snapshots/api-usage/tests/validate/test_licensetest-repository-no-license.json | New API-usage snapshot for no-license test. |
| tests/snapshots/api-usage/tests/validate/test_licensetest-repository-missing-spdx-id.json | New API-usage snapshot for missing SPDX ID test. |
| tests/snapshots/api-usage/tests/action/test_hacs_action_integrationtest-hacs-action-integration-valid-manifest.json | Adds SPDX license list URL to action API-usage snapshot. |
| tests/snapshots/api-usage/tests/action/test_hacs_action_integrationtest-hacs-action-integration-releases-without-assets.json | Adds SPDX license list URL to action API-usage snapshot. |
| tests/snapshots/api-usage/tests/action/test_hacs_action_integrationtest-hacs-action-integration-no-releases.json | Adds SPDX license list URL to action API-usage snapshot. |
| tests/snapshots/api-usage/tests/action/test_hacs_action_integrationtest-hacs-action-integration-bad-issue-tracker.json | Adds SPDX license list URL to action API-usage snapshot. |
| tests/snapshots/api-usage/tests/action/test_hacs_action_integrationtest-hacs-action-integration-bad-documentation.json | Adds SPDX license list URL to action API-usage snapshot. |
| tests/snapshots/action/test_hacs_action_integration/valid_manifest.log | Adds <Validation license> line and updates total checks to 9. |
| tests/snapshots/action/test_hacs_action_integration/releases_without_assets.log | Adds <Validation license> line and updates total checks to 9. |
| tests/snapshots/action/test_hacs_action_integration/no_releases.log | Adds <Validation license> line and updates total checks to 9. |
| tests/snapshots/action/test_hacs_action_integration/bad_issue_tracker.log | Adds <Validation license> line and updates total checks to 9. |
| tests/snapshots/action/test_hacs_action_integration/bad_documentation.log | Adds <Validation license> line and updates total checks to 9. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Fail immediately when the license has no usable SPDX ID (missing or NOASSERTION) instead of downloading the SPDX license list first, since the check can never pass in those cases. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G9QQsoXZefeSfniDY9utsk
| "The repository license could not be identified (SPDX: NOASSERTION)" | ||
| ) | ||
|
|
||
| result = await self.hacs.async_download_file(SPDX_LICENSE_LIST_URL, handle_rate_limit=True) |
There was a problem hiding this comment.
Not currently, but we can store a set of IDs.
| raise ValidationException("Could not fetch the SPDX license list") | ||
|
|
||
| try: | ||
| licenses = json_loads(result).get("licenses", []) |
There was a problem hiding this comment.
Same thing. Is this running for all repos or just one? Should we cache the json loading
There was a problem hiding this comment.
This validator is for the HACS Github action.
There would be little benefit caching this between runs.
However if the fetch is cached this load will not be here.
HACS added SPDX license validation (hacs/integration#5343); custom proprietary text resolves to NOASSERTION and fails validate. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Summary
This PR adds a new license validation check for repositories that verifies they have an OSI-approved license according to the SPDX license list.
Key Changes
New validator: Added
custom_components/hacs/validate/license.pythat:Comprehensive test coverage: Added
tests/validate/test_license.pywith tests for:Test fixtures: Added mock SPDX license list data for testing
Integration: Updated existing integration test snapshots to reflect the new 9th validation check (previously 8)
Implementation Details
c4a7237ec8f4654e867546f9f409749300f1bf4c(v3.28.0)isOsiApprovedflag to determine validityhttps://claude.ai/code/session_01G9QQsoXZefeSfniDY9utsk