[ews-app] Add methods to update Patch fields
authoraakash_jain@apple.com <aakash_jain@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Nov 2018 20:12:00 +0000 (20:12 +0000)
committeraakash_jain@apple.com <aakash_jain@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Nov 2018 20:12:00 +0000 (20:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191931

Reviewed by Lucas Forschler.

* BuildSlaveSupport/ews-app/ews/models/patch.py:
(Patch.set_sent_to_buildbot):
(Patch.set_bug_id):
(Patch.set_obsolete):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238627 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/BuildSlaveSupport/ews-app/ews/models/patch.py
Tools/ChangeLog

index 092a5ab..b24267a 100644 (file)
@@ -26,7 +26,7 @@ import logging
 
 from django.db import models
 
-from ews.config import *
+from ews.config import ERR_EXISTING_PATCH, ERR_INVALID_PATCH_ID, ERR_NON_EXISTING_PATCH, SUCCESS
 
 _log = logging.getLogger(__name__)
 
@@ -73,3 +73,47 @@ class Patch(models.Model):
     @classmethod
     def is_patch_sent_to_buildbot(cls, patch_id):
         return Patch.is_existing_patch_id(patch_id) and Patch.objects.get(pk=patch_id).sent_to_buildbot
+
+    @classmethod
+    def set_sent_to_buildbot(cls, patch_id):
+        if not Patch.is_existing_patch_id(patch_id):
+            return ERR_NON_EXISTING_PATCH
+
+        patch = Patch.objects.get(pk=patch_id)
+        if patch.sent_to_buildbot:
+            _log.warn('Patch {} has already been sent to Buildbot.'.format(patch_id))
+            return SUCCESS
+
+        patch.sent_to_buildbot = True
+        patch.save()
+        _log.debug('Updated patch {} with sent_to_buildbot=True'.format(patch_id))
+        return SUCCESS
+
+    @classmethod
+    def set_bug_id(cls, patch_id, bug_id):
+        if not Patch.is_existing_patch_id(patch_id):
+            return ERR_NON_EXISTING_PATCH
+
+        patch = Patch.objects.get(pk=patch_id)
+        if patch.bug_id == bug_id:
+            _log.warn('Patch {} already has bug id {} set.'.format(patch_id, bug_id))
+            return SUCCESS
+
+        patch.bug_id = bug_id
+        patch.save()
+        _log.debug('Updated patch {} with bug id {}'.format(patch_id, bug_id))
+        return SUCCESS
+
+    @classmethod
+    def set_obsolete(cls, patch_id, obsolete=True):
+        if not Patch.is_existing_patch_id(patch_id):
+            return ERR_NON_EXISTING_PATCH
+
+        patch = Patch.objects.get(pk=patch_id)
+        if patch.obsolete == obsolete:
+            _log.warn('Patch {} is already marked with obsolete={}.'.format(patch_id, obsolete))
+            return SUCCESS
+        patch.obsolete = obsolete
+        patch.save()
+        _log.debug('Marked patch {} as obsolete={}'.format(patch_id, obsolete))
+        return SUCCESS
index 69d1f20..aa364a8 100644 (file)
@@ -1,3 +1,15 @@
+2018-11-28  Aakash Jain  <aakash_jain@apple.com>
+
+        [ews-app] Add methods to update Patch fields
+        https://bugs.webkit.org/show_bug.cgi?id=191931
+
+        Reviewed by Lucas Forschler.
+
+        * BuildSlaveSupport/ews-app/ews/models/patch.py:
+        (Patch.set_sent_to_buildbot):
+        (Patch.set_bug_id):
+        (Patch.set_obsolete):
+
 2018-11-28  Yongjun Zhang  <yongjun_zhang@apple.com>
 
         Allow WebKit clients to specify a minimum effective width for layout.