Skip to content

Commit 5461cbd

Browse files
authored
Add all "classify" plugin fields on the CodebaseResource model #1275 (#1286)
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent d528a2a commit 5461cbd

31 files changed

+9553
-592
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
v34.6.4 (unreleased)
5+
--------------------
6+
7+
- Add all "classify" plugin fields from scancode-toolkit on the CodebaseResource model.
8+
https://github.com/nexB/scancode.io/issues/1275
9+
410
v34.6.3 (2024-06-21)
511
--------------------
612

scanpipe/api/serializers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ class Meta:
315315
"is_text",
316316
"is_archive",
317317
"is_media",
318+
"is_legal",
319+
"is_manifest",
320+
"is_readme",
321+
"is_top_level",
318322
"is_key_file",
319323
"detected_license_expression",
320324
"detected_license_expression_spdx",

scanpipe/filters.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,12 @@ class Meta:
566566
"is_binary",
567567
"is_text",
568568
"is_archive",
569-
"is_key_file",
570569
"is_media",
570+
"is_legal",
571+
"is_manifest",
572+
"is_readme",
573+
"is_top_level",
574+
"is_key_file",
571575
]
572576

573577
def __init__(self, *args, **kwargs):
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Generated by Django 5.0.6 on 2024-06-24 05:57
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("scanpipe", "0060_discovereddependency_renames"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="codebaseresource",
15+
name="is_legal",
16+
field=models.BooleanField(
17+
default=False,
18+
help_text="True if this file is likely a legal, license-related file such as a COPYING or LICENSE file.",
19+
),
20+
),
21+
migrations.AddField(
22+
model_name="codebaseresource",
23+
name="is_manifest",
24+
field=models.BooleanField(
25+
default=False,
26+
help_text="True if this file is likely a package manifest file such as a Maven pom.xml or an npm package.json",
27+
),
28+
),
29+
migrations.AddField(
30+
model_name="codebaseresource",
31+
name="is_readme",
32+
field=models.BooleanField(
33+
default=False, help_text="True if this file is likely a README file."
34+
),
35+
),
36+
migrations.AddField(
37+
model_name="codebaseresource",
38+
name="is_top_level",
39+
field=models.BooleanField(
40+
default=False,
41+
help_text="True if this file is top-level file located either at the root of a package or in a well-known common location.",
42+
),
43+
),
44+
migrations.AlterField(
45+
model_name="codebaseresource",
46+
name="is_key_file",
47+
field=models.BooleanField(
48+
default=False,
49+
help_text="True if this file is top-level file and either a legal, readme or manifest file.",
50+
),
51+
),
52+
]

scanpipe/models.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2343,9 +2343,53 @@ def compute_compliance_alert(self):
23432343
return self.Compliance.OK
23442344

23452345

2346+
class FileClassifierFieldsModelMixin(models.Model):
2347+
"""
2348+
Fields returned by the ScanCode-toolkit ``--classify`` plugin.
2349+
See ``summarycode.classify_plugin.FileClassifier``.
2350+
"""
2351+
2352+
is_legal = models.BooleanField(
2353+
default=False,
2354+
help_text=_(
2355+
"True if this file is likely a legal, license-related file such as a "
2356+
"COPYING or LICENSE file."
2357+
),
2358+
)
2359+
is_manifest = models.BooleanField(
2360+
default=False,
2361+
help_text=_(
2362+
"True if this file is likely a package manifest file such as a Maven "
2363+
"pom.xml or an npm package.json"
2364+
),
2365+
)
2366+
is_readme = models.BooleanField(
2367+
default=False,
2368+
help_text=_("True if this file is likely a README file."),
2369+
)
2370+
is_top_level = models.BooleanField(
2371+
default=False,
2372+
help_text=_(
2373+
"True if this file is top-level file located either at the root of a "
2374+
"package or in a well-known common location."
2375+
),
2376+
)
2377+
is_key_file = models.BooleanField(
2378+
default=False,
2379+
help_text=_(
2380+
"True if this file is top-level file and either a legal, readme or "
2381+
"manifest file."
2382+
),
2383+
)
2384+
2385+
class Meta:
2386+
abstract = True
2387+
2388+
23462389
class CodebaseResource(
23472390
ProjectRelatedModel,
23482391
ScanFieldsModelMixin,
2392+
FileClassifierFieldsModelMixin,
23492393
ExtraDataFieldMixin,
23502394
SaveProjectMessageMixin,
23512395
UpdateFromDataMixin,
@@ -2440,7 +2484,6 @@ class Type(models.TextChoices):
24402484
is_binary = models.BooleanField(default=False)
24412485
is_text = models.BooleanField(default=False)
24422486
is_archive = models.BooleanField(default=False)
2443-
is_key_file = models.BooleanField(default=False)
24442487
is_media = models.BooleanField(default=False)
24452488
package_data = models.JSONField(
24462489
default=list,

scanpipe/templates/scanpipe/includes/resource_file_viewer.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@
1212
{% if object.is_archive %}
1313
{% include "scanpipe/dropdowns/dropdown_hoverable.html" with trigger='<span class="tag is-info">Archive</span>' content="Archive or compressed file. Not scanned directly." only %}
1414
{% endif %}
15-
{% if object.is_key_file %}
16-
{% include "scanpipe/dropdowns/dropdown_hoverable.html" with trigger='<span class="tag is-info">Key file</span>' content="Top-level file with key content and metadata and either a legal, readme or package manifest." only %}
17-
{% endif %}
1815
{% if object.is_media %}
1916
{% include "scanpipe/dropdowns/dropdown_hoverable.html" with trigger='<span class="tag is-info">Media</span>' content="Image, sound, video or similar media file." only %}
2017
{% endif %}
18+
{% if object.is_legal %}
19+
{% include "scanpipe/dropdowns/dropdown_hoverable.html" with trigger='<span class="tag is-info">Legal</span>' content="Legal, license-related file such as a COPYING or LICENSE file." only %}
20+
{% endif %}
21+
22+
{% if object.is_manifest %}
23+
{% include "scanpipe/dropdowns/dropdown_hoverable.html" with trigger='<span class="tag is-info">Manifest</span>' content="Package manifest file such as a Maven pom.xml or a npm package.json" only %}
24+
{% endif %}
25+
{% if object.is_readme %}
26+
{% include "scanpipe/dropdowns/dropdown_hoverable.html" with trigger='<span class="tag is-info">Readme</span>' content="README file" only %}
27+
{% endif %}
28+
{% if object.is_top_level %}
29+
{% include "scanpipe/dropdowns/dropdown_hoverable.html" with trigger='<span class="tag is-info">Top level</span>' content="Top-level file located either at the root of a package or in a well-known common location." only %}
30+
{% endif %}
31+
32+
{% if object.is_key_file %}
33+
{% include "scanpipe/dropdowns/dropdown_hoverable.html" with trigger='<span class="tag is-info">Key file</span>' content="Top-level file with key content and metadata and either a legal, readme or package manifest." only %}
34+
{% endif %}
2135
</div>
2236
<div class="nav-button">
2337
<button class="button previous-btn is-dark" disabled><i class="fa-solid fa-arrow-up"></i></button>

scanpipe/tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ def make_dependency(project, **extra):
9797
"is_text": True,
9898
"is_archive": False,
9999
"is_media": False,
100+
"is_legal": False,
101+
"is_manifest": False,
102+
"is_readme": False,
103+
"is_top_level": False,
100104
"is_key_file": False,
101105
"license_detections": [],
102106
"detected_license_expression": "",

0 commit comments

Comments
 (0)