]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: Add fields for series dependencies
authorAdam Hassick <ahassick@iol.unh.edu>
Thu, 30 Jan 2025 19:56:36 +0000 (14:56 -0500)
committerStephen Finucane <stephen@that.guru>
Mon, 10 Mar 2025 22:31:21 +0000 (22:31 +0000)
* Add a ManyToMany field to represent a dependency relationship between
  patch series and a helper method to add dependencies.
* Add the parse_dependency field to the Project model.

Signed-off-by: Adam Hassick <ahassick@iol.unh.edu>
Acked-by: Aaron Conole <aconole@redhat.com>
[stephenfin: Rename Project field from parse_dependencies to
             show_dependencies. Also add 'blank=True' to
             Series.cover_letter field]
Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/migrations/0048_series_dependencies.py [new file with mode: 0644]
patchwork/models.py

diff --git a/patchwork/migrations/0048_series_dependencies.py b/patchwork/migrations/0048_series_dependencies.py
new file mode 100644 (file)
index 0000000..8368a24
--- /dev/null
@@ -0,0 +1,42 @@
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ('patchwork', '0047_add_database_indexes'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='series',
+            name='dependencies',
+            field=models.ManyToManyField(
+                blank=True,
+                help_text='Optional dependencies on this patch.',
+                related_name='dependents',
+                related_query_name='dependent',
+                to='patchwork.series',
+            ),
+        ),
+        migrations.AddField(
+            model_name='project',
+            name='show_dependencies',
+            field=models.BooleanField(
+                default=False,
+                help_text='Enable dependency tracking for patches and cover '
+                'letters.',
+            ),
+        ),
+        migrations.AlterField(
+            model_name='series',
+            name='cover_letter',
+            field=models.OneToOneField(
+                blank=True,
+                null=True,
+                on_delete=django.db.models.deletion.CASCADE,
+                related_name='series',
+                to='patchwork.cover',
+            ),
+        ),
+    ]
index b67d11382b8ed03861216054058bc7643a5eddab..ae2f4a6dcbaad3f0332c507568ce44ba1c5ae75f 100644 (file)
@@ -100,6 +100,10 @@ class Project(models.Model):
     # configuration options
 
     send_notifications = models.BooleanField(default=False)
+    show_dependencies = models.BooleanField(
+        default=False,
+        help_text='Enable dependency tracking for patches and cover letters.',
+    )
     use_tags = models.BooleanField(default=True)
 
     def is_editable(self, user):
@@ -837,7 +841,21 @@ class Series(FilenameMixin, models.Model):
 
     # content
     cover_letter = models.OneToOneField(
-        Cover, related_name='series', null=True, on_delete=models.CASCADE
+        Cover,
+        related_name='series',
+        null=True,
+        blank=True,
+        on_delete=models.CASCADE,
+    )
+
+    # dependencies
+    dependencies = models.ManyToManyField(
+        'self',
+        symmetrical=False,
+        blank=True,
+        help_text='Optional dependencies on this patch.',
+        related_name='dependents',
+        related_query_name='dependent',
     )
 
     # metadata
@@ -879,6 +897,22 @@ class Series(FilenameMixin, models.Model):
     def received_all(self):
         return self.total <= self.received_total
 
+    def add_dependencies(self, dependencies):
+        """Add dependencies to this series.
+
+        Helper method to add any found dependencies to this series.
+        The method will filter out self and any series not from the
+        same project.
+        """
+        self.dependencies.add(
+            *(
+                dep
+                for dep in dependencies
+                if dep.id != self.id and dep.project == self.project
+            )
+        )
+        self.save()
+
     def add_cover_letter(self, cover):
         """Add a cover letter to the series.