Diff
Modified: trunk/Tools/ChangeLog (289248 => 289249)
--- trunk/Tools/ChangeLog 2022-02-08 00:22:19 UTC (rev 289248)
+++ trunk/Tools/ChangeLog 2022-02-08 01:13:23 UTC (rev 289249)
@@ -1,3 +1,26 @@
+2022-02-07 Jonathan Bedard <[email protected]>
+
+ [webkitscmpy] Adopt webkitbugspy for GitHub issues (Part 1)
+ https://bugs.webkit.org/show_bug.cgi?id=235899
+ <rdar://problem/88280520>
+
+ 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.Encoder.default): Leverage Tracker URL templates.
+ (Tracker.__init__): Ditto.
+ * Scripts/libraries/webkitbugspy/webkitbugspy/github.py:
+ (Tracker.Encoder.default): Handle API url regexes.
+ (Tracker.__init__): Match API urls.
+ * Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py:
+ (GitHub.__init__): Spell "username" correctly.
+ (GitHub._issue): Handle case where assignee or watchers is undefined.
+ (GitHub.request): Rename "api_host" to "api_remote" to match webkitscmpy.
+ * Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py:
+ (TestGitHub.test_link):
+
2022-02-07 Commit Queue <[email protected]>
Unreviewed, reverting r289239.
Modified: trunk/Tools/Scripts/libraries/webkitbugspy/setup.py (289248 => 289249)
--- trunk/Tools/Scripts/libraries/webkitbugspy/setup.py 2022-02-08 00:22:19 UTC (rev 289248)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/setup.py 2022-02-08 01:13:23 UTC (rev 289249)
@@ -30,7 +30,7 @@
setup(
name='webkitbugspy',
- version='0.2.0',
+ version='0.3.1',
description='Library containing a shared API for various bug trackers.',
long_description=readme(),
classifiers=[
Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py (289248 => 289249)
--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py 2022-02-08 00:22:19 UTC (rev 289248)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py 2022-02-08 01:13:23 UTC (rev 289249)
@@ -46,7 +46,7 @@
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)
-version = Version(0, 2, 0)
+version = Version(0, 3, 1)
from .user import User
from .issue import Issue
Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/bugzilla.py (289248 => 289249)
--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/bugzilla.py 2022-02-08 00:22:19 UTC (rev 289248)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/bugzilla.py 2022-02-08 01:13:23 UTC (rev 289249)
@@ -36,6 +36,10 @@
class Tracker(GenericTracker):
ROOT_RE = re.compile(r'\Ahttps?://(?P<domain>\S+)\Z')
+ RE_TEMPLATES = [
+ r'\Ahttps?://{}/show_bug.cgi\?id=(?P<id>\d+)\Z',
+ r'\A{}/show_bug.cgi\?id=(?P<id>\d+)\Z',
+ ]
class Encoder(GenericTracker.Encoder):
@webkitcorepy.decorators.hybridmethod
@@ -45,8 +49,8 @@
type='bugzilla',
url=""
)
- if obj._res[2:]:
- result['res'] = [compiled.pattern for compiled in obj._res[2:]]
+ if obj._res[len(Tracker.RE_TEMPLATES):]:
+ result['res'] = [compiled.pattern for compiled in obj._res[len(Tracker.RE_TEMPLATES):]]
return result
if isinstance(context, type):
raise TypeError('Cannot invoke parent class when classmethod')
@@ -61,8 +65,8 @@
raise self.Exception("'{}' is not a valid bugzilla url".format(url))
self.url = ""
self._res = [
- re.compile(r'\Ahttps?://{}/show_bug.cgi\?id=(?P<id>\d+)\Z'.format(match.group('domain'))),
- re.compile(r'\A{}/show_bug.cgi\?id=(?P<id>\d+)\Z'.format(match.group('domain'))),
+ re.compile(template.format(match.group('domain')))
+ for template in self.RE_TEMPLATES
] + (res or [])
def user(self, name=None, username=None, email=None):
Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py (289248 => 289249)
--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py 2022-02-08 00:22:19 UTC (rev 289248)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py 2022-02-08 01:13:23 UTC (rev 289249)
@@ -39,6 +39,12 @@
ROOT_RE = re.compile(r'\Ahttps?://github.(?P<domain>\S+)/(?P<owner>\S+)/(?P<repository>\S+)\Z')
ISSUE_LINK_RE = re.compile(r'#(?P<id>\d+)')
USERNAME_RE = re.compile(r'(^|\s|\'|")@(?P<username>[^\s"\'<>]+)')
+ RE_TEMPLATES = [
+ r'\Ahttps?://github.{}/{}/{}/issues/(?P<id>\d+)\Z',
+ r'\Agithub.{}/{}/{}/issues/(?P<id>\d+)\Z',
+ r'\Ahttps?://api.github.{}/repos/{}/{}/issues/(?P<id>\d+)\Z',
+ r'\Aapi.github.{}/repos/{}/{}/issues/(?P<id>\d+)\Z',
+ ]
class Encoder(GenericTracker.Encoder):
@webkitcorepy.decorators.hybridmethod
@@ -48,8 +54,8 @@
type='github',
url=""
)
- if obj._res[2:]:
- result['res'] = [compiled.pattern for compiled in obj._res[2:]]
+ if obj._res[len(Tracker.RE_TEMPLATES):]:
+ result['res'] = [compiled.pattern for compiled in obj._res[len(Tracker.RE_TEMPLATES):]]
return result
if isinstance(context, type):
raise TypeError('Cannot invoke parent class when classmethod')
@@ -64,11 +70,8 @@
raise self.Exception("'{}' is not a valid GitHub project".format(url))
self._res = [
- re.compile(r'\Ahttps?://github.{}/{}/{}/issues/(?P<id>\d+)\Z'.format(
- match.group('domain'), match.group('owner'), match.group('repository'),
- )), re.compile(r'\Agithub.{}/{}/{}/issues/(?P<id>\d+)\Z'.format(
- match.group('domain'), match.group('owner'), match.group('repository'),
- )),
+ re.compile(template.format(match.group('domain'), match.group('owner'), match.group('repository')))
+ for template in self.RE_TEMPLATES
] + (res or [])
self.url = ""
@@ -334,7 +337,8 @@
timestamp=tm,
content=data.get('body'),
)
- if not issue._comments:
+ if issue._comments is None:
self.populate(issue, 'comments')
- issue._comments.append(result)
+ else:
+ issue._comments.append(result)
return result
Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py (289248 => 289249)
--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py 2022-02-08 00:22:19 UTC (rev 289248)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/mocks/github.py 2022-02-08 01:13:23 UTC (rev 289249)
@@ -48,14 +48,16 @@
def __init__(self, hostname='github.example.com/WebKit/WebKit', users=None, issues=None, environment=None):
hostname, repo = hostname.split('/', 1)
- self.api_host = 'api.{hostname}/repos/{repo}'.format(hostname=hostname, repo=repo)
+ self.api_remote = 'api.{hostname}/repos/{repo}'.format(hostname=hostname, repo=repo)
Base.__init__(self, users=users, issues=issues)
mocks.Requests.__init__(self, hostname, 'api.{}'.format(hostname))
prefix = self.hosts[0].replace('.', '_').upper()
+ if not environment:
+ self.users.create(username='username')
self._environment = environment or mocks.Environment(**{
- '{}_USERNAME'.format(prefix): 'usernmae',
+ '{}_USERNAME'.format(prefix): 'username',
'{}_TOKEN'.format(prefix): 'token',
})
@@ -101,8 +103,8 @@
user=dict(login=self.users[issue['creator'].name].username),
created_at=self.time_string(issue['timestamp']),
state='opened' if issue['opened'] else 'closed',
- assignee=dict(login=self.users[issue['assignee'].name].username),
- assignees=[dict(login=self.users[user.name].username) for user in issue['watchers']],
+ 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', [])],
))
def _comments(self, url, id):
@@ -178,17 +180,17 @@
if match and method == 'GET':
return self._user(url, match.group('username'))
- match = re.match(r'{}/issues/(?P<id>\d+)$'.format(self.api_host), stripped_url)
+ match = re.match(r'{}/issues/(?P<id>\d+)$'.format(self.api_remote), stripped_url)
if match and method in ('GET', 'PATCH'):
return self._issue(url, int(match.group('id')), data="" if method == 'PATCH' else None)
- match = re.match(r'{}/issues/(?P<id>\d+)/comments$'.format(self.api_host), stripped_url)
+ match = re.match(r'{}/issues/(?P<id>\d+)/comments$'.format(self.api_remote), stripped_url)
if match and method == 'GET':
return self._comments(url, int(match.group('id')))
if match and method == 'POST':
return self._post_comment(url, int(match.group('id')), auth, json)
- match = re.match(r'{}/issues/(?P<id>\d+)/timeline$'.format(self.api_host), stripped_url)
+ match = re.match(r'{}/issues/(?P<id>\d+)/timeline$'.format(self.api_remote), stripped_url)
if match and method == 'GET':
return self._timelines(url, int(match.group('id')))
Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py (289248 => 289249)
--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py 2022-02-08 00:22:19 UTC (rev 289248)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/tests/github_unittest.py 2022-02-08 01:13:23 UTC (rev 289249)
@@ -73,6 +73,10 @@
tracker.from_string('http://github.example.com/WebKit/WebKit/issues/1234').link,
'https://github.example.com/WebKit/WebKit/issues/1234',
)
+ self.assertEqual(
+ tracker.from_string('http://api.github.example.com/repos/WebKit/WebKit/issues/1234').link,
+ 'https://github.example.com/WebKit/WebKit/issues/1234',
+ )
self.assertEqual(tracker.from_string('https://github.example.com/Apple/Swift/issues/1234'), None)
def test_title(self):