Skip to content

Commit 8614382

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 57bd9d9 commit 8614382

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
@@ -2685,6 +2685,14 @@ class CodebaseResource(
26852685
'Eg.: "/usr/bin/bash" for a path of "tarball-extract/rootfs/usr/bin/bash"'
26862686
),
26872687
)
2688+
2689+
ancestor = models.CharField(
2690+
max_length=2000,
2691+
null=True,
2692+
blank=True,
2693+
help_text="Path of the immediate parent directory of this resource. Its '.' for top-level resources.",
2694+
)
2695+
26882696
status = models.CharField(
26892697
blank=True,
26902698
max_length=50,
@@ -2772,6 +2780,7 @@ class Meta:
27722780
models.Index(fields=["compliance_alert"]),
27732781
models.Index(fields=["is_binary"]),
27742782
models.Index(fields=["is_text"]),
2783+
models.Index(fields=["project", "ancestor"]),
27752784
]
27762785
constraints = [
27772786
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)