Title: [291989] trunk/Tools
Revision
291989
Author
[email protected]
Date
2022-03-28 14:02:59 -0700 (Mon, 28 Mar 2022)

Log Message

[webkitbugspy] Support component and version in GitHub
https://bugs.webkit.org/show_bug.cgi?id=238086
<rdar://problem/90495776>

Reviewed by Dewei Zhu.

GitHub issues do not have the concept of "component" and "version." However,
we can use label colors to divide labels into types.

* Tools/Scripts/libraries/webkitbugspy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py:
(Tracker):
(Tracker.__init__): Add concept of color groups for version and components.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py:
(GitHub):
(GitHub.__init__):
(GitHub._labels): Sort labels and output project details as labels.
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py:
(TestGitHub.test_create):
(TestGitHub.test_create_projects):

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

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (291988 => 291989)


--- trunk/Tools/ChangeLog	2022-03-28 20:58:18 UTC (rev 291988)
+++ trunk/Tools/ChangeLog	2022-03-28 21:02:59 UTC (rev 291989)
@@ -1,5 +1,29 @@
 2022-03-28  Jonathan Bedard  <[email protected]>
 
+        [webkitbugspy] Support component and version in GitHub
+        https://bugs.webkit.org/show_bug.cgi?id=238086
+        <rdar://problem/90495776>
+
+        Reviewed by Dewei Zhu.
+
+        GitHub issues do not have the concept of "component" and "version." However,
+        we can use label colors to divide labels into types.
+
+        * Scripts/libraries/webkitbugspy/setup.py: Bump version.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py: Ditto.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/github.py:
+        (Tracker):
+        (Tracker.__init__): Add concept of color groups for version and components.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py:
+        (GitHub):
+        (GitHub.__init__):
+        (GitHub._labels): Sort labels and output project details as labels.
+        * Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py:
+        (TestGitHub.test_create):
+        (TestGitHub.test_create_projects):
+
+2022-03-28  Jonathan Bedard  <[email protected]>
+
         [git-webkit] Support —oneline in log command
         https://bugs.webkit.org/show_bug.cgi?id=238209
         <rdar://problem/90660142>

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/setup.py (291988 => 291989)


--- trunk/Tools/Scripts/libraries/webkitbugspy/setup.py	2022-03-28 20:58:18 UTC (rev 291988)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/setup.py	2022-03-28 21:02:59 UTC (rev 291989)
@@ -30,7 +30,7 @@
 
 setup(
     name='webkitbugspy',
-    version='0.4.3',
+    version='0.4.4',
     description='Library containing a shared API for various bug trackers.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py (291988 => 291989)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py	2022-03-28 20:58:18 UTC (rev 291988)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py	2022-03-28 21:02:59 UTC (rev 291989)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(0, 4, 3)
+version = Version(0, 4, 4)
 
 from .user import User
 from .issue import Issue

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py (291988 => 291989)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py	2022-03-28 20:58:18 UTC (rev 291988)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py	2022-03-28 21:02:59 UTC (rev 291989)
@@ -46,7 +46,10 @@
         r'\Aapi.github.{}/repos/{}/{}/issues/(?P<id>\d+)\Z',
     ]
     REFRESH_TOKEN_PROMPT = "Is your API token out of date? Run 'git-webkit setup' to refresh credentials\n"
+    DEFAULT_COMPONENT_COLOR = 'FFFFFF'
+    DEFAULT_VERSION_COLOR = 'EEEEEE'
 
+
     class Encoder(GenericTracker.Encoder):
         @webkitcorepy.decorators.hybridmethod
         def default(context, obj):
@@ -63,9 +66,12 @@
             return super(Tracker.Encoder, context).default(obj)
 
 
-    def __init__(self, url, users=None, res=None):
+    def __init__(self, url, users=None, res=None, component_color=DEFAULT_COMPONENT_COLOR, version_color=DEFAULT_VERSION_COLOR):
         super(Tracker, self).__init__(users=users)
 
+        self.component_color = component_color
+        self.version_color = version_color
+
         match = self.ROOT_RE.match(url)
         if not match:
             raise TypeError("'{}' is not a valid GitHub project".format(url))
@@ -379,15 +385,71 @@
 
     @property
     def projects(self):
-        # FIXME: Should be implemented via tags in GitHub, come up with a standard technique for parsing
-        return dict()
+        result = dict(
+            versions=[],
+            components=dict(),
+        )
+        for name, details in self.labels.items():
+            if details.get('color') == self.component_color:
+                result['components'][name] = details
+            elif details.get('color') == self.version_color:
+                result['versions'].append(name)
 
-    def create(self, title, description, labels=None, assign=True):
+        result['versions'] = list(sorted(result['versions']))
+        if result['versions'] or result['components']:
+            return {self.name: result}
+        return {}
+
+    def create(
+        self, title, description,
+        project=None, component=None, version=None,
+        labels=None, assign=True,
+    ):
         if not title:
             raise ValueError('Must define title to create issue')
         if not description:
             raise ValueError('Must define description to create issue')
 
+        if self.projects:
+            if not project and len(self.projects.keys()) == 1:
+                project = list(self.projects.keys())[0]
+            if project not in self.projects:
+                raise ValueError("'{}' is not a recognized product on {}".format(project, self.url))
+
+            if not component and len(self.projects[project]['components'].keys()) == 1:
+                component = list(self.projects[project]['components'].keys())[0]
+            elif not component:
+                component = webkitcorepy.Terminal.choose(
+                    "What component in '{}' should the bug be associated with?".format(project),
+                    options=sorted(self.projects[project]['components'].keys()), numbered=True,
+                )
+            if component not in self.projects[project]['components']:
+                raise ValueError("'{}' is not a recognized component in '{}'".format(component, project))
+
+            if not version and len(self.projects[project]['versions']) == 1:
+                version = self.projects[project]['versions'][0]
+            elif not version:
+                version = webkitcorepy.Terminal.choose(
+                    "What version of '{}' should the bug be associated with?".format(project),
+                    options=self.projects[project]['versions'], numbered=True,
+                )
+            if version not in self.projects[project]['versions']:
+                raise ValueError("'{}' is not a recognized version for '{}'".format(version, project))
+
+        else:
+            if project:
+                raise ValueError("No 'projects' defined, cannot specify 'project'")
+            if component:
+                raise ValueError("No 'projects' defined, cannot specify 'component'")
+            if version:
+                raise ValueError("No 'projects' defined, cannot specify 'version'")
+
+        labels = labels or []
+        if component:
+            labels.append(component)
+        if version:
+            labels.append(version)
+
         for label in labels or []:
             if label not in self.labels:
                 raise ValueError("'{}' is not a recognized label in '{}'".format(label, self.url))

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


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py	2022-03-28 20:58:18 UTC (rev 291988)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py	2022-03-28 21:02:59 UTC (rev 291989)
@@ -26,7 +26,7 @@
 
 from .base import Base
 
-from webkitbugspy import User, Issue
+from webkitbugspy import User, Issue, github
 from webkitcorepy import mocks
 
 
@@ -41,7 +41,7 @@
         'help wanted': dict(color='008672', description='Extra attention is needed'),
         'invalid': dict(color='e4e669', description="This doesn't seem right"),
         'question': dict(color='d876e3', description='Further information is requested'),
-        'wontfix': dict(color='ffffff', description='This will not be worked on'),
+        'wontfix': dict(color='fefefe', description='This will not be worked on'),
     }
 
     @classmethod
@@ -57,11 +57,11 @@
         from datetime import datetime, timedelta
         return datetime.utcfromtimestamp(timestamp - timedelta(hours=7).seconds).strftime('%Y-%m-%dT%H:%M:%SZ')
 
-    def __init__(self, hostname='github.example.com/WebKit/WebKit', users=None, issues=None, environment=None, labels=None):
+    def __init__(self, hostname='github.example.com/WebKit/WebKit', users=None, issues=None, environment=None, projects=None, labels=None):
         hostname, repo = hostname.split('/', 1)
         self.api_remote = 'api.{hostname}/repos/{repo}'.format(hostname=hostname, repo=repo)
 
-        Base.__init__(self, users=users, issues=issues)
+        Base.__init__(self, users=users, issues=issues, projects=projects)
         mocks.Requests.__init__(self, hostname, 'api.{}'.format(hostname))
 
         prefix = self.hosts[0].replace('.', '_').upper()
@@ -185,14 +185,27 @@
         ], url=""
 
     def _labels(self, url):
