Title: [238631] trunk/Tools
Revision
238631
Author
aakash_j...@apple.com
Date
2018-11-28 13:09:34 -0800 (Wed, 28 Nov 2018)

Log Message

[ews-app] Add support to download Patch from Bugzilla
https://bugs.webkit.org/show_bug.cgi?id=191943

Reviewed by Lucas Forschler.

* BuildSlaveSupport/ews-app/ews/common/bugzilla.py: Added.
(Bugzilla.retrieve_attachment): Retreives the attachment from Bugzilla and saves to disk.
(Bugzilla._fetch_attachment_json):
(Bugzilla.file_path_for_patch):
* BuildSlaveSupport/ews-app/ews/common/util.py: Added.
(fetch_data_from_url): Method to fetch data from given url.
* BuildSlaveSupport/ews-app/ews/config.py:

Modified Paths

Added Paths

Diff

Added: trunk/Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py (0 => 238631)


--- trunk/Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py	                        (rev 0)
+++ trunk/Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py	2018-11-28 21:09:34 UTC (rev 238631)
@@ -0,0 +1,71 @@
+# Copyright (C) 2018 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import base64
+import logging
+import os
+
+from ews.models.patch import Patch
+import ews.common.util as util
+import ews.config as config
+
+_log = logging.getLogger(__name__)
+
+
+class Bugzilla():
+    @classmethod
+    def retrieve_attachment(cls, attachment_id):
+        attachment_json = Bugzilla._fetch_attachment_json(attachment_id)
+        if not attachment_json or not attachment_json.get('data'):
+            _log.warn('Unable to fetch attachment "{}".'.format(attachment_id))
+            return None
+
+        attachment_data = base64.b64decode(attachment_json.get('data'))
+        Bugzilla.save_attachment(attachment_id, attachment_data)
+        attachment_json['path'] = Bugzilla.file_path_for_patch(attachment_id)
+        return attachment_json
+
+    @classmethod
+    def save_attachment(cls, attachment_id, attachment_data):
+        with open(Bugzilla.file_path_for_patch(attachment_id), 'w') as attachment_file:
+            attachment_file.write(attachment_data)
+
+    @classmethod
+    def _fetch_attachment_json(cls, attachment_id):
+        if not Patch.is_valid_patch_id(attachment_id):
+            _log.warn('Invalid attachment id: "{}", skipping download.'.format(attachment_id))
+            return None
+
+        attachment_url = '{}rest/bug/attachment/{}'.format(config.BUG_SERVER_URL, attachment_id)
+        attachment = util.fetch_data_from_url(attachment_url)
+        if not attachment:
+            return None
+        attachment_json = attachment.json().get('attachments')
+        if not attachment_json or len(attachment_json) == 0:
+            return None
+        return attachment_json.get(str(attachment_id))
+
+    @classmethod
+    def file_path_for_patch(cls, patch_id):
+        if not os.path.exists(config.PATCH_FOLDER):
+            os.mkdir(config.PATCH_FOLDER)
+        return config.PATCH_FOLDER + '{}.patch'.format(patch_id)

Added: trunk/Tools/BuildSlaveSupport/ews-app/ews/common/util.py (0 => 238631)


--- trunk/Tools/BuildSlaveSupport/ews-app/ews/common/util.py	                        (rev 0)
+++ trunk/Tools/BuildSlaveSupport/ews-app/ews/common/util.py	2018-11-28 21:09:34 UTC (rev 238631)
@@ -0,0 +1,43 @@
+# Copyright (C) 2018 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import logging
+import requests
+
+_log = logging.getLogger(__name__)
+
+
+def fetch_data_from_url(url):
+    _log.debug('Fetching: {}'.format(url))
+    response = None
+    try:
+        response = requests.get(url)
+    except Exception as e:
+        if response:
+            _log.error('Failed to access {url} with status code {status_code}.'.format(url="" status_code=response.status_code))
+        else:
+            _log.error('Failed to access {url} with exception: {exception}'.format(url="" exception=e))
+        return None
+    if response.status_code != 200:
+        _log.error('Accessed {url} with unexpected status code {status_code}.'.format(url="" status_code=response.status_code))
+        return None
+    return response

Modified: trunk/Tools/BuildSlaveSupport/ews-app/ews/config.py (238630 => 238631)


--- trunk/Tools/BuildSlaveSupport/ews-app/ews/config.py	2018-11-28 21:09:09 UTC (rev 238630)
+++ trunk/Tools/BuildSlaveSupport/ews-app/ews/config.py	2018-11-28 21:09:34 UTC (rev 238631)
@@ -23,6 +23,9 @@
 import os
 
 BUG_SERVER_HOST = 'bugs.webkit.org'
+BUG_SERVER_URL = 'https://{}/'.format(BUG_SERVER_HOST)
+PATCH_FOLDER = '/tmp/'
+
 BUILDBOT_SERVER_HOST = 'ews-build.webkit-uat.org'
 BUILDBOT_SERVER_PORT = '5555'
 BUILDBOT_PB_USERNAME = os.getenv('BUILDBOT_PB_USERNAME', 'sampleuser')

Modified: trunk/Tools/ChangeLog (238630 => 238631)


--- trunk/Tools/ChangeLog	2018-11-28 21:09:09 UTC (rev 238630)
+++ trunk/Tools/ChangeLog	2018-11-28 21:09:34 UTC (rev 238631)
@@ -1,5 +1,20 @@
 2018-11-28  Aakash Jain  <aakash_j...@apple.com>
 
+        [ews-app] Add support to download Patch from Bugzilla
+        https://bugs.webkit.org/show_bug.cgi?id=191943
+
+        Reviewed by Lucas Forschler.
+
+        * BuildSlaveSupport/ews-app/ews/common/bugzilla.py: Added.
+        (Bugzilla.retrieve_attachment): Retreives the attachment from Bugzilla and saves to disk.
+        (Bugzilla._fetch_attachment_json):
+        (Bugzilla.file_path_for_patch):
+        * BuildSlaveSupport/ews-app/ews/common/util.py: Added.
+        (fetch_data_from_url): Method to fetch data from given url.
+        * BuildSlaveSupport/ews-app/ews/config.py:
+
+2018-11-28  Aakash Jain  <aakash_j...@apple.com>
+
         [ews-app] Add methods to update Patch fields
         https://bugs.webkit.org/show_bug.cgi?id=191931
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to