Title: [292132] trunk/Tools
Revision
292132
Author
[email protected]
Date
2022-03-30 17:06:33 -0700 (Wed, 30 Mar 2022)

Log Message

[webkitbugspy] Get and set issue component data
https://bugs.webkit.org/show_bug.cgi?id=238514
<rdar://problem/90994542>

Reviewed by Dewei Zhu.

* Tools/Scripts/libraries/webkitbugspy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/bugzilla.py:
(Tracker.populate): Populate project, component and version.
(Tracker.set): Set project, component and version.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py:
(Tracker.request): github.Tracker has no Exception member. Use RuntimeError instead.
(Tracker.populate): Populate labels and then extract component and version.
(Tracker.set): Set labels associated with components and versions.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/issue.py:
(Issue.__init__): Set _labels, _project, _component and _version values.
(Issue.labels): Populate and return labels.
(Issue.set_labels): Set labels associated with issue.
(Issue.project): Populate and return project.
(Issue.component): Populate and return component.
(Issue.version): Populate and return version.
(Issue.set_component): Set the project, component and version of an issue.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/bugzilla.py:
(Bugzilla._issue): Mock setting and returning project, component and version.
(Bugzilla._create): Populate project, component and version on creation.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/data.py: Set values for
project, component and version.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py:
(GitHub._labels_for_issue): Given an issue, return a list of labels. Take into
consideration component and version.
(GitHub._issue): Mock label editing and returning.
(GitHub._create): Ditto.
(GitHub.request): Support request to update labels.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/radar.py:
(RadarModel.__init__): Set component.
(RadarModel.commit_changes): Commit component changes.
(RadarClient.find_components): Implement version filter.
(RadarClient.create_radar): Create radar with component details.
(Radar.Component.get): Implement dict-like API.
(Radar.Component.__getitem__): Ditto.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/radar.py:
(Tracker.populate): Get project, component and version.
(Tracker.set): Set component information.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/bugzilla_unittest.py:
(TestBugzilla.test_create):
(TestBugzilla.test_create_prompt):
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py:
(TestGitHub.test_projects):
(TestGitHub.test_create_projects):
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/radar_unittest.py:
(TestRadar.test_create):
(TestRadar.test_create_prompt):

Canonical link: https://commits.webkit.org/249039@main

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (292131 => 292132)


