⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 285733 in webkit


Ignore:
Timestamp:
Nov 12, 2021, 11:13:03 AM (5 years ago)
Author:
Jonathan Bedard
Message:

[git-webkit] Open closed pull-request when running pr
https://bugs.webkit.org/show_bug.cgi?id=232765
<rdar://problem/85084318>

Reviewed by Dewei Zhu.

  • Scripts/libraries/webkitscmpy/webkitscmpy/mocks/remote/bitbucket.py:

(BitBucket.request): Ensure displayId is set when updating PR.

  • Scripts/libraries/webkitscmpy/webkitscmpy/mocks/remote/git_hub.py:

(GitHub.request): Make sure that new pull-requests are open.

  • Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:

(PullRequest.main): Open closed pull-requests.

  • Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py:

(GitHub.PRGenerator.update): Only set head if user specifies head.

  • Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:

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

Location:
trunk/Tools
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r285731 r285733  
     12021-11-05  Jonathan Bedard  <jbedard@apple.com>
     2
     3        [git-webkit] Open closed pull-request when running pr
     4        https://bugs.webkit.org/show_bug.cgi?id=232765
     5        <rdar://problem/85084318>
     6
     7        Reviewed by Dewei Zhu.
     8
     9        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
     10        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
     11        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/remote/bitbucket.py:
     12        (BitBucket.request): Ensure displayId is set when updating PR.
     13        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/remote/git_hub.py:
     14        (GitHub.request): Make sure that new pull-requests are open.
     15        * Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
     16        (PullRequest.main): Open closed pull-requests.
     17        * Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py:
     18        (GitHub.PRGenerator.update): Only set head if user specifies head.
     19        * Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:
     20
    1212021-11-12  Chris Dumez  <cdumez@apple.com>
    222
  • trunk/Tools/Scripts/libraries/webkitcorepy/setup.py

    r283843 r285733  
    3131setup(
    3232    name='webkitcorepy',
    33     version='0.11.3',
     33    version='0.11.4',
    3434    description='Library containing various Python support classes and functions.',
    3535    long_description=readme(),
  • trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py

    r283843 r285733  
    4444from webkitcorepy.file_lock import FileLock
    4545
    46 version = Version(0, 11, 3)
     46version = Version(0, 11, 4)
    4747
    4848from webkitcorepy.autoinstall import Package, AutoInstall
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/remote/bitbucket.py

    r284892 r285733  
    222222            json['participants'] = [json['author']]
    223223            json['id'] = 1 + max([0] + [pr.get('id', 0) for pr in self.pull_requests])
    224             json['fromRef']['displayId'] = json['fromRef']['id'].split('/')[-2:]
    225             json['toRef']['displayId'] = json['toRef']['id'].split('/')[-2:]
     224            json['fromRef']['displayId'] = '/'.join(json['fromRef']['id'].split('/')[-2:])
     225            json['toRef']['displayId'] = '/'.join(json['toRef']['id'].split('/')[-2:])
    226226            json['state'] = 'OPEN'
    227227            json['activities'] = []
     
    241241            if method == 'PUT':
    242242                self.pull_requests[existing].update(json)
     243                self.pull_requests[existing]['fromRef']['displayId'] = '/'.join(json['fromRef']['id'].split('/')[-2:])
     244                self.pull_requests[existing]['toRef']['displayId'] = '/'.join(json['toRef']['id'].split('/')[-2:])
    243245            if len(split_url) < 11:
    244246                return mocks.Response.fromJson({key: value for key, value in self.pull_requests[existing].items() if key != 'activities'})
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/remote/git_hub.py

    r285035 r285733  
    409409        if method == 'POST' and auth and stripped_url == pr_base:
    410410            pr['number'] = 1 + max([0] + [pr.get('number', 0) for pr in self.pull_requests])
     411            pr['state'] = 'open'
    411412            pr['user'] = dict(login=auth.username)
    412413            pr['_links'] = dict(issue=dict(href='https://{}/issues/{}'.format(self.api_remote, pr['number'])))
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py

    r285158 r285733  
    2727from .branch import Branch
    2828
    29 from webkitcorepy import arguments, run
     29from webkitcorepy import arguments, run, Terminal
    3030from webkitscmpy import local, log, remote
    3131
     
    5050            help='Rebase (or do not rebase) the pull-request on the source branch before pushing',
    5151            action=arguments.NoAction,
     52        )
     53        parser.add_argument(
     54            '--defaults', '--no-defaults', action=arguments.NoAction, default=None,
     55            help='Do not prompt the user for defaults, always use (or do not use) them',
    5256        )
    5357
     
    131135            sys.stderr.write("'{}' cannot generate pull-requests\n".format(rmt.url))
    132136            return 1
    133         candidates = list(rmt.pull_requests.find(opened=None, head=repository.branch))
     137        existing_pr = None
     138        for pr in rmt.pull_requests.find(opened=None, head=repository.branch):
     139            existing_pr = pr
     140            if existing_pr.opened:
     141                continue
     142        if existing_pr and not existing_pr.opened and not args.defaults and (args.defaults is False or Terminal.choose(
     143            "'{}' is already associated with '{}', which is closed.\nWould you like to create a new pull-request?".format(
     144                repository.branch, existing_pr,
     145            ), default='No',
     146        ) == 'Yes'):
     147            existing_pr = None
    134148        commits = list(repository.commits(begin=dict(hash=branch_point.hash), end=dict(branch=repository.branch)))
    135149
    136         if candidates:
     150        if existing_pr:
    137151            log.warning("Updating pull-request for '{}'...".format(repository.branch))
    138152            pr = rmt.pull_requests.update(
    139                 pull_request=candidates[0],
     153                pull_request=existing_pr,
    140154                title=cls.title_for(commits),
    141155                commits=commits,
    142156                base=branch_point.branch,
    143157                head=repository.branch,
     158                opened=None if existing_pr.opened else True
    144159            )
    145160            if not pr:
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py

    r285142 r285733  
    128128                title=title or pull_request.title,
    129129                base=base or pull_request.base,
    130                 head='{}:{}'.format(user, head) if head else pull_request.head,
    131             )
     130            )
     131            if head:
     132                updates['head'] = '{}:{}'.format(user, head)
    132133            if body or commits:
    133134                updates['body'] = PullRequest.create_body(body, commits)
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py

    r285142 r285733  
    2626
    2727from webkitcorepy import OutputCapture, testing
    28 from webkitscmpy import Contributor, Commit, PullRequest, program, mocks, remote
     28from webkitcorepy.mocks import Terminal as MockTerminal
     29from webkitscmpy import Contributor, Commit, PullRequest, local, program, mocks, remote
    2930
    3031
     
    146147
    147148    def test_parse_html_body_multiple(self):
    148         self.maxDiff = None
    149149        body, commits = PullRequest.parse_body('''#### 11aa76f9fc380e9fe06157154f32b304e8dc4749
    150150<pre>
     
    359359        self.assertEqual(captured.stderr.getvalue(), '')
    360360        log = captured.root.log.getvalue().splitlines()
    361         self.maxDiff = None
     361        self.assertEqual(
     362            [line for line in log if 'Mock process' not in line], [
     363                "Amending commit...",
     364                '    Found 1 commit...',
     365                "Rebasing 'eng/pr-branch' on 'main'...",
     366                "Rebased 'eng/pr-branch' on 'main!'",
     367                "    Found 1 commit...",
     368                "Pushing 'eng/pr-branch' to 'fork'...",
     369                "Updating pull-request for 'eng/pr-branch'...",
     370                "Updated 'PR 1 | Amended commit'!",
     371            ],
     372        )
     373
     374    def test_github_reopen(self):
     375        with mocks.remote.GitHub() as remote, mocks.local.Git(self.path, remote='https://{}'.format(remote.remote)) as repo, mocks.local.Svn():
     376            with OutputCapture():
     377                repo.staged['added.txt'] = 'added'
     378                self.assertEqual(0, program.main(
     379                    args=('pull-request', '-i', 'pr-branch'),
     380                    path=self.path,
     381                ))
     382
     383            local.Git(self.path).remote().pull_requests.get(1).close()
     384            self.assertFalse(local.Git(self.path).remote().pull_requests.get(1).opened)
     385
     386            with OutputCapture() as captured, MockTerminal.input('n'):
     387                repo.staged['added.txt'] = 'diff'
     388                self.assertEqual(0, program.main(
     389                    args=('pull-request',),
     390                    path=self.path,
     391                ))
     392
     393            self.assertTrue(local.Git(self.path).remote().pull_requests.get(1).opened)
     394
     395        self.assertEqual(captured.stderr.getvalue(), '')
     396        log = captured.root.log.getvalue().splitlines()
    362397        self.assertEqual(
    363398            [line for line in log if 'Mock process' not in line], [
     
    417452                    path=self.path,
    418453                ))
     454
     455        self.assertEqual(captured.stderr.getvalue(), '')
     456        log = captured.root.log.getvalue().splitlines()
     457        self.assertEqual(
     458            [line for line in log if 'Mock process' not in line], [
     459                "Amending commit...",
     460                '    Found 1 commit...',
     461                "Rebasing 'eng/pr-branch' on 'main'...",
     462                "Rebased 'eng/pr-branch' on 'main!'",
     463                "    Found 1 commit...",
     464                "Pushing 'eng/pr-branch' to 'origin'...",
     465                "Updating pull-request for 'eng/pr-branch'...",
     466                "Updated 'PR 1 | Amended commit'!",
     467            ],
     468        )
     469
     470    def test_bitbucket_reopen(self):
     471        with mocks.remote.BitBucket() as remote, mocks.local.Git(self.path, remote='ssh://git@{}/{}/{}.git'.format(
     472            remote.hosts[0], remote.project.split('/')[1], remote.project.split('/')[3],
     473        )) as repo, mocks.local.Svn():
     474            with OutputCapture():
     475                repo.staged['added.txt'] = 'added'
     476                self.assertEqual(0, program.main(
     477                    args=('pull-request', '-i', 'pr-branch'),
     478                    path=self.path,
     479                ))
     480
     481            local.Git(self.path).remote().pull_requests.get(1).close()
     482            self.assertFalse(local.Git(self.path).remote().pull_requests.get(1).opened)
     483
     484            with OutputCapture() as captured, MockTerminal.input('n'):
     485                repo.staged['added.txt'] = 'diff'
     486                self.assertEqual(0, program.main(
     487                    args=('pull-request',),
     488                    path=self.path,
     489                ))
     490
     491            self.assertTrue(local.Git(self.path).remote().pull_requests.get(1).opened)
    419492
    420493        self.assertEqual(captured.stderr.getvalue(), '')
Note: See TracChangeset for help on using the changeset viewer.