Skip to content

Commit

Permalink
Store extension in CodebaseResource.name #467 (#493)
Browse files Browse the repository at this point in the history
* Create migration on CodebaseResource to append extension to name, if name does not end with extension
    * Update exptected test results

Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang authored Aug 10, 2022
1 parent f44fd36 commit 525f046
Show file tree
Hide file tree
Showing 16 changed files with 1,589 additions and 1,538 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ v31.0.0 (next)
to any filters.
https://github.com/nexB/scancode.io/issues/296

- CodebaseResource.name now contains both the bare file name with extension, as
opposed to just the bare file name without extension.

- Using a name stripped from its extension was something that was not used in
other AboutCode project or tools.

https://github.com/nexB/scancode.io/issues/467

v30.2.0 (2021-12-17)
--------------------

Expand Down
25 changes: 25 additions & 0 deletions scanpipe/migrations/0019_auto_20220804_1836.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.0.6 on 2022-08-04 18:36

from django.db import migrations
from django.db.models import F, Q
from django.db.models.functions import Concat


def concat_codebaseresource_name_and_extension(apps, schema_editor):
CodebaseResource = apps.get_model('scanpipe', 'CodebaseResource')
qs = CodebaseResource.objects.filter(
Q(extension__isnull=False) # Has an "extension" value
& ~Q(name__endswith=F("extension")) # "name" do not ends with the "extension"
)
qs.update(name=Concat(F("name"), F("extension")))


class Migration(migrations.Migration):

dependencies = [
('scanpipe', '0018_codebaseresource_tag'),
]

operations = [
migrations.RunPython(concat_codebaseresource_name_and_extension),
]
18 changes: 18 additions & 0 deletions scanpipe/migrations/0020_alter_codebaseresource_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.6 on 2022-08-09 17:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('scanpipe', '0019_auto_20220804_1836'),
]

operations = [
migrations.AlterField(
model_name='codebaseresource',
name='name',
field=models.CharField(blank=True, help_text='File or directory name of this resource with its extension.', max_length=255),
),
]
2 changes: 1 addition & 1 deletion scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ class Type(models.TextChoices):
name = models.CharField(
max_length=255,
blank=True,
help_text=_("File or directory name of this resource."),
help_text=_("File or directory name of this resource with its extension."),
)
extension = models.CharField(
max_length=100,
Expand Down
2 changes: 1 addition & 1 deletion scanpipe/pipes/scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_resource_info(location):
file_info.update(
{
"type": resource_type,
"name": fileutils.file_base_name(location),
"name": fileutils.file_name(location),
"extension": fileutils.file_extension(location),
}
)
Expand Down
Loading

0 comments on commit 525f046

Please sign in to comment.