[patch 1/1] models: add "comment added to patch" event
DJ Delorie
dj at redhat.com
Fri Feb 25 07:25:55 AEDT 2022
This small patch stitches in "comment added" events into the event
queue.
Signed-off-by: DJ Delorie <dj at redhat.com>
Closes: #424
diff --git a/patchwork/api/event.py b/patchwork/api/event.py
index 71f9593..45b3f4f 100644
--- a/patchwork/api/event.py
+++ b/patchwork/api/event.py
@@ -13,6 +13,7 @@ from rest_framework.serializers import SlugRelatedField
from patchwork.api.embedded import CheckSerializer
from patchwork.api.embedded import CoverSerializer
from patchwork.api.embedded import PatchSerializer
+from patchwork.api.comment import PatchCommentSerializer
from patchwork.api.embedded import ProjectSerializer
from patchwork.api.embedded import SeriesSerializer
from patchwork.api.embedded import UserSerializer
@@ -31,6 +32,7 @@ class EventSerializer(ModelSerializer):
current_state = SlugRelatedField(slug_field='slug', read_only=True)
previous_delegate = UserSerializer()
current_delegate = UserSerializer()
+ comment_added = PatchCommentSerializer()
created_check = SerializerMethodField()
created_check = CheckSerializer()
previous_relation = SerializerMethodField()
@@ -40,6 +42,7 @@ class EventSerializer(ModelSerializer):
Event.CATEGORY_COVER_CREATED: ['cover'],
Event.CATEGORY_PATCH_CREATED: ['patch'],
Event.CATEGORY_PATCH_COMPLETED: ['patch', 'series'],
+ Event.CATEGORY_PATCH_COMMENT_ADDED: ['patch', 'comment_added'],
Event.CATEGORY_PATCH_STATE_CHANGED: ['patch', 'previous_state',
'current_state'],
Event.CATEGORY_PATCH_DELEGATED: ['patch', 'previous_delegate',
@@ -80,7 +83,7 @@ class EventSerializer(ModelSerializer):
'id', 'category', 'project', 'date', 'actor', 'patch',
'series', 'cover', 'previous_state', 'current_state',
'previous_delegate', 'current_delegate', 'created_check',
- 'previous_relation', 'current_relation',
+ 'previous_relation', 'current_relation', 'comment_added',
)
read_only_fields = fields
versioned_fields = {
@@ -102,4 +105,4 @@ class EventList(ListAPIView):
.prefetch_related('project', 'patch__project', 'series__project',
'cover', 'previous_state', 'current_state',
'previous_delegate', 'current_delegate',
- 'created_check')
+ 'created_check', 'comment_added')
diff --git a/patchwork/migrations/0046_patch_comment_events.py b/patchwork/migrations/0046_patch_comment_events.py
new file mode 100644
index 0000000..6d1a798
--- /dev/null
+++ b/patchwork/migrations/0046_patch_comment_events.py
@@ -0,0 +1,24 @@
+# Generated by Django 3.1.13 on 2022-02-25 07:01
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('patchwork', '0045_addressed_fields'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='event',
+ name='comment_added',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='patchwork.patchcomment'),
+ ),
+ migrations.AlterField(
+ model_name='event',
+ name='category',
+ field=models.CharField(choices=[('cover-created', 'Cover Letter Created'), ('patch-created', 'Patch Created'), ('patch-completed', 'Patch Completed'), ('patch-comment-added', 'Patch Comment Added'), ('patch-state-changed', 'Patch State Changed'), ('patch-delegated', 'Patch Delegate Changed'), ('patch-relation-changed', 'Patch Relation Changed'), ('check-created', 'Check Created'), ('series-created', 'Series Created'), ('series-completed', 'Series Completed')], db_index=True, help_text='The category of the event.', max_length=25),
+ ),
+ ]
diff --git a/patchwork/models.py b/patchwork/models.py
index 6304b34..74229de 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -1022,6 +1022,7 @@ class Event(models.Model):
CATEGORY_COVER_CREATED = 'cover-created'
CATEGORY_PATCH_CREATED = 'patch-created'
CATEGORY_PATCH_COMPLETED = 'patch-completed'
+ CATEGORY_PATCH_COMMENT_ADDED = 'patch-comment-added'
CATEGORY_PATCH_STATE_CHANGED = 'patch-state-changed'
CATEGORY_PATCH_DELEGATED = 'patch-delegated'
CATEGORY_PATCH_RELATION_CHANGED = 'patch-relation-changed'
@@ -1032,6 +1033,7 @@ class Event(models.Model):
(CATEGORY_COVER_CREATED, 'Cover Letter Created'),
(CATEGORY_PATCH_CREATED, 'Patch Created'),
(CATEGORY_PATCH_COMPLETED, 'Patch Completed'),
+ (CATEGORY_PATCH_COMMENT_ADDED, 'Patch Comment Added'),
(CATEGORY_PATCH_STATE_CHANGED, 'Patch State Changed'),
(CATEGORY_PATCH_DELEGATED, 'Patch Delegate Changed'),
(CATEGORY_PATCH_RELATION_CHANGED, 'Patch Relation Changed'),
@@ -1113,6 +1115,12 @@ class Event(models.Model):
Check, related_name='+', null=True, blank=True,
on_delete=models.CASCADE)
+ # fields for 'patch-comment-added' events
+
+ comment_added = models.ForeignKey(
+ PatchComment, related_name='+', null=True, blank=True,
+ on_delete=models.CASCADE)
+
# TODO(stephenfin): Validate that the correct fields are being set by way
# of a 'clean' method
diff --git a/patchwork/signals.py b/patchwork/signals.py
index dc08129..4697993 100644
--- a/patchwork/signals.py
+++ b/patchwork/signals.py
@@ -15,7 +15,7 @@ from patchwork.models import Event
from patchwork.models import Patch
from patchwork.models import PatchChangeNotification
from patchwork.models import Series
-
+from patchwork.models import PatchComment
@receiver(pre_save, sender=Patch)
def patch_change_callback(sender, instance, raw, **kwargs):
@@ -53,6 +53,18 @@ def patch_change_callback(sender, instance, raw, **kwargs):
notification.last_modified = dt.utcnow()
notification.save()
+ at receiver(post_save, sender=PatchComment)
+def create_patch_comment_created_callback(sender, instance, raw, **kwargs):
+
+ def create_event(comment):
+ return Event.objects.create(
+ category=Event.CATEGORY_PATCH_COMMENT_ADDED,
+ project=comment.patch.project,
+ patch=comment.patch,
+ comment_added=comment)
+
+ create_event(instance)
+
@receiver(post_save, sender=Cover)
def create_cover_created_event(sender, instance, created, raw, **kwargs):
More information about the Patchwork
mailing list