-        return mocks.Response.fromJson([
-            dict(
-                name=name,
-                color=details['color'],
-                description=details['description'],
-            ) for name, details in self.labels.items()
-        ], url=""
+        result = [dict(
+            name=name,
+            color=details['color'],
+            description=details['description'],
+        ) for name, details in self.labels.items()]
 
+        for project in self.projects.values():
+            for name in project.get('versions', []):
+                result.append(dict(
+                    name=name,
+                    color=github.Tracker.DEFAULT_VERSION_COLOR,
+                ))
+            for name, details in project.get('components', {}).items():
+                result.append(dict(
+                    name=name,
+                    description=details['description'],
+                    color=github.Tracker.DEFAULT_COMPONENT_COLOR,
+                ))
+
+        return mocks.Response.fromJson(list(sorted(result, key=lambda v: v['name'])), url=""
+
     def _create(self, url, credentials, data):
         user = self.users.get(credentials.username) if credentials else None
         assignee = self.users.get(data['assignee']) if 'assignee' in data else None

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


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py	2022-03-28 20:58:18 UTC (rev 291988)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py	2022-03-28 21:02:59 UTC (rev 291989)
@@ -25,7 +25,7 @@
 import unittest
 
 from webkitbugspy import Issue, Tracker, User, github, mocks
-from webkitcorepy import mocks as wkmocks
+from webkitcorepy import OutputCapture, mocks as wkmocks
 
 
 class TestGitHub(unittest.TestCase):
@@ -268,8 +268,36 @@
             self.assertDictEqual(github.Tracker(self.URL).labels, mocked.DEFAULT_LABELS)
 
     def test_projects(self):
-        with mocks.GitHub(self.URL.split('://')[1]):
-            self.assertDictEqual(github.Tracker(self.URL).projects, dict())
+        self.maxDiff = None
+        with mocks.GitHub(self.URL.split('://')[1], projects=mocks.PROJECTS):
+            self.assertDictEqual(
+                dict(
+                    WebKit=dict(
+                        versions=['All', 'Other', 'Safari 15', 'Safari Technology Preview', 'WebKit Local Build'],
+                        components=dict(
+                            IPv4=dict(
+                                description='Bugs involving IPv4 networking',
+                                color='FFFFFF',
+                            ), IPv6=dict(
+                                description='Bugs involving IPv6 networking',
+                                color='FFFFFF',
+                            ), Scrolling=dict(
+                                description='Bugs related to main thread and off-main thread scrolling',
+                                color='FFFFFF',
+                            ), SVG=dict(
+                                description='For bugs in the SVG implementation.',
+                                color='FFFFFF',
+                            ), Tables=dict(
+                                description='For bugs specific to tables (both the DOM and rendering issues).',
+                                color='FFFFFF',
+                            ), Text=dict(
+                                description='For bugs in text layout and rendering, including international text support.',
+                                color='FFFFFF',
+                            ),
+                        ),
+                    ),
+                ), github.Tracker(self.URL).projects,
+            )
 
     def test_create(self):
         with mocks.GitHub(self.URL.split('://')[1], issues=mocks.ISSUES, environment=wkmocks.Environment(
@@ -289,3 +317,42 @@
                 User.Encoder().default(created.assignee),
                 dict(name='Tim Contributor', username='tcontributor', emails=['[email protected]']),
             )
+
+    def test_create_projects(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',
+        )), wkmocks.Terminal.input('3', '2'), OutputCapture() as captured:
+            created = github.Tracker(self.URL).create('New bug', 'Creating new bug')
+            self.assertEqual(created.id, 4)
+            self.assertEqual(created.title, 'New bug')
+            self.assertEqual(created.description, 'Creating new bug')
+            self.assertTrue(created.opened)
+            self.assertEqual(
+                User.Encoder().default(created.creator),
+                dict(name='Tim Contributor', username='tcontributor', emails=['[email protected]']),
+            )
+            self.assertEqual(
+                User.Encoder().default(created.assignee),
+                dict(name='Tim Contributor', username='tcontributor', emails=['[email protected]']),
+            )
+
+        self.assertEqual(
+            captured.stdout.getvalue(),
+            '''What component in 'WebKit' should the bug be associated with?:
+    1) IPv4
+    2) IPv6
+    3) SVG
+    4) Scrolling
+    5) Tables
+    6) Text
+: 
+What version of 'WebKit' should the bug be associated with?:
+    1) All
+    2) Other
+    3) Safari 15
+    4) Safari Technology Preview
+    5) WebKit Local Build
+: 
+''',
+        )
\ No newline at end of file
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to