---
api/urls.py | 5 ++++-
mods/git.py | 50 +++++++++++++++++++++++++++++++++++++++--------
tests/test_git.py | 15 ++++++++++++++
3 files changed, 61 insertions(+), 9 deletions(-)
diff --git a/api/urls.py b/api/urls.py
index 2383f2a..c44e3ce 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -17,6 +17,7 @@ from rest_framework.schemas import get_schema_view
from . import views
from . import rest
+from mod import dispatch_module_hook
def _build_urls(base=None, r=[]):
@@ -49,7 +50,9 @@ results_router.register('results', rest.SeriesResultsViewSet, base_name='results
schema_view = get_schema_view(title='API schema')
-urlpatterns = _build_urls() + [
+urlpatterns = _build_urls()
+dispatch_module_hook("api_url_hook", urlpatterns=urlpatterns)
+urlpatterns += [
url(r'^v1/projects/by-name/(?P<name>[^/]*)(?P<tail>/.*|$)', rest.ProjectsByNameView.as_view()),
url(r'^v1/users/login/$', LoginView.as_view(), name='rest_login'),
url(r'^v1/users/logout/$', LogoutView.as_view(), name='rest_logout'),
diff --git a/mods/git.py b/mods/git.py
index 42a932e..78939b8 100644
--- a/mods/git.py
+++ b/mods/git.py
@@ -22,12 +22,12 @@ from django.db.models import Q
from mod import PatchewModule
from event import declare_event, register_handler, emit_event
from api.models import (Message, Project, Result)
-from api.rest import PluginMethodField, reverse_detail
+from api.rest import PluginMethodField, SeriesSerializer, reverse_detail
from api.views import APILoginRequiredView, prepare_series
from patchew.logviewer import LogView
from schema import *
-from rest_framework import serializers
-from rest_framework.fields import CharField
+from rest_framework import generics, mixins, serializers
+from rest_framework.fields import CharField, SerializerMethodField
_instance = None
@@ -239,11 +239,12 @@ class GitModule(PatchewModule):
GitLogViewer.as_view(),
name="git-log"))
-class ApplierGetView(APILoginRequiredView):
- name = "applier-get"
- allowed_groups = ["importers"]
+ def api_url_hook(self, urlpatterns):
+ urlpatterns.append(url(r"^v1/series/unapplied/$",
+ UnappliedSeriesView.as_view(),
+ name="unapplied"))
- def handle(self, request, target_repo=None):
+ def pending_series(self, target_repo):
q = Message.objects.filter(results__name="git", results__status="pending")
if target_repo is not None and target_repo != '':
# Postgres could use JSON fields instead. Fortunately projects are
@@ -260,7 +261,14 @@ class ApplierGetView(APILoginRequiredView):
projects = Project.objects.values_list('id', 'config').all()
projects = [pid for pid, config in projects if match_target_repo(config, target_repo)]
q = q.filter(project__pk__in=projects)
- m = q.first()
+ return q
+
+class ApplierGetView(APILoginRequiredView):
+ name = "applier-get"
+ allowed_groups = ["importers"]
+
+ def handle(self, request, target_repo=None):
+ m = _instance.pending_series(target_repo).first()
if not m:
return None
@@ -285,6 +293,32 @@ class ApplierGetView(APILoginRequiredView):
response["result_uri"] = reverse_detail(m.git_result, request)
return response
+
+class UnappliedSeriesSerializer(SeriesSerializer):
+ class Meta:
+ model = Message
+ fields = SeriesSerializer.Meta.fields + ('mirror', 'result_uri')
+
+ mirror = SerializerMethodField()
+ result_uri = SerializerMethodField()
+
+ def get_result_uri(self, obj):
+ request = self.context['request']
+ return reverse_detail(obj.git_result, request)
+
+ def get_mirror(self, obj):
+ request = self.context['request']
+ mirror = _instance.get_mirror(obj.project, request, None)
+ mirror['source'] = obj.project.git
+ return mirror
+
+class UnappliedSeriesView(generics.ListAPIView):
+ name = "unapplied"
+ serializer_class = UnappliedSeriesSerializer
+
+ def get_queryset(self, target_repo=None):
+ return _instance.pending_series(target_repo)
+
class ApplierReportView(APILoginRequiredView):
name = "applier-report"
allowed_groups = ["importers"]
diff --git a/tests/test_git.py b/tests/test_git.py
index 0b9fa50..e99755f 100755
--- a/tests/test_git.py
+++ b/tests/test_git.py
@@ -144,6 +144,21 @@ class GitTest(PatchewTestCase):
self.assertEqual(log.status_code, 200)
self.assertEqual(log.content.decode(), resp.data['log'])
+ def test_rest_unapplied(self):
+ self.cli_import('0004-multiple-patch-reviewed.mbox.gz')
+ self.cli_import('0001-simple-patch.mbox.gz')
+ self.api_client.login(username=self.user, password=self.password)
+ self.api_client.put(self.PROJECT_BASE + 'series/20160628014747.20971-1-famz@redhat.com/results/git/',
+ { 'status': 'success' })
+ resp = self.api_client.get(self.REST_BASE + 'series/unapplied/')
+ self.assertEqual(resp.status_code, 200)
+ self.assertEquals(len(resp.data['results']), 1)
+ self.assertEquals(resp.data['results'][0]['message_id'], '1469192015-16487-1-git-send-email-berrange@redhat.com')
+ self.do_apply()
+ resp = self.api_client.get(self.REST_BASE + 'series/unapplied/')
+ self.assertEqual(resp.status_code, 200)
+ self.assertEquals(len(resp.data['results']), 0)
+
if __name__ == '__main__':
main()
--
2.21.0
_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel