-
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.
Add step to tag resources based on content and name #688
Signed-off-by: Thomas Druez <tdruez@nexb.com>
- Loading branch information
Showing
10 changed files
with
143 additions
and
26 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
scanpipe/migrations/0031_codebaseresource_scanpipe_co_status_20d02b_idx.py
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,16 @@ | ||
# Generated by Django 4.2 on 2023-04-21 13:01 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("scanpipe", "0030_codebaserelation_scanpipe_co_relatio_40d26d_idx_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddIndex( | ||
model_name="codebaseresource", | ||
index=models.Index(fields=["status"], name="scanpipe_co_status_20d02b_idx"), | ||
), | ||
] |
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# http://nexb.com and https://github.com/nexB/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/nexB/scancode.io for support and download. | ||
|
||
|
||
def tag_empty_codebase_resources(project): | ||
"""Tags empty files as ignored.""" | ||
qs = ( | ||
project.codebaseresources.files() | ||
.empty() | ||
.filter(status__in=("", "not-analyzed")) | ||
) | ||
return qs.update(status="ignored-empty-file") | ||
|
||
|
||
def tag_ignored_filenames(project, filenames): | ||
"""Tag codebase resource as `ignored` status from list of `filenames`.""" | ||
qs = project.codebaseresources.no_status().filter(name__in=filenames) | ||
return qs.update(status="ignored-filename") | ||
|
||
|
||
def tag_ignored_extensions(project, extensions): | ||
"""Tag codebase resource as `ignored` status from list of `extensions`.""" | ||
qs = project.codebaseresources.no_status().filter(extension__in=extensions) | ||
return qs.update(status="ignored-extension") |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# http://nexb.com and https://github.com/nexB/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/nexB/scancode.io for support and download. | ||
|
||
from django.test import TestCase | ||
|
||
from scanpipe.models import CodebaseResource | ||
from scanpipe.models import Project | ||
from scanpipe.pipes import tag | ||
|
||
|
||
class ScanPipeTagPipesTest(TestCase): | ||
def setUp(self): | ||
self.project1 = Project.objects.create(name="Analysis") | ||
self.resource1 = CodebaseResource.objects.create( | ||
project=self.project1, path="dir/" | ||
) | ||
self.resource2 = CodebaseResource.objects.create( | ||
project=self.project1, | ||
type=CodebaseResource.Type.FILE, | ||
path="dir/filename.ext", | ||
name="filename.ext", | ||
extension=".ext", | ||
) | ||
|
||
def test_scanpipe_pipes_tag_tag_empty_codebase_resources(self): | ||
tag.tag_empty_codebase_resources(self.project1) | ||
self.resource1.refresh_from_db() | ||
self.resource2.refresh_from_db() | ||
self.assertEqual("", self.resource1.status) | ||
self.assertEqual("ignored-empty-file", self.resource2.status) | ||
|
||
def test_scanpipe_pipes_tag_tag_ignored_filenames(self): | ||
tag.tag_ignored_filenames(self.project1, filenames=[self.resource2.name]) | ||
self.resource1.refresh_from_db() | ||
self.resource2.refresh_from_db() | ||
self.assertEqual("", self.resource1.status) | ||
self.assertEqual("ignored-filename", self.resource2.status) | ||
|
||
def test_scanpipe_pipes_tag_tag_ignored_extensions(self): | ||
tag.tag_ignored_extensions(self.project1, extensions=[self.resource2.extension]) | ||
self.resource1.refresh_from_db() | ||
self.resource2.refresh_from_db() | ||
self.assertEqual("", self.resource1.status) | ||
self.assertEqual("ignored-extension", self.resource2.status) |