--- trunk/Tools/ChangeLog	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/ChangeLog	2022-03-31 00:06:33 UTC (rev 292132)
@@ -1,3 +1,59 @@
+2022-03-30  Jonathan Bedard  <[email protected]>
+
+        [webkitbugspy] Get and set issue component data
+        https://bugs.webkit.org/show_bug.cgi?id=238514
+        <rdar://problem/90994542>
+
+        Reviewed by Dewei Zhu.
+
+        * Scripts/libraries/webkitbugspy/setup.py: Bump version.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py: Ditto.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/bugzilla.py:
+        (Tracker.populate): Populate project, component and version.
+        (Tracker.set): Set project, component and version.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/github.py:
+        (Tracker.request): github.Tracker has no Exception member. Use RuntimeError instead.
+        (Tracker.populate): Populate labels and then extract component and version.
+        (Tracker.set): Set labels associated with components and versions.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/issue.py:
+        (Issue.__init__): Set _labels, _project, _component and _version values.
+        (Issue.labels): Populate and return labels.
+        (Issue.set_labels): Set labels associated with issue.
+        (Issue.project): Populate and return project.
+        (Issue.component): Populate and return component.
+        (Issue.version): Populate and return version.
+        (Issue.set_component): Set the project, component and version of an issue.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/mocks/bugzilla.py:
+        (Bugzilla._issue): Mock setting and returning project, component and version.
+        (Bugzilla._create): Populate project, component and version on creation.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/mocks/data.py: Set values for
+        project, component and version.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py:
+        (GitHub._labels_for_issue): Given an issue, return a list of labels. Take into
+        consideration component and version.
+        (GitHub._issue): Mock label editing and returning.
+        (GitHub._create): Ditto.
+        (GitHub.request): Support request to update labels.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/mocks/radar.py:
+        (RadarModel.__init__): Set component.
+        (RadarModel.commit_changes): Commit component changes.
+        (RadarClient.find_components): Implement version filter.
+        (RadarClient.create_radar): Create radar with component details.
+        (Radar.Component.get): Implement dict-like API.
+        (Radar.Component.__getitem__): Ditto.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/radar.py:
+        (Tracker.populate): Get project, component and version.
+        (Tracker.set): Set component information.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/tests/bugzilla_unittest.py:
+        (TestBugzilla.test_create):
+        (TestBugzilla.test_create_prompt):
+        * Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py:
+        (TestGitHub.test_projects):
+        (TestGitHub.test_create_projects):
+        * Scripts/libraries/webkitbugspy/webkitbugspy/tests/radar_unittest.py:
+        (TestRadar.test_create):
+        (TestRadar.test_create_prompt):
+
 2022-03-30  Sihui Liu  <[email protected]>
 
         Remove -[WKWebsiteDataStore _indexedDBDatabaseDirectory]

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/setup.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/setup.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/setup.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -30,7 +30,7 @@
 
 setup(
     name='webkitbugspy',
-    version='0.4.4',
+    version='0.5.0',
     description='Library containing a shared API for various bug trackers.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(0, 4, 4)
+version = Version(0, 5, 0)
 
 from .user import User
 from .issue import Issue

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/bugzilla.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/bugzilla.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/bugzilla.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -145,8 +145,9 @@
 
     def populate(self, issue, member=None):
         issue._link = '{}/show_bug.cgi?id={}'.format(self.url, issue.id)
+        issue._labels = []
 
-        if member in ['title', 'timestamp', 'creator', 'opened', 'assignee', 'watchers']:
+        if member in ('title', 'timestamp', 'creator', 'opened', 'assignee', 'watchers', 'project', 'component', 'version'):
             response = requests.get('{}/rest/bug/{}{}'.format(self.url, issue.id, self._login_arguments(required=False)))
             response = response.json().get('bugs', []) if response.status_code == 200 else None
             if response:
@@ -174,6 +175,10 @@
                 for name in response.get('cc', []):
                     issue._watchers.append(self.user(username=name))
 
+                issue._project = response.get('product', '')
+                issue._component = response.get('component', '')
+                issue._version = response.get('version', '')
+
             else:
                 sys.stderr.write("Failed to fetch '{}'\n".format(issue.link))
 
@@ -225,7 +230,7 @@
 
         return issue
 
-    def set(self, issue, assignee=None, opened=None, why=None, **properties):
+    def set(self, issue, assignee=None, opened=None, why=None, project=None, component=None, version=None, **properties):
         update_dict = dict()
 
         if properties:
@@ -249,6 +254,36 @@
         if why is not None:
             update_dict['comment'] = dict(body=why)
 
+        if project or component or version:
+            if not project and len(self.projects) == 1:
+                project = list(self.projects.keys())[0]
+            if not project:
+                raise ValueError('No project provided')
+            if not self.projects.get(project):
+                raise ValueError("'{}' is not a recognized project".format(project))
+
+            components = sorted(self.projects.get(project, {}).get('components', {}).keys())
+            if not component and len(components) == 1:
+                component = components[0]
+            if not component:
+                raise ValueError('No component provided')
+            if component and component not in components:
+                raise ValueError("'{}' is not a recognized component of '{}'".format(component, project))
+
+            versions = []
+            if component:
+                versions = self.projects.get(project, {}).get('components', {}).get(component, {}).get('versions', [])
+            if not versions:
+                versions = self.projects.get(project, {}).get('versions', [])
+            if not version:
+                version = versions[0]
+            if version not in versions:
+                raise ValueError("'{}' is not a recognized version in '{} {}'".format(version, project, component))
+
+            update_dict['product'] = project
+            update_dict['component'] = component
+            update_dict['version'] = version
+
         if update_dict:
             update_dict['ids'] = [issue.id]
             response = requests.put(
@@ -262,6 +297,10 @@
                     issue._opened = None
                 sys.stderr.write("Failed to modify '{}'\n".format(issue))
                 return None
+            elif project and component and version:
+                issue._project = project
+                issue._component = component
+                issue._version = version
 
         return issue
 

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -138,7 +138,7 @@
         if authenticated is False:
             auth = None
         if authenticated and not auth:
-            raise self.Exception('Request requires authentication, none provided')
+            raise RuntimeError('Request requires authentication, none provided')
 
         params = {key: value for key, value in params.items()} if params else dict()
         params['per_page'] = params.get('per_page', 100)
@@ -167,8 +167,7 @@
             params['page'] += 1
             response = requests.get(url, params=params, headers=headers, auth=auth)
             if response.status_code != 200:
-                raise self.Exception(
-                    "Failed to assemble pagination requests for '{}', failed on page {}".format(url, params['page']))
+                raise OSError("Failed to assemble pagination requests for '{}', failed on page {}".format(url, params['page']))
             result += response.json()
         return result
 
@@ -206,8 +205,9 @@
 
     def populate(self, issue, member=None):
         issue._link = '{}/issues/{}'.format(self.url, issue.id)
+        issue._project = self.name
 
-        if member in ('title', 'timestamp', 'creator', 'opened', 'assignee', 'description'):
+        if member in ('title', 'timestamp', 'creator', 'opened', 'assignee', 'description', 'project', 'component', 'version', 'labels'):
             response = self.request(path='issues/{}'.format(issue.id))
             if response:
                 issue._title = response['title']
@@ -216,6 +216,16 @@
                 issue._description = response['body']
                 issue._opened = response['state'] != 'closed'
                 issue._assignee = self.user(username=response['assignee']['login']) if response.get('assignee') else None
+
+                issue._labels = []
+                for label in response.get('labels', []):
+                    if not label.get('name'):
+                        continue
+                    issue._labels.append(label['name'])
+                    if self.component_color and label.get('color') == self.component_color:
+                        issue._component = label['name']
+                    if self.version_color and label.get('color') == self.version_color:
+                        issue._version = label['name']
             else:
                 sys.stderr.write("Failed to fetch '{}'\n".format(issue.link))
 
@@ -295,7 +305,7 @@
 
         return issue
 
-    def set(self, issue, assignee=None, opened=None, why=None, **properties):
+    def set(self, issue, assignee=None, opened=None, why=None, project=None, component=None, version=None, labels=None, **properties):
         update_dict = dict()
 
         if properties:
@@ -311,6 +321,65 @@
             issue._opened = bool(opened)
             update_dict['state'] = 'open' if issue._opened else 'closed'
 
+        if project or component or version:
+            if not self.projects:
+                raise ValueError("No components are defined for '{}'".format(self.url))
+            project = project or self.name
+            if project != self.name:
+                raise ValueError("Project should be '{}' not '{}'".format(self.name, project))
+
+            components = sorted(self.projects.get(project, {}).get('components', {}).keys())
+            if not component and len(components) == 1:
+                component = components[0]
+            if component and component not in components:
+                raise ValueError("'{}' is not a recognized component of '{}'".format(component, project))
+
+            versions = self.projects.get(project, {}).get('versions', [])
+            if not version and len(versions) == 1:
+                version = versions[0]
+            if version and version not in versions:
+                raise ValueError("'{}' is not a recognized version of '{}'".format(version, project))
+
+            labels = (labels or issue.labels)
+            index = 0
+            while index < len(labels):
+                label = labels[index]
+                color = self.labels.get(label, {}).get('color')
+                if color and component and color == self.component_color:
+                    labels.pop(index)
+                elif color and version and color == self.version_color:
+                    labels.pop(index)
+                else:
+                    index += 1
+            if component:
+                labels.append(component)
+            if version:
+                labels.append(version)
+
+        if labels:
+            for label in labels:
+                if not self.labels.get(label):
+                    raise ValueError("'{}' is not a label for '{}'".format(label, self.url))
+            response = requests.put(
+                '{api_url}/repos/{owner}/{name}/issues/{id}/labels'.format(
+                    api_url=self.api_url,
+                    owner=self.owner,
+                    name=self.name,
+                    id=issue.id,
+                ), auth=HTTPBasicAuth(*self.credentials(required=True)),
+                headers=dict(Accept='application/vnd.github.v3+json'),
+                json=dict(labels=labels),
+            )
+            if response.status_code // 100 != 2:
+                sys.stderr.write("Failed to modify '{}'\n".format(issue))
+                sys.stderr.write(self.REFRESH_TOKEN_PROMPT)
+                if not update_dict:
+                    return None
+            elif project and component and version:
+                issue._project = project
+                issue._component = component
+                issue._version = version
+
         if update_dict:
             update_dict['number'] = [issue.id]
             response = requests.patch(

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/issue.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/issue.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/issue.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -67,6 +67,11 @@
         self._comments = None
         self._references = None
 
+        self._labels = None
+        self._project = None
+        self._component = None
+        self._version = None
+
         self.tracker.populate(self, None)
 
     def __str__(self):
@@ -149,6 +154,36 @@
     def add_comment(self, text):
         return self.tracker.add_comment(self, text)
 
+    @property
+    def labels(self):
+        if self._labels is None:
+            self.tracker.populate(self, 'labels')
+        return self._labels
+
+    def set_labels(self, labels):
+        return self.tracker.set(labels=labels)
+
+    @property
+    def project(self):
+        if self._project is None:
+            self.tracker.populate(self, 'project')
+        return self._project
+
+    @property
+    def component(self):
+        if self._component is None:
+            self.tracker.populate(self, 'component')
+        return self._component
+
+    @property
+    def version(self):
+        if self._version is None:
+            self.tracker.populate(self, 'version')
+        return self._version
+
+    def set_component(self, project=None, component=None, version=None):
+        return self.tracker.set(self, project=project, component=component, version=version)
+
     def __hash__(self):
         return hash(self.link)
 

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/bugzilla.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/bugzilla.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/bugzilla.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -136,6 +136,12 @@
                 issue['comments'].append(
                     Issue.Comment(user=user, timestamp=int(time.time()), content=data['comment']['body']),
                 )
+            if data.get('project'):
+                issue['product'] = data['project']
+            if data.get('component'):
+                issue['component'] = data['component']
+            if data.get('version'):
+                issue['version'] = data['version']
 
         return mocks.Response.fromJson(dict(
             bugs=[dict(
@@ -145,6 +151,9 @@
                 status='REOPENED' if issue['opened'] else 'RESOLVED',
                 resolution='' if issue['opened'] else 'FIXED',
                 creator=self.users[issue['creator'].name].username,
+                product=issue.get('project'),
+                component=issue.get('component'),
+                version=issue.get('version'),
                 creator_detail=dict(
                     email=issue['creator'].email,
                     name=self.users[issue['creator'].name].username,
@@ -296,6 +305,9 @@
             creator=user,
             assignee=assignee,
             description=data['description'],
+            project=data.get('product'),
+            component=data.get('component'),
+            version=data.get('version'),
             comments=[], watchers=[user, assignee] if assignee else [user],
         )
 

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/data.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/data.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/data.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -45,6 +45,9 @@
         creator=USERS['Felix Filer'],
         assignee=USERS['Tim Contributor'],
         description='An example issue for testing',
+        project='WebKit',
+        component='Text',
+        version='Other',
         comments=[
             Issue.Comment(
                 user=USERS['Felix Filer'],
@@ -63,6 +66,9 @@
         creator=USERS['Tim Contributor'],
         assignee=USERS['Tim Contributor'],
         description='We need to support a new feature',
+        project='WebKit',
+        component='Scrolling',
+        version='Safari 15',
         comments=[
             Issue.Comment(
                 user=USERS['Tim Contributor'],
@@ -78,6 +84,9 @@
         creator=USERS['Felix Filer'],
         assignee=USERS['Tim Contributor'],
         description='Another example issue for testing, example.com is broken',
+        project='WebKit',
+        component='SVG',
+        version='WebKit Local Build',
         comments=[
             Issue.Comment(
                 user=USERS['Tim Contributor'],

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -94,6 +94,24 @@
             email=user.email,
         ), url=""
 
+    def _labels_for_issue(self, issue):
+        ref_labels = self._labels(None).json()
+        labels = issue.get('labels', [])
+
+        component = issue.get('component')
+        version = issue.get('version')
+        for label in labels:
+            if label.get('name') == component:
+                component = None
+            if label.get('name') == version:
+                version = None
+        for ref in ref_labels:
+            if component and ref.get('name') == component:
+                labels.append(ref)
+            if version and ref.get('name') == version:
+                labels.append(ref)
+        return labels
+
     def _issue(self, url, id, data=""
         if id not in self.issues:
             return mocks.Response(
@@ -111,6 +129,14 @@
             if data.get('state') == 'closed':
                 issue['opened'] = False
 
+            if data.get('labels'):
+                issue['labels'] = []
+                issue['component'] = None
+                issue['version'] = None
+            for label in self._labels(None).json():
+                if label.get('name') in data.get('labels', []):
+                    issue['labels'].append(label)
+
         return mocks.Response.fromJson(dict(
             title=issue['title'],
             body=issue['description'],
@@ -117,6 +143,7 @@
             user=dict(login=self.users[issue['creator'].name].username),
             created_at=self.time_string(issue['timestamp']),
             state='opened' if issue['opened'] else 'closed',
+            labels=self._labels_for_issue(issue),
             assignee=dict(login=self.users[issue['assignee'].name].username) if issue['assignee'] else None,
             assignees=[dict(login=self.users[user.name].username) for user in issue.get('watchers', [])],
         ))
@@ -219,6 +246,11 @@
         while id in self.issues.keys():
             id += 1
 
+        labels = []
+        for label in self._labels(None).json():
+            if label.get('name') in data.get('labels', []):
+                labels.append(label)
+
         issue = dict(
             id=id,
             title=data['title'],
@@ -227,6 +259,7 @@
             creator=user,
             assignee=assignee,
             description=data['body'],
+            labels=labels,
             comments=[], watchers=[user, assignee] if assignee else [user],
         )
         self.issues[id] = issue
@@ -238,6 +271,7 @@
             user=dict(login=self.users[issue['creator'].name].username),
             created_at=self.time_string(issue['timestamp']),
             state='opened' if issue['opened'] else 'closed',
+            labels=self._labels_for_issue(issue),
             assignee=dict(login=self.users[issue['assignee'].name].username) if issue['assignee'] else None,
             assignees=[dict(login=self.users[user.name].username) for user in issue.get('watchers', [])],
         ), url=""
@@ -266,6 +300,10 @@
         if match and method == 'GET':
             return self._timelines(url, int(match.group('id')))
 
+        match = re.match(r'{}/issues/(?P<id>\d+)/labels$'.format(self.api_remote), stripped_url)
+        if match and method == 'PUT':
+            return self._issue(url, int(match.group('id')), json)
+
         match = re.match(r'{}/labels$'.format(self.api_remote), stripped_url)
         if match and method == 'GET':
             return self._labels(url)

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/radar.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/radar.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/radar.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -139,6 +139,16 @@
         self.cc_memberships = self.CollectionProperty(self, *[
             self.CCMembership(Radar.transform_user(watcher)) for watcher in issue.get('watchers', [])
         ])
+        components = []
+        if issue.get('project') and issue.get('component') and issue.get('version'):
+            components = self.client.find_components(dict(
+                name=dict(eq='{} {}'.format(issue['project'], issue['component'])),
+                version=dict(eq=issue['version']),
+            ))
+        if components:
+            self.component = components[0]
+        else:
+            self.component = None
 
     def related_radars(self):
         for reference in self._issue.get('references', []):
@@ -157,7 +167,19 @@
         self.client.parent.issues[self.id]['assignee'] = self.client.parent.users[self.assignee.dsid]
         self.client.parent.issues[self.id]['opened'] = self.state not in ('Verify', 'Closed')
 
+        if self.component:
+            project = ''
+            component = self.component.name
+            for candidate in self.client.parent.projects.keys():
+                if component.startswith(candidate):
+                    project = candidate
+                    component = component[len(project):].lstrip()
 
+            self.client.parent.issues[self.id]['project'] = project
+            self.client.parent.issues[self.id]['component'] = component
+            self.client.parent.issues[self.id]['version'] = self.component.version
+
+
 class RadarClient(object):
     def __init__(self, parent, authentication_strategy):
         self.parent = parent
@@ -171,26 +193,27 @@
 
     def find_components(self, request_data):
         filters = []
-        if 'name' in request_data:
-            name_data = request_data['name']
-            action = "" if isinstance(name_data, dict) else 'eq'
-            name = name_data[action] if isinstance(name_data, dict) else name_data
-            filter = dict(
-                eq=lambda s: s == name,
-                like=lambda s: re.match(name.replace('%', '.*'), s),
-            ).get(action)
-            if not filter:
-                raise ValueError('{} is not a valid Radar filter'.format(action))
-            filters.append(filter)
+        for key in ('name', 'version'):
+            if key in request_data:
+                key_data = request_data[key]
+                action = "" if isinstance(key_data, dict) else 'eq'
+                key_value = key_data[action] if isinstance(key_data, dict) else key_data
+                filter = dict(
+                    eq=lambda key=key, key_value=key_value, **kwargs: not kwargs.get(key) or kwargs[key] == key_value,
+                    like=lambda key=key, key_value=key_value, **kwargs: not kwargs.get(key) or re.match(key_value.replace('%', '.*'), kwargs[key]),
+                ).get(action)
+                if not filter:
+                    raise ValueError('{} is not a valid Radar filter'.format(action))
+                filters.append(filter)
 
         result = []
         for project, project_details in self.parent.projects.items():
             for component, component_details in project_details.get('components', {}).items():
                 component_name = '{} {}'.format(project, component)
-                if any(not filter(component_name) for filter in filters):
+                if any(not filter(name=component_name) for filter in filters):
                     continue
                 for version in project_details.get('versions', ['All']):
-                    if 'version' in request_data and version != request_data['version']:
+                    if any(not filter(version=version) for filter in filters):
                         continue
                     result.append(Radar.Component(component_name, component_details['description'], version))
         return result
@@ -202,7 +225,8 @@
         )):
             raise Radar.exceptions.UnsuccessfulResponseException('Not enough parameters defined to create a radar')
 
-        if len(self.find_components(request_data['component'])) != 1:
+        components = self.find_components(request_data['component'])
+        if len(components) != 1:
             raise Radar.exceptions.UnsuccessfulResponseException('Provided component is not valid')
         if request_data['classification'] not in radar.Tracker.CLASSIFICATIONS:
             raise Radar.exceptions.UnsuccessfulResponseException("'{}' is not a valid classification".format(request_data['classification']))
@@ -209,10 +233,16 @@
         if request_data['reproducible'] not in radar.Tracker.REPRODUCIBILITY:
             raise Radar.exceptions.UnsuccessfulResponseException("'{}' is not a valid reproducibility value".format(request_data['reproducible']))
 
+        project = ''
+        component = components[0].name
+        for candidate in self.parent.projects.keys():
+            if component.startswith(candidate):
+                project = candidate
+                component = component[len(project):].lstrip()
+
         id = 1
         while id in self.parent.issues.keys():
             id += 1
-
         user = self.parent.users['{}@APPLECONNECT.APPLE.COM'.format(self.authentication_strategy.username())]
         issue = dict(
             id=id,
@@ -222,6 +252,9 @@
             creator=user,
             assignee=user,
             description=request_data['description'],
+            project=project,
+            component=component,
+            version=components[0].version,
             comments=[], watchers=[user],
         )
         self.parent.issues[id] = issue
@@ -254,6 +287,12 @@
             self.description = description
             self.version = version
 
+        def get(self, item, default=None):
+            return getattr(self, item, default)
+
+        def __getitem__(self, item):
+            return getattr(self, item)
+
     class DiagnosisEntry(object):
         def __init__(self, text=None, addedAt=None, addedBy=None):
             self.text = text

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/radar.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/radar.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/radar.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -170,11 +170,12 @@
 
     def populate(self, issue, member=None):
         issue._link = '<rdar://{}>'.format(issue.id)
+        issue._labels = []
         if (not self.client or not self.library) and member:
             sys.stderr.write('radarclient inaccessible on this machine\n')
             return issue
 
-        if not member:
+        if not member or member == 'labels':
             return issue
 
         radar = self.client.radar_for_id(issue.id)
@@ -238,9 +239,19 @@
                 issue._references.append(candidate)
                 refs.add(candidate.link)
 
+        if radar.component and member in ('project', 'component', 'version'):
+            issue._project = ''
+            issue._component = radar.component.get('name', '')
+            issue._version = radar.component.get('version', 'All')
+            for project in self._projects:
+                if issue._component.startswith(project):
+                    issue._project = project
+                    issue._component = issue._component[len(project):].lstrip()
+                    break
+
         return issue
 
-    def set(self, issue, assignee=None, opened=None, why=None, **properties):
+    def set(self, issue, assignee=None, opened=None, why=None, project=None, component=None, version=None, **properties):
         if not self.client or not self.library:
             sys.stderr.write('radarclient inaccessible on this machine\n')
             return None
@@ -275,6 +286,46 @@
                 radar.resolution = 'Software Changed'
             did_change = True
 
+        if project or component or version:
+            if not project and len(self.projects) == 1:
+                project = list(self.projects.keys())[0]
+            if not project:
+                raise ValueError('No project provided')
+            if not self.projects.get(project):
+                raise ValueError("'{}' is not a recognized project".format(project))
+
+            components = self.projects.get(project, {}).get('components', {}).keys()
+            if not component and len(components) == 1:
+                component = components[0]
+            if not component or component == '*':
+                component = ''
+            if component and component not in components:
+                raise ValueError("'{}' is not a recognized component of '{}'".format(component, project))
+
+            if component:
+                versions = self.projects.get(project, {}).get('components', {}).get(component, {}).get('versions', [])
+            else:
+                versions = self.projects.get(project, {}).get('versions', [])
+            if not version:
+                version = versions[0]
+            if version not in versions:
+                raise ValueError("'{}' is not a recognized version in '{} {}'".format(version, project, component))
+
+            components = self.client.find_components(dict(
+                name=dict(eq='{} {}'.format(project, component)),
+                version=dict(eq=version),
+            ))
+            if not components:
+                raise ValueError("No components match '{}' with version '{}'".format('{} {}'.format(project, component), version))
+            if len(components) > 1:
+                raise ValueError("{} components match '{}' with version '{}'".format(len(components), '{} {}'.format(project, component), version))
+            radar.component = components[0]
+            did_change = True
+
+            issue._project = project
+            issue._component = component
+            issue._version = version
+
         if did_change:
             radar.commit_changes()
         return self.add_comment(issue, why) if why else issue

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/bugzilla_unittest.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/bugzilla_unittest.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/bugzilla_unittest.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -309,6 +309,10 @@
                 dict(name='Tim Contributor', username='[email protected]', emails=['[email protected]']),
             )
 
+            self.assertEqual(created.project, 'WebKit')
+            self.assertEqual(created.component, 'Tables')
+            self.assertEqual(created.version, 'Other')
+
     def test_create_prompt(self):
         with mocks.Bugzilla(self.URL.split('://')[1], environment=wkmocks.Environment(
                 BUGS_EXAMPLE_COM_USERNAME='[email protected]',
@@ -328,6 +332,10 @@
                 dict(name='Tim Contributor', username='[email protected]', emails=['[email protected]']),
             )
 
+            self.assertEqual(created.project, 'WebKit')
+            self.assertEqual(created.component, 'SVG')
+            self.assertEqual(created.version, 'Safari 15')
+
         self.assertEqual(
             captured.stdout.getvalue(),
             '''What project should the bug be associated with?:
@@ -348,3 +356,27 @@
 : 
 ''',
         )
+
+    def test_get_component(self):
+        with mocks.Bugzilla(self.URL.split('://')[1], issues=mocks.ISSUES, projects=mocks.PROJECTS):
+            issue = bugzilla.Tracker(self.URL).issue(1)
+            self.assertEqual(issue.project, 'WebKit')
+            self.assertEqual(issue.component, 'Text')
+            self.assertEqual(issue.version, 'Other')
+
+    def test_set_component(self):
+        with mocks.Bugzilla(self.URL.split('://')[1], environment=wkmocks.Environment(
+                BUGS_EXAMPLE_COM_USERNAME='[email protected]',
+                BUGS_EXAMPLE_COM_PASSWORD='password',
+        ), projects=mocks.PROJECTS, issues=mocks.ISSUES):
+            bugzilla.Tracker(self.URL).issue(1).set_component(project='WebKit', component='Tables', version='Safari 15')
+
+            issue = bugzilla.Tracker(self.URL).issue(1)
+            self.assertEqual(issue.project, 'WebKit')
+            self.assertEqual(issue.component, 'Tables')
+            self.assertEqual(issue.version, 'Safari 15')
+
+    def test_labels(self):
+        with mocks.Bugzilla(self.URL.split('://')[1], issues=mocks.ISSUES, projects=mocks.PROJECTS):
+            issue = bugzilla.Tracker(self.URL).issue(1)
+            self.assertEqual(issue.labels, [])

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -268,7 +268,6 @@
             self.assertDictEqual(github.Tracker(self.URL).labels, mocked.DEFAULT_LABELS)
 
     def test_projects(self):
-        self.maxDiff = None
         with mocks.GitHub(self.URL.split('://')[1], projects=mocks.PROJECTS):
             self.assertDictEqual(
                 dict(
@@ -337,6 +336,10 @@
                 dict(name='Tim Contributor', username='tcontributor', emails=['[email protected]']),
             )
 
+            self.assertEqual(created.project, 'WebKit')
+            self.assertEqual(created.component, 'SVG')
+            self.assertEqual(created.version, 'Other')
+
         self.assertEqual(
             captured.stdout.getvalue(),
             '''What component in 'WebKit' should the bug be associated with?:
@@ -355,4 +358,28 @@
     5) WebKit Local Build
 : 
 ''',
-        )
\ No newline at end of file
+        )
+
+    def test_get_component(self):
+        with mocks.GitHub(self.URL.split('://')[1], issues=mocks.ISSUES, projects=mocks.PROJECTS):
+            issue = github.Tracker(self.URL).issue(1)
+            self.assertEqual(issue.project, 'WebKit')
+            self.assertEqual(issue.component, 'Text')
+            self.assertEqual(issue.version, 'Other')
+
+    def test_set_component(self):
+        with mocks.GitHub(self.URL.split('://')[1], issues=mocks.ISSUES, projects=mocks.PROJECTS, environment=wkmocks.Environment(
+            GITHUB_EXAMPLE_COM_USERNAME='tcontributor',
+            GITHUB_EXAMPLE_COM_TOKEN='token',
+        )):
+            github.Tracker(self.URL).issue(1).set_component(component='Tables', version='Safari 15')
+
+            issue = github.Tracker(self.URL).issue(1)
+            self.assertEqual(issue.project, 'WebKit')
+            self.assertEqual(issue.component, 'Tables')
+            self.assertEqual(issue.version, 'Safari 15')
+
+    def test_issue_label(self):
+        with mocks.GitHub(self.URL.split('://')[1], issues=mocks.ISSUES, projects=mocks.PROJECTS):
+            issue = github.Tracker(self.URL).issue(1)
+            self.assertEqual(issue.labels, ['Other', 'Text'])

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/radar_unittest.py (292131 => 292132)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/radar_unittest.py	2022-03-30 23:54:51 UTC (rev 292131)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/radar_unittest.py	2022-03-31 00:06:33 UTC (rev 292132)
@@ -270,6 +270,10 @@
                 dict(name='Tim Contributor', username=504, emails=['[email protected]']),
             )
 
+            self.assertEqual(created.project, 'WebKit')
+            self.assertEqual(created.component, 'Tables')
+            self.assertEqual(created.version, 'Other')
+
     def test_create_prompt(self):
         with wkmocks.Environment(RADAR_USERNAME='tcontributor'), mocks.Radar(issues=mocks.ISSUES, projects=mocks.PROJECTS), \
             wkmocks.Terminal.input('2', '4', '4'), OutputCapture() as captured:
@@ -288,6 +292,10 @@
                 dict(name='Tim Contributor', username=504, emails=['[email protected]']),
             )
 
+            self.assertEqual(created.project, 'WebKit')
+            self.assertEqual(created.component, 'Text')
+            self.assertEqual(created.version, 'WebKit Local Build')
+
         self.assertEqual(
             captured.stdout.getvalue(),
             '''What project should the bug be associated with?:
@@ -308,3 +316,24 @@
 : 
 ''',
         )
+
+    def test_get_component(self):
+        with wkmocks.Environment(RADAR_USERNAME='tcontributor'), mocks.Radar(issues=mocks.ISSUES, projects=mocks.PROJECTS):
+            issue = radar.Tracker(project='WebKit').issue(1)
+            self.assertEqual(issue.project, 'WebKit')
+            self.assertEqual(issue.component, 'Text')
+            self.assertEqual(issue.version, 'Other')
+
+    def test_set_component(self):
+        with wkmocks.Environment(RADAR_USERNAME='tcontributor'), mocks.Radar(issues=mocks.ISSUES, projects=mocks.PROJECTS):
+            radar.Tracker(project='WebKit').issue(1).set_component(component='Tables', version='Safari 15')
+
+            issue = radar.Tracker(project='WebKit').issue(1)
+            self.assertEqual(issue.project, 'WebKit')
+            self.assertEqual(issue.component, 'Tables')
+            self.assertEqual(issue.version, 'Safari 15')
+
+    def test_labels(self):
+        with wkmocks.Environment(RADAR_USERNAME='tcontributor'), mocks.Radar(issues=mocks.ISSUES):
+            issue = radar.Tracker().issue(1)
+            self.assertEqual(issue.labels, [])
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to