From: Fam Zheng <famz@redhat.com>
Git ResultUpdate is a good point to run the watched queries, because
maintainers fiels is populated here.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
api/search.py | 6 ++++++
mods/maintainer.py | 19 +++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/api/search.py b/api/search.py
index 3067235..a15d238 100644
--- a/api/search.py
+++ b/api/search.py
@@ -369,3 +369,9 @@ Search text keyword in the email message. Example:
self._last_keywords, q)
return queryset.filter(q)
+
+ def query_test_message(self, query, message):
+ queryset = Message.objects.filter(id=message.id)
+ terms = [x.strip() for x in query.split() if x.strip()]
+ return self.search_series(*terms, queryset=queryset).first()
+
diff --git a/mods/maintainer.py b/mods/maintainer.py
index 54738ec..60ed4c4 100644
--- a/mods/maintainer.py
+++ b/mods/maintainer.py
@@ -14,12 +14,17 @@ from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest
from django.urls import reverse
from mod import PatchewModule
from api.models import Message, Queue, WatchedQuery
+from api.search import SearchEngine
+from event import register_handler
class MaintainerModule(PatchewModule):
""" Project maintainer related tasks """
name = "maintainer"
+ def __init__(self):
+ register_handler("ResultUpdate", self.on_result_update)
+
def _add_to_queue(self, user, m, queue):
for x in [m] + list(m.get_patches()):
Queue.objects.get_or_create(user=user, message=x, name=queue)
@@ -29,6 +34,20 @@ class MaintainerModule(PatchewModule):
name=queue)
q.delete()
+ def _update_watch_queue(self, series):
+ se = SearchEngine()
+ for wq in WatchedQuery.objects.all():
+ if se.query_test_message(wq.query, series):
+ self._add_to_queue(wq.user, series, "watched")
+
+ def on_result_update(self, evt, obj, old_status, result):
+ if not isinstance(obj, Message):
+ return
+ if result == obj.git_result and result.status != result.PENDING:
+ # By the time of git result update we should have calculated
+ # maintainers so redo the watched queue
+ self._update_watch_queue(obj)
+
def _update_review_state(self, request, message_id, accept):
if not request.user.is_authenticated:
return HttpResponseForbidden()
--
2.17.2
_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel