Diff
Modified: trunk/Tools/ChangeLog (281378 => 281379)
--- trunk/Tools/ChangeLog 2021-08-21 19:18:51 UTC (rev 281378)
+++ trunk/Tools/ChangeLog 2021-08-21 19:19:56 UTC (rev 281379)
@@ -1,3 +1,31 @@
+2021-08-21 Jonathan Bedard <jbed...@apple.com>
+
+ [git-webkit] Add pull-request command (Part 3)
+ https://bugs.webkit.org/show_bug.cgi?id=229089
+ <rdar://problem/81908751>
+
+ Reviewed by Dewei Zhu.
+
+ * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Bump version, export pull-request.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/pull_request.py:
+ (PullRequest.State):
+ (PullRequest.create_body): Create pull-request body from commits and comment.
+ (PullRequest.parse_body): Turn a body from a pull-request into a comment string and partial commits.
+ (PullRequest.__init__):
+ (PullRequest.__repr__):
+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:
+ (TestPullRequest):
+ (TestPullRequest.test_representation):
+ (TestPullRequest.test_create_body_single):
+ (TestPullRequest.test_parse_body_single):
+ (TestPullRequest.test_create_body_multiple):
+ (TestPullRequest.test_parse_body_multiple):
+ (TestPullRequest.test_create_body_empty):
+ (TestPullRequest.test_parse_body_empty):
+ (TestPullRequest.test_create_body_comment):
+ (TestPullRequest.test_parse_body_single):
+
2021-08-21 Myles C. Maxfield <mmaxfi...@apple.com>
[Cocoa] Single characters don't get shaped in the fast text codepath
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (281378 => 281379)
--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py 2021-08-21 19:18:51 UTC (rev 281378)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py 2021-08-21 19:19:56 UTC (rev 281379)
@@ -29,7 +29,7 @@
setup(
name='webkitscmpy',
- version='1.1.6',
+ version='1.1.7',
description='Library designed to interact with git and svn repositories.',
long_description=readme(),
classifiers=[
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (281378 => 281379)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py 2021-08-21 19:18:51 UTC (rev 281378)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py 2021-08-21 19:19:56 UTC (rev 281379)
@@ -46,7 +46,7 @@
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)
-version = Version(1, 1, 6)
+version = Version(1, 1, 7)
AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('monotonic', Version(1, 5)))
@@ -55,6 +55,7 @@
from webkitscmpy.contributor import Contributor
from webkitscmpy.commit import Commit
+from webkitscmpy.pull_request import PullRequest
from webkitscmpy.scm_base import ScmBase
from webkitscmpy import local
Added: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/pull_request.py (0 => 281379)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/pull_request.py (rev 0)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/pull_request.py 2021-08-21 19:19:56 UTC (rev 281379)
@@ -0,0 +1,77 @@
+# Copyright (C) 2021 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 re
+
+from .commit import Commit
+
+
+class PullRequest(object):
+ COMMIT_BODY_RE = re.compile(r'\A#### (?P<hash>[0-9a-f]+)\n```\n(?P<message>.+)\n```\n?\Z', flags=re.DOTALL)
+ DIVIDER_LEN = 70
+
+ class State(object):
+ OPENED = 'opened'
+ CLOSED = 'closed'
+
+ @classmethod
+ def create_body(cls, body, commits):
+ body = body or ''
+ if not commits:
+ return body
+ if body:
+ body = '{}\n\n{}\n'.format(body.rstrip(), '-' * cls.DIVIDER_LEN)
+ return body + '\n{}\n'.format('-' * cls.DIVIDER_LEN).join([
+ '#### {}\n```\n{}\n```'.format(commit.hash, commit.message.rstrip() if commit.message else '???') for commit in commits
+ ])
+
+ @classmethod
+ def parse_body(cls, body):
+ if not body:
+ return None, []
+ parts = [part.rstrip().lstrip() for part in body.split('-' * cls.DIVIDER_LEN)]
+ body = ''
+ commits = []
+
+ for part in parts:
+ match = cls.COMMIT_BODY_RE.match(part)
+ if match:
+ commits.append(Commit(
+ hash=match.group('hash'),
+ message=match.group('message') if match.group('message') != '???' else None,
+ ))
+ elif body:
+ body = '{}\n{}\n{}\n'.format(body.rstrip(), '-' * cls.DIVIDER_LEN, part.rstrip().lstrip())
+ else:
+ body = part.rstrip().lstrip()
+ return body or None, commits
+
+ def __init__(self, number, title=None, body=None, author=None, head=None, base=None):
+ self.number = number
+ self.title = title
+ self.body, self.commits = self.parse_body(body)
+ self.author = author
+ self.head = head
+ self.base = base
+
+ def __repr__(self):
+ return 'PR {}{}'.format(self.number, ' | {}'.format(self.title) if self.title else '')
Added: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py (0 => 281379)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py (rev 0)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py 2021-08-21 19:19:56 UTC (rev 281379)
@@ -0,0 +1,152 @@
+# Copyright (C) 2021 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 unittest
+
+from webkitscmpy import Commit, PullRequest
+
+
+class TestPullRequest(unittest.TestCase):
+ def test_representation(self):
+ self.assertEqual('PR 123 | [scoping] Bug to fix', str(PullRequest(123, title='[scoping] Bug to fix')))
+ self.assertEqual('PR 1234', str(PullRequest(1234)))
+
+ def test_create_body_single(self):
+ self.assertEqual(
+ PullRequest.create_body(None, [Commit(
+ hash='11aa76f9fc380e9fe06157154f32b304e8dc4749',
+ message='[scoping] Bug to fix\n\nReviewed by Tim Contributor.\n',
+ )]), '''#### 11aa76f9fc380e9fe06157154f32b304e8dc4749
+```
+[scoping] Bug to fix
+
+Reviewed by Tim Contributor.
+```''',
+ )
+
+ def test_parse_body_single(self):
+ body, commits = PullRequest.parse_body('''#### 11aa76f9fc380e9fe06157154f32b304e8dc4749
+```
+[scoping] Bug to fix
+
+Reviewed by Tim Contributor.
+```''')
+ self.assertIsNone(body)
+ self.assertEqual(len(commits), 1)
+ self.assertEqual(commits[0].hash, '11aa76f9fc380e9fe06157154f32b304e8dc4749')
+ self.assertEqual(commits[0].message, '[scoping] Bug to fix\n\nReviewed by Tim Contributor.')
+
+ def test_create_body_multiple(self):
+ self.assertEqual(
+ PullRequest.create_body(None, [Commit(
+ hash='11aa76f9fc380e9fe06157154f32b304e8dc4749',
+ message='[scoping] Bug to fix (Part 2)\n\nReviewed by Tim Contributor.\n',
+ ), Commit(
+ hash='53ea230fcedbce327eb1c45a6ab65a88de864505',
+ message='[scoping] Bug to fix (Part 1)\n\nReviewed by Tim Contributor.\n',
+ )]), '''#### 11aa76f9fc380e9fe06157154f32b304e8dc4749
+```
+[scoping] Bug to fix (Part 2)
+
+Reviewed by Tim Contributor.
+```
+----------------------------------------------------------------------
+#### 53ea230fcedbce327eb1c45a6ab65a88de864505
+```
+[scoping] Bug to fix (Part 1)
+
+Reviewed by Tim Contributor.
+```''',
+ )
+
+ def test_parse_body_multiple(self):
+ body, commits = PullRequest.parse_body('''#### 11aa76f9fc380e9fe06157154f32b304e8dc4749
+```
+[scoping] Bug to fix (Part 2)
+
+Reviewed by Tim Contributor.
+```
+----------------------------------------------------------------------
+#### 53ea230fcedbce327eb1c45a6ab65a88de864505
+```
+[scoping] Bug to fix (Part 1)
+
+Reviewed by Tim Contributor.
+```''')
+ self.assertIsNone(body)
+ self.assertEqual(len(commits), 2)
+
+ self.assertEqual(commits[0].hash, '11aa76f9fc380e9fe06157154f32b304e8dc4749')
+ self.assertEqual(commits[0].message, '[scoping] Bug to fix (Part 2)\n\nReviewed by Tim Contributor.')
+
+ self.assertEqual(commits[1].hash, '53ea230fcedbce327eb1c45a6ab65a88de864505')
+ self.assertEqual(commits[1].message, '[scoping] Bug to fix (Part 1)\n\nReviewed by Tim Contributor.')
+
+ def test_create_body_empty(self):
+ self.assertEqual(
+ PullRequest.create_body(None, [Commit(hash='11aa76f9fc380e9fe06157154f32b304e8dc4749')]),
+ '''#### 11aa76f9fc380e9fe06157154f32b304e8dc4749
+```
+???
+```''',
+ )
+
+ def test_parse_body_empty(self):
+ body, commits = PullRequest.parse_body('''#### 11aa76f9fc380e9fe06157154f32b304e8dc4749
+```
+???
+```''')
+ self.assertIsNone(body)
+ self.assertEqual(len(commits), 1)
+ self.assertEqual(commits[0].hash, '11aa76f9fc380e9fe06157154f32b304e8dc4749')
+ self.assertEqual(commits[0].message, None)
+
+ def test_create_body_comment(self):
+ self.assertEqual(
+ PullRequest.create_body('Comment body', [Commit(
+ hash='11aa76f9fc380e9fe06157154f32b304e8dc4749',
+ message='[scoping] Bug to fix\n\nReviewed by Tim Contributor.\n',
+ )]), '''Comment body
+
+----------------------------------------------------------------------
+#### 11aa76f9fc380e9fe06157154f32b304e8dc4749
+```
+[scoping] Bug to fix
+
+Reviewed by Tim Contributor.
+```''',
+ )
+
+ def test_parse_body_single(self):
+ body, commits = PullRequest.parse_body('''Comment body
+
+----------------------------------------------------------------------
+#### 11aa76f9fc380e9fe06157154f32b304e8dc4749
+```
+[scoping] Bug to fix
+
+Reviewed by Tim Contributor.
+```''')
+ self.assertEqual(body, 'Comment body')
+ self.assertEqual(len(commits), 1)
+ self.assertEqual(commits[0].hash, '11aa76f9fc380e9fe06157154f32b304e8dc4749')
+ self.assertEqual(commits[0].message, '[scoping] Bug to fix\n\nReviewed by Tim Contributor.')