From nobody Mon Apr 29 06:29:32 2024 Delivered-To: importer@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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526913905609108.50793381587141; Mon, 21 May 2018 07:45:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54390AE68D; Mon, 21 May 2018 14:45:04 +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 442D4977A1; Mon, 21 May 2018 14:45:04 +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 2B49F4BB78; Mon, 21 May 2018 14:45:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4LEj1YJ016059 for ; Mon, 21 May 2018 10:45:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7C8D52024CCD; Mon, 21 May 2018 14:45:01 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-54.ams2.redhat.com [10.36.116.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADB7A2024CC7 for ; Mon, 21 May 2018 14:45:00 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Mon, 21 May 2018 16:44:58 +0200 Message-Id: <20180521144458.32564-2-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH] git: return Based-on information from REST API 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 21 May 2018 14:45:04 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The base git repository is returned by the legacy API but not by the REST API. Add a new PluginMethodField to retrieve it, and include it in the Result data after a git tree has been created for a series. Signed-off-by: Paolo Bonzini Reviewed-by: Fam Zheng --- mods/git.py | 40 ++++++++++++++++++++++++++++++---------- tests/test_git.py | 11 +++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/mods/git.py b/mods/git.py index 7d8afbb..fe10423 100644 --- a/mods/git.py +++ b/mods/git.py @@ -19,6 +19,7 @@ from django.utils.html import format_html from mod import PatchewModule from event import declare_event, register_handler, emit_event from api.models import Message, MessageProperty, Result +from api.rest import PluginMethodField from api.views import APILoginRequiredView, prepare_series from patchew.logviewer import LogView from schema import * @@ -111,6 +112,20 @@ class GitModule(PatchewModule): raise Exception("Project git repo invalid: %s" % project_git) return upstream, branch =20 + def get_based_on(self, message, request, format): + git_base =3D self.get_base(message) + if not git_base: + return None + + return { + "repo": git_base.get_property("git.repo"), + "tag": 'refs/tags/' + git_base.get_property("git.tag") + } + + + def rest_series_fields_hook(self, request, fields, detailed): + fields['based_on'] =3D PluginMethodField(obj=3Dself, required=3DFa= lse) + def rest_results_hook(self, request, obj, results, detailed=3DFalse): if not isinstance(obj, Message): return @@ -123,12 +138,15 @@ class GitModule(PatchewModule): git_repo =3D obj.get_property("git.repo") git_tag =3D obj.get_property("git.tag") git_url =3D obj.get_property("git.url") + git_base =3D obj.get_property("git.base") data =3D {} if git_repo and git_tag: data['repo'] =3D git_repo data['tag'] =3D 'refs/tags/' + git_tag if git_url: data['url'] =3D git_url + if git_base: + data['base'] =3D git_base status =3D Result.SUCCESS log_url =3D reverse("git-log", kwargs=3D{'series': obj.message= _id}) else: @@ -208,11 +226,7 @@ class GitModule(PatchewModule): "content_html": self.build_config_html(= request, = project)}) =20 - def prepare_series_hook(self, request, series, response): - po =3D series.project - for prop in ["git.push_to", "git.public_repo", "git.url_template"]: - if po.get_property(prop): - response[prop] =3D po.get_property(prop) + def get_base(self, series): for tag in series.get_property("tags", []): if not tag.startswith("Based-on:"): continue @@ -220,14 +234,20 @@ class GitModule(PatchewModule): if base_id.startswith("<") and base_id.endswith(">"): base_id =3D base_id[1:-1] base =3D Message.objects.series_heads().\ - filter(project=3Dpo, message_id=3Dbase_id).first() + filter(project=3Dseries.project, message_id=3Dbase_id)= .first() if not base: - break - if not base.get_property("git.repo"): - break + return None + return base if base.get_property("git.repo") else None + + def prepare_series_hook(self, request, series, response): + po =3D series.project + for prop in ["git.push_to", "git.public_repo", "git.url_template"]: + if po.get_property(prop): + response[prop] =3D po.get_property(prop) + base =3D self.get_base(series) + if base: response["git.repo"] =3D base.get_property("git.repo") response["git.base"] =3D base.get_property("git.tag") - break =20 def _poll_project(self, po): repo, branch =3D self._get_project_repo_and_branch(po) diff --git a/tests/test_git.py b/tests/test_git.py index 04ac1ef..d64f901 100755 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -101,6 +101,17 @@ class GitTest(PatchewTestCase): self.assertEqual(resp.data['log_url'], None) self.assertEqual(resp.data['log'], None) =20 + def test_rest_git_base(self): + self.cli_import("0013-foo-patch.mbox.gz") + self.do_apply() + s =3D Message.objects.series_heads()[0] + self.cli_import("0014-bar-patch.mbox.gz") + MESSAGE_ID =3D '20160628014747.20971-2-famz@redhat.com' + resp =3D self.api_client.get('%sseries/%s/' % (self.PROJECT_BASE, = MESSAGE_ID)) + self.assertEqual(resp.data['is_complete'], True) + self.assertEqual(resp.data['based_on']['repo'], self.repo) + self.assertEqual(resp.data['based_on']['tag'], 'refs/tags/patchew/= 20160628014747.20971-1-famz@redhat.com') + def test_rest_apply_failure(self): self.cli_import("0014-bar-patch.mbox.gz") self.do_apply() --=20 2.17.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel