-
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
Changes from all commits
0f11470
19bd389
58d4968
a1b1638
f7cff21
39a9da7
e51b77c
ef58578
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE public.repositories DROP COLUMN license; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE public.repositories ADD COLUMN license VARCHAR(255); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from crowdgit.services.license.license_service import LicenseService | ||
|
|
||
| __all__ = ["LicenseService"] |
| 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 | ||
| ) | ||
|
Comment on lines
+11
to
+16
|
||
| 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.
Comment on lines
+11
to
+19
|
||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Transient detection errors silently clear existing license dataMedium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit ef58578. Configure here. |
||
|
|
||
| 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 | ||


Uh oh!
There was an error while loading. Please reload this page.