-
Notifications
You must be signed in to change notification settings - Fork 732
feat: fetch and store repo license via licensee IN-1105 #4095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gaspergrom
wants to merge
7
commits into
main
Choose a base branch
from
feat/IN-1105-fetch-store-repo-license-via-licensee
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0f11470
feat: detect and store repo license via licensee IN-1105
gaspergrom 19bd389
fix: correct licensee version, JSON parsing, and null type cast IN-1105
gaspergrom 58d4968
fix: ruff format license_service and add license to IRepository DAL I…
gaspergrom a1b1638
fix: ruff line length violations in license_service IN-1105
gaspergrom f7cff21
fix: remove useless try/catch wrappers in member activities
gaspergrom 39a9da7
fix: address review comments on license detection IN-1105
gaspergrom e51b77c
fix: wrap long run_shell_command call in license_service IN-1105
gaspergrom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
backend/src/database/migrations/U1778154987__addLicenseToRepositories.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE public.repositories DROP COLUMN license; |
1 change: 1 addition & 0 deletions
1
backend/src/database/migrations/V1778154987__addLicenseToRepositories.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE public.repositories ADD COLUMN license VARCHAR(255); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
services/apps/git_integration/src/crowdgit/services/license/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from crowdgit.services.license.license_service import LicenseService | ||
|
|
||
| __all__ = ["LicenseService"] |
49 changes: 49 additions & 0 deletions
49
services/apps/git_integration/src/crowdgit/services/license/license_service.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import json | ||
|
|
||
| from crowdgit.errors import CommandExecutionError, CommandTimeoutError | ||
| from crowdgit.services.base.base_service import BaseService | ||
| from crowdgit.services.utils import run_shell_command | ||
|
|
||
|
|
||
| class LicenseService(BaseService): | ||
| """Detects SPDX license from a cloned repository using the licensee gem.""" | ||
|
|
||
| async def detect(self, repo_path: str) -> str | None: | ||
| """Run licensee against repo_path and return the SPDX identifier, or None.""" | ||
|
gaspergrom marked this conversation as resolved.
|
||
| try: | ||
| output = await run_shell_command( | ||
| ["licensee", "detect", "--json", repo_path], timeout=60 | ||
| ) | ||
| except CommandExecutionError: | ||
| self.logger.info(f"licensee found no license in {repo_path}") | ||
|
gaspergrom marked this conversation as resolved.
|
||
| return None | ||
|
gaspergrom marked this conversation as resolved.
|
||
| except CommandTimeoutError as e: | ||
| self.logger.warning(f"licensee timed out: {repr(e)}") | ||
| return None | ||
| except FileNotFoundError as e: | ||
| self.logger.warning(f"licensee binary not found in PATH: {repr(e)}") | ||
| return None | ||
| except Exception as e: | ||
| self.logger.warning(f"licensee failed: {repr(e)}") | ||
| return None | ||
|
|
||
| try: | ||
| data = json.loads(output) | ||
| licenses = data.get("licenses") or [] | ||
| matched_files = data.get("matched_files") or [] | ||
| spdx_id = licenses[0].get("spdx_id") if licenses else None | ||
| confidence = ( | ||
| (matched_files[0].get("matcher") or {}).get("confidence") | ||
| if matched_files | ||
| else None | ||
| ) | ||
|
gaspergrom marked this conversation as resolved.
|
||
| if spdx_id: | ||
| self.logger.info( | ||
| f"License detected: {spdx_id} (confidence={confidence}) in {repo_path}" | ||
| ) | ||
| else: | ||
| self.logger.info(f"No SPDX license matched in {repo_path}") | ||
| return spdx_id | ||
| except Exception as e: | ||
| self.logger.warning(f"Failed to parse licensee output: {repr(e)}") | ||
| return None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.