|
26 | 26 |
|
27 | 27 | load_dotenv() |
28 | 28 |
|
| 29 | + |
| 30 | +def build_license_artifact_payload(diff: Diff) -> dict: |
| 31 | + """Build the license artifact payload from a diff, tolerating sparse scan paths.""" |
| 32 | + all_packages = {} |
| 33 | + packages = getattr(diff, "packages", {}) or {} |
| 34 | + for purl in packages: |
| 35 | + package = packages[purl] |
| 36 | + output = { |
| 37 | + "id": package.id, |
| 38 | + "name": package.name, |
| 39 | + "version": package.version, |
| 40 | + "ecosystem": package.type, |
| 41 | + "direct": package.direct, |
| 42 | + "url": package.url, |
| 43 | + "license": package.license, |
| 44 | + "licenseDetails": package.licenseDetails, |
| 45 | + "licenseAttrib": package.licenseAttrib, |
| 46 | + "purl": package.purl, |
| 47 | + } |
| 48 | + all_packages[package.id] = output |
| 49 | + return all_packages |
| 50 | + |
29 | 51 | def cli(): |
30 | 52 | try: |
31 | 53 | main_code() |
@@ -743,22 +765,7 @@ def _is_unprocessed(c): |
743 | 765 |
|
744 | 766 | # Handle license generation |
745 | 767 | if not should_skip_scan and diff.id != "NO_DIFF_RAN" and diff.id != "NO_SCAN_RAN" and config.generate_license: |
746 | | - all_packages = {} |
747 | | - for purl in diff.packages: |
748 | | - package = diff.packages[purl] |
749 | | - output = { |
750 | | - "id": package.id, |
751 | | - "name": package.name, |
752 | | - "version": package.version, |
753 | | - "ecosystem": package.type, |
754 | | - "direct": package.direct, |
755 | | - "url": package.url, |
756 | | - "license": package.license, |
757 | | - "licenseDetails": package.licenseDetails, |
758 | | - "licenseAttrib": package.licenseAttrib, |
759 | | - "purl": package.purl, |
760 | | - } |
761 | | - all_packages[package.id] = output |
| 768 | + all_packages = build_license_artifact_payload(diff) |
762 | 769 | core.save_file(config.license_file_name, json.dumps(all_packages)) |
763 | 770 |
|
764 | 771 | # If we forced API mode due to no supported files, behave as if --disable-blocking was set |
|
0 commit comments