From nobody Tue May 13 13:04:09 2025 Delivered-To: importer2@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557925125; cv=none; d=zoho.com; s=zohoarc; b=BhSh2RebkvUrtYkcRmNG+xOiw1Q+JRK8xQylfPQ1W6xLGoENGq5YcKDFRI5HklseAarq03Ac2YjkDO9tMOvWH9iLTlGhGFLgQoseUtnacXAuwuPt1TGO9Ulf6WVxGkO+Bm/26J/260jc6zbaomX/hojcVy01prc5lgFx/L2TJQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925125; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=oQtmXUxrdh7udkQFVBUJ5RfWL+dp///eyT1a8txQyEA=; b=HgdcK6nKg3303W1D8pneVPHQgiFfUi9pwu5Oz+rtWffGzpj8Zzj844Bi/Ei7iLnmQ1xww1loNsBA4lTPex39dpKl1ImK3F23cG1YHEZOxv7fxcLxmKZnlDbSz/WsIgJIfNpJYn4CXZkUX7lQXzDMX2vV2C1l5/BS7IUB4s/kXdc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557925125611851.2416703645865; Wed, 15 May 2019 05:58:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6DEF83003B36; Wed, 15 May 2019 12:58:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61A415D70A; Wed, 15 May 2019 12:58:44 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 54A724BB45; Wed, 15 May 2019 12:58:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4FCwgSd012688 for ; Wed, 15 May 2019 08:58:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id EF13060F81; Wed, 15 May 2019 12:58:42 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-34.ams2.redhat.com [10.36.112.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E09760CDA for ; Wed, 15 May 2019 12:58:39 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:03 +0200 Message-Id: <20190515125808.27716-7-pbonzini@redhat.com> In-Reply-To: <20190515125808.27716-1-pbonzini@redhat.com> References: <20190515125808.27716-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 06/11] git: reimplement applier-get under /api/v1/series X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 15 May 2019 12:58:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" --- 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 =20 from . import views from . import rest +from mod import dispatch_module_hook =20 =20 def _build_urls(base=3DNone, r=3D[]): @@ -49,7 +50,9 @@ results_router.register('results', rest.SeriesResultsView= Set, base_name=3D'results =20 schema_view =3D get_schema_view(title=3D'API schema') =20 -urlpatterns =3D _build_urls() + [ +urlpatterns =3D _build_urls() +dispatch_module_hook("api_url_hook", urlpatterns=3Durlpatterns) +urlpatterns +=3D [ url(r'^v1/projects/by-name/(?P[^/]*)(?P/.*|$)', rest.Proje= ctsByNameView.as_view()), url(r'^v1/users/login/$', LoginView.as_view(), name=3D'rest_login'), url(r'^v1/users/logout/$', LogoutView.as_view(), name=3D'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 =20 _instance =3D None =20 @@ -239,11 +239,12 @@ class GitModule(PatchewModule): GitLogViewer.as_view(), name=3D"git-log")) =20 -class ApplierGetView(APILoginRequiredView): - name =3D "applier-get" - allowed_groups =3D ["importers"] + def api_url_hook(self, urlpatterns): + urlpatterns.append(url(r"^v1/series/unapplied/$", + UnappliedSeriesView.as_view(), + name=3D"unapplied")) =20 - def handle(self, request, target_repo=3DNone): + def pending_series(self, target_repo): q =3D Message.objects.filter(results__name=3D"git", results__statu= s=3D"pending") if target_repo is not None and target_repo !=3D '': # Postgres could use JSON fields instead. Fortunately project= s are @@ -260,7 +261,14 @@ class ApplierGetView(APILoginRequiredView): projects =3D Project.objects.values_list('id', 'config').all() projects =3D [pid for pid, config in projects if match_target_= repo(config, target_repo)] q =3D q.filter(project__pk__in=3Dprojects) - m =3D q.first() + return q + +class ApplierGetView(APILoginRequiredView): + name =3D "applier-get" + allowed_groups =3D ["importers"] + + def handle(self, request, target_repo=3DNone): + m =3D _instance.pending_series(target_repo).first() if not m: return None =20 @@ -285,6 +293,32 @@ class ApplierGetView(APILoginRequiredView): response["result_uri"] =3D reverse_detail(m.git_result, request) return response =20 + +class UnappliedSeriesSerializer(SeriesSerializer): + class Meta: + model =3D Message + fields =3D SeriesSerializer.Meta.fields + ('mirror', 'result_uri') + + mirror =3D SerializerMethodField() + result_uri =3D SerializerMethodField() + + def get_result_uri(self, obj): + request =3D self.context['request'] + return reverse_detail(obj.git_result, request) + + def get_mirror(self, obj): + request =3D self.context['request'] + mirror =3D _instance.get_mirror(obj.project, request, None) + mirror['source'] =3D obj.project.git + return mirror + +class UnappliedSeriesView(generics.ListAPIView): + name =3D "unapplied" + serializer_class =3D UnappliedSeriesSerializer + + def get_queryset(self, target_repo=3DNone): + return _instance.pending_series(target_repo) + class ApplierReportView(APILoginRequiredView): name =3D "applier-report" allowed_groups =3D ["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']) =20 + 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=3Dself.user, password=3Dself.passwo= rd) + self.api_client.put(self.PROJECT_BASE + 'series/20160628014747.209= 71-1-famz@redhat.com/results/git/', + { 'status': 'success' }) + resp =3D 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'], '14691920= 15-16487-1-git-send-email-berrange@redhat.com') + self.do_apply() + resp =3D self.api_client.get(self.REST_BASE + 'series/unapplied/') + self.assertEqual(resp.status_code, 200) + self.assertEquals(len(resp.data['results']), 0) + =20 if __name__ =3D=3D '__main__': main() --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel