Skip to content

Commit dfab26b

Browse files
committed
Add ancestor field to CodebasResource to track parent path of a resource
Signed-off-by: Aayush Kumar <aayush214.kumar@gmail.com>
1 parent a5343b1 commit dfab26b

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 5.1.9 on 2025-06-12 10:32
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('scanpipe', '0072_discovereddependency_uuid_unique'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='codebaseresource',
15+
name='ancestor',
16+
field=models.CharField(blank=True, help_text="Path of the immediate parent directory of this resource. Its '.' for top-level resources.", max_length=2000, null=True),
17+
),
18+
migrations.AddIndex(
19+
model_name='codebaseresource',
20+
index=models.Index(fields=['project', 'ancestor'], name='scanpipe_co_project_f1a160_idx'),
21+
),
22+
]

scanpipe/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,14 @@ class CodebaseResource(
26952695
'Eg.: "/usr/bin/bash" for a path of "tarball-extract/rootfs/usr/bin/bash"'
26962696
),
26972697
)
2698+
2699+
ancestor = models.CharField(
2700+
max_length=2000,
2701+
null=True,
2702+
blank=True,
2703+
help_text="Path of the immediate parent directory of this resource. Its '.' for top-level resources.",
2704+
)
2705+
26982706
status = models.CharField(
26992707
blank=True,
27002708
max_length=50,
@@ -2788,6 +2796,7 @@ class Meta:
27882796
models.Index(fields=["compliance_alert"]),
27892797
models.Index(fields=["is_binary"]),
27902798
models.Index(fields=["is_text"]),
2799+
models.Index(fields=["project", "ancestor"]),
27912800
]
27922801
constraints = [
27932802
models.UniqueConstraint(

scanpipe/pipes/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def make_codebase_resource(project, location, save=True, **extra_fields):
7171
from scanpipe.pipes import flag
7272

7373
relative_path = Path(location).relative_to(project.codebase_path)
74+
parent_path = str(relative_path.parent)
7475
try:
7576
resource_data = scancode.get_resource_info(location=str(location))
7677
except OSError as error:
@@ -91,6 +92,7 @@ def make_codebase_resource(project, location, save=True, **extra_fields):
9192
codebase_resource = CodebaseResource(
9293
project=project,
9394
path=relative_path,
95+
ancestor=parent_path,
9496
**resource_data,
9597
)
9698

0 commit comments

Comments
 (0)