|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# |
| 3 | +# http://nexb.com and https://github.com/aboutcode-org/scancode.io |
| 4 | +# The ScanCode.io software is licensed under the Apache License version 2.0. |
| 5 | +# Data generated with ScanCode.io is provided as-is without warranties. |
| 6 | +# ScanCode is a trademark of nexB Inc. |
| 7 | +# |
| 8 | +# You may not use this software except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 |
| 10 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 11 | +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | +# CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | +# specific language governing permissions and limitations under the License. |
| 14 | +# |
| 15 | +# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 16 | +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from |
| 17 | +# ScanCode.io should be considered or used as legal advice. Consult an Attorney |
| 18 | +# for any legal advice. |
| 19 | +# |
| 20 | +# ScanCode.io is a free software code scanning tool from nexB Inc. and others. |
| 21 | +# Visit https://github.com/aboutcode-org/scancode.io for support and download. |
| 22 | + |
| 23 | + |
| 24 | +from pathlib import Path |
| 25 | + |
| 26 | +from minecode_pipelines.pipes import nuget |
| 27 | + |
| 28 | +from scanpipe.pipelines import Pipeline |
| 29 | +from scanpipe.pipes import federatedcode |
| 30 | + |
| 31 | + |
| 32 | +class MineNuGet(Pipeline): |
| 33 | + """ |
| 34 | + Mine and Publish NuGet PackageURLs. |
| 35 | +
|
| 36 | + Mine PackageURLs from AboutCode NuGet catalog mirror and publish |
| 37 | + them to FederatedCode Git repository. |
| 38 | + """ |
| 39 | + |
| 40 | + download_inputs = False |
| 41 | + CATALOG_REPO_URL = "https://github.com/aboutcode-org/aboutcode-mirror-nuget-catalog.git" |
| 42 | + |
| 43 | + @classmethod |
| 44 | + def steps(cls): |
| 45 | + return ( |
| 46 | + cls.check_federatedcode_eligibility, |
| 47 | + cls.fetch_nuget_catalog, |
| 48 | + cls.mine_nuget_package_versions, |
| 49 | + cls.mine_and_publish_nuget_packageurls, |
| 50 | + cls.delete_cloned_repos, |
| 51 | + ) |
| 52 | + |
| 53 | + def check_federatedcode_eligibility(self): |
| 54 | + """ |
| 55 | + Check if the project fulfills the following criteria for |
| 56 | + pushing the project result to FederatedCode. |
| 57 | + """ |
| 58 | + federatedcode.check_federatedcode_configured_and_available() |
| 59 | + |
| 60 | + def fetch_nuget_catalog(self): |
| 61 | + """Fetch NuGet package catalog from AboutCode mirror.""" |
| 62 | + self.catalog_repo = federatedcode.clone_repository( |
| 63 | + repo_url=self.CATALOG_REPO_URL, |
| 64 | + logger=self.log, |
| 65 | + ) |
| 66 | + |
| 67 | + def mine_nuget_package_versions(self): |
| 68 | + """Mine NuGet package and versions from NuGet catalog.""" |
| 69 | + self.package_versions, self.skipped_packages = nuget.mine_nuget_package_versions( |
| 70 | + catalog_path=Path(self.catalog_repo.working_dir), |
| 71 | + logger=self.log, |
| 72 | + ) |
| 73 | + |
| 74 | + def mine_and_publish_nuget_packageurls(self): |
| 75 | + """Mine and publish PackageURLs from NuGet package versions.""" |
| 76 | + nuget.mine_and_publish_nuget_packageurls( |
| 77 | + package_versions=self.package_versions, |
| 78 | + logger=self.log, |
| 79 | + ) |
| 80 | + |
| 81 | + def delete_cloned_repos(self): |
| 82 | + """Remove cloned catalog repository.""" |
| 83 | + if self.catalog_repo: |
| 84 | + self.log("Removing cloned repository") |
| 85 | + federatedcode.delete_local_clone(repo=self.catalog_repo) |
0 commit comments