From nobody Fri Apr 26 16:44:12 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; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527103384509650.6909773947119; Wed, 23 May 2018 12:23:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85F77358400; Wed, 23 May 2018 19:23:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 721EE5C3FA; Wed, 23 May 2018 19:23:03 +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 2F9A018033EE; Wed, 23 May 2018 19:23:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4NJGYNU011065 for ; Wed, 23 May 2018 15:16:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5394C1057FA4; Wed, 23 May 2018 19:16:34 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B4A21062242 for ; Wed, 23 May 2018 19:16:32 +0000 (UTC) Received: from mail-pg0-f68.google.com (mail-pg0-f68.google.com [74.125.83.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7FAE09DDF2 for ; Wed, 23 May 2018 19:16:21 +0000 (UTC) Received: by mail-pg0-f68.google.com with SMTP id k2-v6so9855615pgc.1 for ; Wed, 23 May 2018 12:16:21 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.149]) by smtp.gmail.com with ESMTPSA id b5-v6sm26478951pgc.16.2018.05.23.12.16.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 12:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=SE2NgRopIKLk3TW0I1d7gJousor6qa74qcRZ0QOLjuk=; b=WlOH1VBt6SL946VU+z+2kq2vbnKKdY4qUArmvUr9cs1ENO3b9f7s1F5UaT4dpy1e94 q7b0x9Zxgj0kcXksog8UlcxNnjmlFuHoWzqC/x/lpmdx8ZqlaHG9VVsUJcsyNTczpUPP jmcX758T8Fu9AXRwZcfk/rZhoDV08tox0O+SO9mlNGGKDrNSpkjeMRFcsDjZv/6KoJwl 4SC0pbFv7wvqYSk1QkCTNAQDqPZFZzVbBvHzOw1Wfe0AMBnER+UcUkDcQBt/Y8yMqb9q lp6dgs9Fm28QRocT9jbTkWuMIHbfXow6BI2lT24shsO0tSJT8bAZPbO8KD4n8WERi+tI WT+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SE2NgRopIKLk3TW0I1d7gJousor6qa74qcRZ0QOLjuk=; b=poklN7eGjyvuIxMxZLm7UoQd5H54pGG+07irqyMKpHSPiGkGqyBb7osC5KPVvUwm8V 43Ym5/pTbxJPXhhtmygl5Vj4wRfuDp8YXgpmk2VVGl0lQDeei65RiCrDpto27y+shAbI f/99SRYnTxNBKgcfFwaJzRZiGFycSbQ/cn8FJqK9u0pYwxtPBqHX90f6yMSDKXpNKRo6 Ps6+uYaxHkO/3xfk0wTADZi2nW0DOJ1qFHkYWu3w6DdQWcJykBRnG2Dri4XuiBseiCii aKs3JppzADHrj8SeIEhyeD/2oiPKNGggodTAHOqFI2Qmz/hoS53BCBt3N39btlHbjF+u kXtg== X-Gm-Message-State: ALKqPweGN9ehPf2DBNPY8q/unTatf1srN6nMUn5W4rwtq2cQ+jD5VAH2 mbr+0nLnh4fcIECgIdRkQJ62PA== X-Google-Smtp-Source: AB8JxZpUprqU/CRSVy73RxqeDcLXoLXd6egjUTWtwehuYPayqaYmHFSwHyDvDDYx9gPK7O6Bsli2kQ== X-Received: by 2002:a63:8dca:: with SMTP id z193-v6mr3253739pgd.418.1527102980277; Wed, 23 May 2018 12:16:20 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Thu, 24 May 2018 00:46:07 +0530 Message-Id: <20180523191607.34465-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 23 May 2018 19:16:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 23 May 2018 19:16:21 +0000 (UTC) for IP:'74.125.83.68' DOMAIN:'mail-pg0-f68.google.com' HELO:'mail-pg0-f68.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.531 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 74.125.83.68 mail-pg0-f68.google.com 74.125.83.68 mail-pg0-f68.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v2] Refactoring of UpdateProjectHeadView.handle() 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 23 May 2018 19:23:03 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" moved and refactored the UpdateProjectHeadView.handle() into method of api.= models.Project so that it can be re-used in rest conversion of update-proje= ct-head --- api/models.py | 31 +++++++++++++++++++++++++++++++ api/views.py | 29 +++-------------------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/api/models.py b/api/models.py index d602cb7..1a51a6d 100644 --- a/api/models.py +++ b/api/models.py @@ -171,6 +171,37 @@ class Project(models.Model): def get_subprojects(self): return Project.objects.filter(parent_project=3Dself) =20 + def get_project_head(self): + return self.get_property("git.head") + + def set_project_head(self, new_head): + self.set_property("git.head", new_head) + + project_head =3D property(get_project_head,set_project_head) + + def series_update(self, message_ids): + updated_series =3D [] + for msgid in message_ids: + if msgid.startswith("<") and msgid.endswith(">"): + msgid =3D msgid[1:-1] + mo =3D Message.objects.filter(project=3Dself, message_id=3Dmsg= id, + is_merged=3DFalse).first() + if not mo: + continue + mo.is_merged =3D True + mo.save() + s =3D mo.get_series_head() + if s: + updated_series.append(s) + for s in updated_series: + for p in series.get_patches(): + if not p.is_merged: + break + else: + series.is_merged =3D True + series.save() + return len(updated_series) + class ProjectProperty(models.Model): project =3D models.ForeignKey('Project', on_delete=3Dmodels.CASCADE) name =3D models.CharField(max_length=3D1024, db_index=3DTrue) diff --git a/api/views.py b/api/views.py index c27cd5a..7a37481 100644 --- a/api/views.py +++ b/api/views.py @@ -120,34 +120,11 @@ class UpdateProjectHeadView(APILoginRequiredView): =20 def handle(self, request, project, old_head, new_head, message_ids): po =3D Project.objects.get(name=3Dproject) - old_head_0 =3D po.get_property("git.head") + old_head_0 =3D po.project_head if old_head_0 and old_head_0 !=3D old_head: raise Exception("wrong old head") - ret =3D 0 - updated_series =3D [] - for msgid in message_ids: - if msgid.startswith("<") and msgid.endswith(">"): - msgid =3D msgid[1:-1] - mo =3D Message.objects.filter(project=3Dpo, message_id=3Dmsgid, - is_merged=3DFalse).first() - if not mo: - continue - ret +=3D 1 - mo.is_merged =3D True - mo.save() - s =3D mo.get_series_head() - if s: - updated_series.append(s) - for s in updated_series: - merged =3D True - for p in s.get_patches(): - if not p.is_merged: - merged =3D False - break - if merged: - s.is_merged =3D True - s.save() - po.set_property("git.head", new_head) + ret =3D po.series_update(message_ids) + po.project_head =3D new_head return ret =20 class SetPropertyView(APILoginRequiredView): --=20 2.14.3 (Apple Git-98) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel