Skip to content

Commit

Permalink
Add a ignore tag step based on paths #688
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Apr 24, 2023
1 parent 73b6984 commit 0ac0243
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions scanpipe/pipelines/develop_to_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def tag_empty_and_ignored_files(self):
tag.tag_empty_codebase_resources(self.project)
tag.tag_ignored_filenames(self.project, filenames=d2d.IGNORE_FILENAMES)
tag.tag_ignored_extensions(self.project, extensions=d2d.IGNORE_EXTENSIONS)
tag.tag_ignored_paths(self.project, paths=d2d.IGNORE_PATHS)

def checksum_match(self):
"""Match using SHA1 checksum."""
Expand Down
2 changes: 1 addition & 1 deletion scanpipe/pipes/d2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
TO = "to/"

IGNORE_FILENAMES = ("packageinfo",)

IGNORE_EXTENSIONS = ()
IGNORE_PATHS = ("gradleTest/",)


def get_inputs(project):
Expand Down
12 changes: 12 additions & 0 deletions scanpipe/pipes/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# 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.db.models import Q


def tag_empty_codebase_resources(project):
"""Tags empty files as ignored."""
Expand All @@ -41,3 +43,13 @@ 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")


def tag_ignored_paths(project, paths):
"""Tag codebase resource as `ignored` status from list of `paths`."""
lookups = Q()
for path in paths:
lookups |= Q(path__contains=path)

qs = project.codebaseresources.no_status().filter(lookups)
return qs.update(status="ignored-path")
7 changes: 7 additions & 0 deletions scanpipe/tests/pipes/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ def test_scanpipe_pipes_tag_tag_ignored_extensions(self):
self.resource2.refresh_from_db()
self.assertEqual("", self.resource1.status)
self.assertEqual("ignored-extension", self.resource2.status)

def test_scanpipe_pipes_tag_tag_ignored_paths(self):
tag.tag_ignored_paths(self.project1, paths=["dir/"])
self.resource1.refresh_from_db()
self.resource2.refresh_from_db()
self.assertEqual("ignored-path", self.resource1.status)
self.assertEqual("ignored-path", self.resource2.status)

0 comments on commit 0ac0243

Please # to comment.