Changeset 238636 in webkit


Ignore:
Timestamp:
Nov 28, 2018 1:59:51 PM (6 years ago)
Author:
aakash_jain@apple.com
Message:

[ews-app] Add support to get list of Bugzilla patches needing review
https://bugs.webkit.org/show_bug.cgi?id=191942

Reviewed by Lucas Forschler.

  • BuildSlaveSupport/ews-app/ews/common/bugzilla.py:

(Bugzilla.get_list_of_patches_needing_reviews): Get list of patches needing review.
(BugzillaBeautifulSoup.fetch_attachment_ids_from_review_queue): Copied from Tools/Scripts/webkitpy/common/net/bugzilla/bugzilla.py
(BugzillaBeautifulSoup._load_query): Ditto.
(BugzillaBeautifulSoup._parse_attachment_ids_request_query): Ditto.

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py

    r238631 r238636  
    2424import logging
    2525import os
     26import re
     27import socket
     28
     29from datetime import datetime, timedelta
    2630
    2731from ews.models.patch import Patch
     32from ews.thirdparty.BeautifulSoup import BeautifulSoup, SoupStrainer
    2833import ews.common.util as util
    2934import ews.config as config
     
    7075            os.mkdir(config.PATCH_FOLDER)
    7176        return config.PATCH_FOLDER + '{}.patch'.format(patch_id)
     77
     78    @classmethod
     79    def get_list_of_patches_needing_reviews(cls):
     80        current_time = datetime.today()
     81        ids_needing_review = set(BugzillaBeautifulSoup().fetch_attachment_ids_from_review_queue(current_time - timedelta(7)))
     82        #TODO: add security bugs support here.
     83        return ids_needing_review
     84
     85
     86class BugzillaBeautifulSoup():
     87    # FIXME: Deprecate this class when https://bugzilla.mozilla.org/show_bug.cgi?id=1508531 is fixed.
     88    def __init__(self):
     89        self._browser = None
     90
     91    def _get_browser(self):
     92        if not self._browser:
     93            socket.setdefaulttimeout(600)
     94            from mechanize import Browser
     95            self._browser = Browser()
     96            self._browser.set_handle_robots(False)
     97        return self._browser
     98
     99    def _set_browser(self, value):
     100        self._browser = value
     101
     102    browser = property(_get_browser, _set_browser)
     103
     104    def fetch_attachment_ids_from_review_queue(self, since=None, only_security_bugs=False):
     105        review_queue_url = 'request.cgi?action=queue&type=review&group=type'
     106        if only_security_bugs:
     107            review_queue_url += '&product=Security'
     108        return self._parse_attachment_ids_request_query(self._load_query(review_queue_url), since)
     109
     110    def _load_query(self, query):
     111        # TODO: check if we need to authenticate.
     112        full_url = '{}{}'.format(config.BUG_SERVER_URL, query)
     113        _log.info('Getting list of patches needing review, URL: {}'.format(full_url))
     114        return self.browser.open(full_url)
     115
     116    def _parse_attachment_ids_request_query(self, page, since=None):
     117        # Formats
     118        digits = re.compile("\d+")
     119        attachment_href = re.compile("attachment.cgi\?id=\d+&action=review")
     120        # if no date is given, return all ids
     121        if not since:
     122            attachment_links = SoupStrainer("a", href=attachment_href)
     123            return [int(digits.search(tag["href"]).group(0))
     124                for tag in BeautifulSoup(page, parseOnlyThese=attachment_links)]
     125
     126        # Parse the main table only
     127        date_format = re.compile("\d{4}-\d{2}-\d{2} \d{2}:\d{2}")
     128        mtab = SoupStrainer("table", {"class": "requests"})
     129        soup = BeautifulSoup(page, parseOnlyThese=mtab)
     130        patch_ids = []
     131
     132        for row in soup.findAll("tr"):
     133            patch_tag = row.find("a", {"href": attachment_href})
     134            if not patch_tag:
     135                continue
     136            patch_id = int(digits.search(patch_tag["href"]).group(0))
     137            date_tag = row.find("td", text=date_format)
     138            if date_tag and datetime.strptime(date_format.search(date_tag).group(0), "%Y-%m-%d %H:%M") < since:
     139                continue
     140            patch_ids.append(patch_id)
     141        return patch_ids
  • trunk/Tools/ChangeLog

    r238635 r238636  
     12018-11-28  Aakash Jain  <aakash_jain@apple.com>
     2
     3        [ews-app] Add support to get list of Bugzilla patches needing review
     4        https://bugs.webkit.org/show_bug.cgi?id=191942
     5
     6        Reviewed by Lucas Forschler.
     7
     8        * BuildSlaveSupport/ews-app/ews/common/bugzilla.py:
     9        (Bugzilla.get_list_of_patches_needing_reviews): Get list of patches needing review.
     10        (BugzillaBeautifulSoup.fetch_attachment_ids_from_review_queue): Copied from Tools/Scripts/webkitpy/common/net/bugzilla/bugzilla.py
     11        (BugzillaBeautifulSoup._load_query): Ditto.
     12        (BugzillaBeautifulSoup._parse_attachment_ids_request_query): Ditto.
     13
    1142018-11-28  Daniel Bates  <dabates@apple.com>
    215
Note: See TracChangeset for help on using the changeset viewer.