From nobody Fri Apr 26 05:21:53 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 1527016430269616.1539681928977; Tue, 22 May 2018 12:13:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1FF3B3002F27; Tue, 22 May 2018 19:13:49 +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 11D6C3001933; Tue, 22 May 2018 19:13:49 +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 05C3D4CA80; Tue, 22 May 2018 19:13:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4MJDli4017644 for ; Tue, 22 May 2018 15:13:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id D151F308BDA1; Tue, 22 May 2018 19:13:47 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C9EBF308BDA0 for ; Tue, 22 May 2018 19:13:45 +0000 (UTC) Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) (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 B7AB630C4AD9 for ; Tue, 22 May 2018 19:13:34 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id c41-v6so11450529plj.10 for ; Tue, 22 May 2018 12:13:34 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.149]) by smtp.gmail.com with ESMTPSA id j5-v6sm42719269pfe.119.2018.05.22.12.13.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 12:13:32 -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=yPrkryIYIJ/cCs+m4J/2A0nXHf65GwEGzJhSpqyfGNg=; b=dC6u1bZbKBkMxRH0hooovEh5CH8X3gLjzf0WuB+X66pqtMTR1gMuPK8l9UQPOcqbEC hhPIJC9S8ZWnhzapCeHQfQb6yjFkTBksn18XAEErDZtW5SnKz6eR5pWbxj3qqQs1UfuU fQ7FExT/pLpjeCEU4n5BnIRjjIBrysd5CCFf3OQInolBBLsJxxGWnAVl1mhRFl3qbSTj +ol1pgkcQcJRpw+A/BPSXvBLqL3LDOYaZ3PksrLsso8XFBok+43DK8o69MAt1XZEjJGS Bwq9aPR2aDQqe4x9mo9/T053F10vuQ2SYWpefHMyQDImFU5ziVA75fQhwa7NMAPy6h6e LrfQ== 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=yPrkryIYIJ/cCs+m4J/2A0nXHf65GwEGzJhSpqyfGNg=; b=QHRA2spbliH/ASwZGka3HxCRY0m4VWhIzSLK0vzHDSQZ6IJIASTp5sNLJBmxU87cqA gq4TIMunpc1VszYe0CKrAVXMhSUYsIXRfdWQfBryq3CtuM+tcSbH5+nwIpdJokQxeZvY Gnn0syxB1zLYb/xAXZL4CGfrGizqCAmbC+nXucCoCme3FXBsAk911O14w068ZZYMvdPG aSepD5nof/q+FYKYTbYnekDWHdtseqcN3plhWCS+7SuqYWbIb/+m1bjL9iuZvGM1Uxoj vZSNQZb7aKNjDb+VdLPhhwWnnbPPCeYz+X7ttoL9wr1P5Y78aQwSt98rhr+lx0zZ1QyQ svBA== X-Gm-Message-State: ALKqPwfsQx9PvF13seOwI/XFC2oKDco5emHTJL24Cde6umrJ65oDtWTP nIVDWr3eX247Pk7KJpPSOO6pcg== X-Google-Smtp-Source: AB8JxZpXJBnvAErgpcQ665SRyeAeqn9nE0fPDgKsZ4Rfaa3pVR/bCuFhCzASiHuXa1FGXqK/hH2c7g== X-Received: by 2002:a17:902:b409:: with SMTP id x9-v6mr26591401plr.180.1527016413695; Tue, 22 May 2018 12:13:33 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Wed, 23 May 2018 00:43:21 +0530 Message-Id: <20180522191321.28691-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 22 May 2018 19:13:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 22 May 2018 19:13:34 +0000 (UTC) for IP:'209.85.160.67' DOMAIN:'mail-pl0-f67.google.com' HELO:'mail-pl0-f67.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) 209.85.160.67 mail-pl0-f67.google.com 209.85.160.67 mail-pl0-f67.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH] 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 22 May 2018 19:13:49 +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 | 42 ++++++++++++++++++++++++++++++++++++++++++ api/views.py | 25 +------------------------ 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/api/models.py b/api/models.py index d602cb7..be1e2be 100644 --- a/api/models.py +++ b/api/models.py @@ -44,6 +44,33 @@ def load_blob_json(name): logging.error('Failed to load blob %s: %s' %(name, e)) return None =20 +def get_series_to_be_updated(project_name, message_ids): + updated_series =3D [] + for msgid in message_ids: + if msgid.startswith("<") and msgid.endswith(">"): + msgid =3D msgid[1:-1] + p =3D Project.objects.get(name=3Dproject_name) + mo =3D Message.objects.filter(project=3Dp, message_id=3Dmsgid, + 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) + return updated_series + +def change_merge_status(series): + merged =3D True + for p in series.get_patches(): + if not p.is_merged: + merged =3D False + break + if merged: + series.is_merged =3D True + series.save() + class Project(models.Model): name =3D models.CharField(max_length=3D1024, db_index=3DTrue, unique= =3DTrue, help_text=3D"""The name of the project""") @@ -171,6 +198,21 @@ 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") + + project_head =3D property(get_project_head) + + def series_update(self, message_ids): + series_to_be_updated =3D get_series_to_be_updated(self.name, messa= ge_ids) + ret =3D len(series_to_be_updated) + for s in series_to_be_updated: + change_merge_status(s) + return ret + + def set_project_head(self, new_head): + self.set_property("git.head", new_head) + 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..4cb10c1 100644 --- a/api/views.py +++ b/api/views.py @@ -123,30 +123,7 @@ class UpdateProjectHeadView(APILoginRequiredView): old_head_0 =3D po.get_property("git.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() + ret =3D po.series_update(message_ids) po.set_property("git.head", new_head) return ret =20 --=20 2.14.3 (Apple Git-98) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel