-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 1426-optional-step
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
- Loading branch information
Showing
20 changed files
with
547 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
Empty file.
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -209,6 +209,7 @@ class Meta: | |
"name", | ||
"url", | ||
"uuid", | ||
"purl", | ||
"upload_file", | ||
"upload_file_tag", | ||
"input_urls", | ||
|
This file contains 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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
from django.core.exceptions import ObjectDoesNotExist | ||
from django.core.exceptions import ValidationError | ||
|
||
from packageurl import PackageURL | ||
from taggit.forms import TagField | ||
from taggit.forms import TagWidget | ||
|
||
|
@@ -480,12 +481,31 @@ class Meta: | |
fields = [ | ||
"name", | ||
"notes", | ||
"purl", | ||
] | ||
widgets = { | ||
"name": forms.TextInput(attrs={"class": "input"}), | ||
"notes": forms.Textarea(attrs={"rows": 3, "class": "textarea is-dynamic"}), | ||
"purl": forms.TextInput( | ||
attrs={ | ||
"class": "input", | ||
"placeholder": "pkg:npm/[email protected]", | ||
} | ||
), | ||
} | ||
|
||
def clean_purl(self): | ||
"""Validate the Project PURL.""" | ||
purl = self.cleaned_data.get("purl") | ||
|
||
if purl: | ||
try: | ||
PackageURL.from_string(purl) | ||
except ValueError: | ||
raise forms.ValidationError("PURL must be a valid PackageURL") | ||
|
||
return purl | ||
|
||
def __init__(self, *args, **kwargs): | ||
"""Load initial values from Project ``settings`` field.""" | ||
super().__init__(*args, **kwargs) | ||
|
This file contains 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,18 @@ | ||
# Generated by Django 5.1.3 on 2024-11-08 12:47 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('scanpipe', '0068_rename_discovered_dependencies_attribute'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='project', | ||
name='purl', | ||
field=models.CharField(blank=True, help_text='Package URL for the project, used for pushing project scan result to FederatedCode. This should be the PURL of the input.', max_length=2048), | ||
), | ||
] |
This file contains 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 |
---|---|---|
|
@@ -562,6 +562,16 @@ class Project(UUIDPKModel, ExtraDataFieldMixin, UpdateMixin, models.Model): | |
notes = models.TextField(blank=True) | ||
settings = models.JSONField(default=dict, blank=True) | ||
labels = TaggableManager(through=UUIDTaggedItem) | ||
purl = models.CharField( | ||
max_length=2048, | ||
blank=True, | ||
help_text=_( | ||
"Package URL (PURL) for the project, required for pushing the project's " | ||
"scan result to FederatedCode. For example, if the input is an input URL " | ||
"like https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz, the " | ||
"corresponding PURL would be pkg:npm/[email protected]." | ||
), | ||
) | ||
|
||
objects = ProjectQuerySet.as_manager() | ||
|
||
|
@@ -705,6 +715,7 @@ def clone( | |
"""Clone this project using the provided ``clone_name`` as new project name.""" | ||
new_project = Project.objects.create( | ||
name=clone_name, | ||
purl=self.purl, | ||
settings=self.settings if copy_settings else {}, | ||
) | ||
|
||
|
This file contains 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,97 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# http://nexb.com and https://github.com/aboutcode-org/scancode.io | ||
# The ScanCode.io software is licensed under the Apache License version 2.0. | ||
# Data generated with ScanCode.io is provided as-is without warranties. | ||
# ScanCode is a trademark of nexB Inc. | ||
# | ||
# You may not use this software except in compliance with the License. | ||
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
# | ||
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from | ||
# ScanCode.io should be considered or used as legal advice. Consult an Attorney | ||
# for any legal advice. | ||
# | ||
# ScanCode.io is a free software code scanning tool from nexB Inc. and others. | ||
# Visit https://github.com/aboutcode-org/scancode.io for support and download. | ||
|
||
|
||
from scanpipe.pipelines import Pipeline | ||
from scanpipe.pipes import federatedcode | ||
|
||
|
||
class PublishToFederatedCode(Pipeline): | ||
""" | ||
Publish package scan to FederatedCode. | ||
This pipeline commits the project scan result in FederatedCode Git repository. | ||
It uses ``Project PURL`` to determine the Git repository and the | ||
exact directory path where the scan should be stored. | ||
""" | ||
|
||
download_inputs = False | ||
is_addon = True | ||
|
||
@classmethod | ||
def steps(cls): | ||
return ( | ||
cls.check_federatedcode_eligibility, | ||
cls.get_package_repository, | ||
cls.clone_repository, | ||
cls.add_scan_result, | ||
cls.commit_and_push_changes, | ||
cls.delete_local_clone, | ||
) | ||
|
||
def check_federatedcode_eligibility(self): | ||
""" | ||
Check if the project fulfills the following criteria for | ||
pushing the project result to FederatedCode. | ||
""" | ||
federatedcode.check_federatedcode_eligibility(project=self.project) | ||
|
||
def get_package_repository(self): | ||
"""Get the Git repository URL and scan path for a given package.""" | ||
self.package_git_repo, self.package_scan_file = ( | ||
federatedcode.get_package_repository( | ||
project_purl=self.project.purl, logger=self.log | ||
) | ||
) | ||
|
||
def clone_repository(self): | ||
"""Clone repository to local_path.""" | ||
self.repo = federatedcode.clone_repository( | ||
repo_url=self.package_git_repo, | ||
logger=self.log, | ||
) | ||
|
||
def add_scan_result(self): | ||
"""Add package scan result to the local Git repository.""" | ||
self.relative_file_path = federatedcode.add_scan_result( | ||
project=self.project, | ||
repo=self.repo, | ||
package_scan_file=self.package_scan_file, | ||
logger=self.log, | ||
) | ||
|
||
def commit_and_push_changes(self): | ||
"""Commit and push changes to remote repository.""" | ||
federatedcode.commit_and_push_changes( | ||
repo=self.repo, | ||
file_to_commit=str(self.relative_file_path), | ||
purl=self.project.purl, | ||
logger=self.log, | ||
) | ||
self.log( | ||
f"Scan result for '{self.project.purl}' " | ||
f"pushed to '{self.package_git_repo}'" | ||
) | ||
|
||
def delete_local_clone(self): | ||
"""Remove local clone.""" | ||
federatedcode.delete_local_clone(repo=self.repo) |
Oops, something went wrong.