Skip to content

Commit

Permalink
Cherry-pick 275336@main (b5b2c45). rdar://122033841
Browse files Browse the repository at this point in the history
    [git-webkit revert] Should have an option to utilize landing with --unsafe
    https://bugs.webkit.org/show_bug.cgi?id=268729
    rdar://problem/122033841

    Reviewed by Jonathan Bedard.

    Adds arguments from git-webkit land to automatically land reverts with --safe and --unsafe.

    * Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/revert.py:
    (Revert.parser):
    (Revert.get_issue_info):
    (Revert.main):
    * Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/revert_unittest.py:
    (TestRevert):
    (TestRevert.webserver):
    (test_land_safe):
    (test_land_unsafe):

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

Canonical link: https://commits.webkit.org/272448.630@safari-7618-branch
  • Loading branch information
briannafan authored and JonWBedard committed Feb 27, 2024
1 parent 8410c23 commit de5a584
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .branch import Branch
from .pull_request import PullRequest
from .commit import Commit as CommitProgram
from .land import Land

from webkitbugspy import Tracker, bugzilla, radar
from webkitcorepy import arguments, run, Terminal, string_utils
Expand All @@ -44,20 +45,18 @@ class Revert(Command):

@classmethod
def parser(cls, parser, loggers=None):
PullRequest.parser(parser, loggers=loggers)
Land.parser(parser, loggers=loggers)
parser.add_argument(
'commit_id',
nargs='+',
help='git hash, svn revision or identifier of commits to revert'
)

parser.add_argument(
'--reason', '--why', '-w',
dest='reason',
type=str,
help='Reason for the revert'
)

parser.add_argument(
'--pr', '--no-pr',
default=True,
Expand Down Expand Up @@ -292,6 +291,9 @@ def main(cls, args, repository, **kwargs):
if cls.relate_issues(args, repository, issue, commit_issues, revert_reason):
return 1

if args.safe is not None and args.pr:
return Land.main(args, repository, identifier_template=None, canonical_svn=False, hooks=None)

if args.pr:
return PullRequest.create_pull_request(repository, args, branch_point)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

import logging
import os
import time

from mock import patch
from webkitbugspy import bugzilla, mocks as bmocks, radar, Tracker
from webkitcorepy import OutputCapture, testing
from webkitscmpy import local, program, mocks
from webkitscmpy import local, program, mocks, Contributor, Commit
from webkitcorepy.mocks import Time as MockTime, Terminal as MockTerminal, Environment


Expand All @@ -40,6 +41,48 @@ def setUp(self):
os.mkdir(os.path.join(self.path, '.git'))
os.mkdir(os.path.join(self.path, '.svn'))

@classmethod
def webserver(cls, approved=None, labels=None, environment=None):
result = mocks.remote.GitHub(labels=labels, environment=environment)
result.users.create('Ricky Reviewer', 'rreviewer', ['rreviewer@webkit.org'])
result.users.create('Tim Contributor', 'tcontributor', ['tcontributor@webkit.org'])
result.issues = {
1: dict(
number=1,
opened=True,
title='Unreviewed, reverting 5@main',
description='?',
creator=result.users.create(name='Tim Contributor', username='tcontributor'),
timestamp=1639536160,
assignee=None,
comments=[],
),
}
result.pull_requests = [dict(
number=1,
state='open',
title='Unreviewed, reverting 5@main',
user=dict(login='tcontributor'),
body='''#### a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd
<pre>
To Be Committed
Reviewed by NOBODY (OOPS!).
</pre>
''',
head=dict(ref='username:eng/example'),
base=dict(ref='main'),
requested_reviews=[dict(login='rreviewer')],
reviews=[
dict(user=dict(login='rreviewer'), state='APPROVED')
] if approved else [] + [
dict(user=dict(login='rreviewer'), state='CHANGES_REQUESTED')
] if approved is not None else [], _links=dict(
issue=dict(href='https://{}/issues/1'.format(result.api_remote)),
), draft=False,
)]
return result

def test_github(self):
with MockTerminal.input('{}/show_bug.cgi?id=2'.format(self.BUGZILLA)), OutputCapture(level=logging.INFO) as captured, mocks.remote.GitHub() as remote, mocks.local.Git(
self.path, remote='https://{}'.format(remote.remote),
Expand Down Expand Up @@ -309,3 +352,97 @@ def test_pr(self):
"Created 'PR 1 | Unreviewed, reverting 5@main'!\n"
"https://github.example.com/WebKit/WebKit/pull/1\n"
)

def test_land_safe(self):
with OutputCapture(level=logging.INFO) as captured, MockTerminal.input('y', 'n'), self.webserver(
approved=True, labels={'merge-queue': dict(color='3AE653', description="Send PR to merge-queue")},
environment=Environment(
GITHUB_EXAMPLE_COM_USERNAME='tcontributor',
GITHUB_EXAMPLE_COM_TOKEN='token',
),
) as remote, mocks.local.Svn(), mocks.local.Git(
self.path, remote='https://{}'.format(remote.remote),
remotes=dict(fork='https://{}/Contributor/WebKit'.format(remote.hosts[0])),
) as repo, bmocks.Bugzilla(
self.BUGZILLA.split('://')[-1],
issues=bmocks.ISSUES,
environment=Environment(
BUGS_EXAMPLE_COM_USERNAME='tcontributor@example.com',
BUGS_EXAMPLE_COM_PASSWORD='password',
)
), patch('webkitbugspy.Tracker._trackers', [bugzilla.Tracker(self.BUGZILLA)]):

result = program.main(
args=('revert', 'd8bce26fa65c6fc8f39c17927abb77f69fab82fc', '--issue', '{}/show_bug.cgi?id=1'.format(self.BUGZILLA), '-v', '--safe'),
path=self.path,
)
self.assertEqual(0, result)

log = captured.root.log.getvalue().splitlines()
self.assertEqual(
[line for line in log if 'Mock process' not in line], [
"Creating the local development branch 'eng/Example-issue-1'...",
'Reverted 5@main',
'Automatically relating issues...',
'Using committed changes...',
'Detected merging automation, using that instead of local git tooling',
"Rebasing 'eng/Example-issue-1' on 'main'...",
"Rebased 'eng/Example-issue-1' on 'main!'",
'Running pre-PR checks...',
'No pre-PR checks to run',
'Checking if PR already exists...',
'PR not found.',
"Updating 'main' on 'https://github.example.com/Contributor/WebKit'",
"Pushing 'eng/Example-issue-1' to 'fork'...",
"Creating 'eng/Example-issue-1-1' as a reference branch",
"Creating pull-request for 'eng/Example-issue-1'...",
"Adding 'merge-queue' to 'PR 2 | Unreviewed, reverting 5@main'",
],
)

def test_land_unsafe(self):
with OutputCapture(level=logging.INFO) as captured, MockTerminal.input('y', 'n'), self.webserver(
approved=True, labels={'merge-queue': dict(color='3AE653', description="Send PR to merge-queue"), 'unsafe-merge-queue': dict(color='3AE653', description="Send PR to unsafe-merge-queue")},
environment=Environment(
GITHUB_EXAMPLE_COM_USERNAME='tcontributor',
GITHUB_EXAMPLE_COM_TOKEN='token',
),
) as remote, mocks.local.Svn(), mocks.local.Git(
self.path, remote='https://{}'.format(remote.remote),
remotes=dict(fork='https://{}/Contributor/WebKit'.format(remote.hosts[0])),
) as repo, bmocks.Bugzilla(
self.BUGZILLA.split('://')[-1],
issues=bmocks.ISSUES,
environment=Environment(
BUGS_EXAMPLE_COM_USERNAME='tcontributor@example.com',
BUGS_EXAMPLE_COM_PASSWORD='password',
)
), patch('webkitbugspy.Tracker._trackers', [bugzilla.Tracker(self.BUGZILLA)]):

result = program.main(
args=('revert', 'd8bce26fa65c6fc8f39c17927abb77f69fab82fc', '--issue', '{}/show_bug.cgi?id=1'.format(self.BUGZILLA), '-v', '--unsafe'),
path=self.path,
)
self.assertEqual(0, result)

log = captured.root.log.getvalue().splitlines()
self.assertEqual(
[line for line in log if 'Mock process' not in line], [
"Creating the local development branch 'eng/Example-issue-1'...",
'Reverted 5@main',
'Automatically relating issues...',
'Using committed changes...',
'Detected merging automation, using that instead of local git tooling',
"Rebasing 'eng/Example-issue-1' on 'main'...",
"Rebased 'eng/Example-issue-1' on 'main!'",
'Running pre-PR checks...',
'No pre-PR checks to run',
'Checking if PR already exists...',
'PR not found.',
"Updating 'main' on 'https://github.example.com/Contributor/WebKit'",
"Pushing 'eng/Example-issue-1' to 'fork'...",
"Creating 'eng/Example-issue-1-1' as a reference branch",
"Creating pull-request for 'eng/Example-issue-1'...",
"Adding 'unsafe-merge-queue' to 'PR 2 | Unreviewed, reverting 5@main'",
],
)

0 comments on commit de5a584

Please sign in to comment.