Skip to content
Permalink
Browse files
[git-webkit] Run style checker
https://bugs.webkit.org/show_bug.cgi?id=239730
<rdar://problem/92428565>

Reviewed by Chris Dumez.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git): Add webkitscmpy.auto-check option.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
(PullRequest.parser): Add --check/--no-check flag.
(PullRequest.pre_pr_checks): Find and run all pre-PR checks.
(PullRequest.create_pull_request): Run PR checks.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/revert_unittest.py:
* metadata/git_config_extension: Add style-checker as pre-pr check.

Canonical link: https://commits.webkit.org/250071@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293557 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed Apr 28, 2022
1 parent d7b41b7 commit 98456647008e0c4a1d0e3aba8b9df69905ca013c
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 5 deletions.
@@ -1,3 +1,13 @@
2022-04-27 Jonathan Bedard <jbedard@apple.com>

[git-webkit] Run style checker
https://bugs.webkit.org/show_bug.cgi?id=239730
<rdar://problem/92428565>

Reviewed by Chris Dumez.

* metadata/git_config_extension: Add style-checker as pre-pr check.

2022-04-26 Michael Catanzaro <mcatanzaro@redhat.com>

Unreviewed, add my @redhat.com email
@@ -1,3 +1,22 @@
2022-04-27 Jonathan Bedard <jbedard@apple.com>

[git-webkit] Run style checker
https://bugs.webkit.org/show_bug.cgi?id=239730
<rdar://problem/92428565>

Reviewed by Chris Dumez.

* Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git): Add webkitscmpy.auto-check option.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
(PullRequest.parser): Add --check/--no-check flag.
(PullRequest.pre_pr_checks): Find and run all pre-PR checks.
(PullRequest.create_pull_request): Run PR checks.
* Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:
* Scripts/libraries/webkitscmpy/webkitscmpy/test/revert_unittest.py:

2022-04-27 Jonathan Bedard <jbedard@apple.com>

[git-webkit] Cleanup PRs on alternate remotes
@@ -29,7 +29,7 @@ def readme():

setup(
name='webkitscmpy',
version='4.11.4',
version='4.12.0',
description='Library designed to interact with git and svn repositories.',
long_description=readme(),
classifiers=[
@@ -46,7 +46,7 @@ def _maybe_add_webkitcorepy_path():
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)

version = Version(4, 11, 4)
version = Version(4, 12, 0)

AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('jinja2', Version(2, 11, 3)))
@@ -308,6 +308,7 @@ def to_identifier(self, hash=None, revision=None, populate=True, branch=None):
'webkitscmpy.pull-request': ['overwrite', 'append'],
'webkitscmpy.history': ['when-user-owned', 'disabled', 'always', 'never'],
'webkitscmpy.update-fork': ['true', 'false'],
'webkitscmpy.auto-check': ['true', 'false'],
}
CONFIG_LOCATIONS = ['global', 'repository', 'project']

@@ -81,6 +81,12 @@ def parser(cls, parser, loggers=None):
'--remote', dest='remote', type=str, default=None,
help='Make a pull request against a specific remote',
)
parser.add_argument(
'--checks', '--no-checks',
dest='checks', default=None,
help='Explicitly enable or disable automatic pre-flight checks',
action=arguments.NoAction,
)

@classmethod
def create_commit(cls, args, repository, **kwargs):
@@ -172,9 +178,38 @@ def find_existing_pull_request(cls, repository, remote):
break
return existing_pr

@classmethod
def pre_pr_checks(cls, repository):
num_checks = 0
log.info('Running pre-PR checks...')
for key, path in repository.config().items():
if not key.startswith('webkitscmpy.pre-pr.'):
continue
num_checks += 1
name = key.split('.')[-1]
log.info(' Running {}...'.format(name))
command = run(path.split(' '), cwd=repository.root_path)
if command.returncode:
if Terminal.choose(
'{} failed, continue uploading pull request?'.format(name),
default='No',
) == 'No':
sys.stderr.write('Pre-PR check {} failed\n'.format(name))
return False
else:
log.info(' {} failed, continuing PR upload anyway'.format(name))
else:
log.info(' Ran {}!'.format(name))

if num_checks:
log.info('All pre-PR checks run!')
else:
log.info('No pre-PR checks to run')
return True

@classmethod
def create_pull_request(cls, repository, args, branch_point):
# FIXME: We can do better by infering the remote from the branch point, if it's not specified
# FIXME: We can do better by inferring the remote from the branch point, if it's not specified
source_remote = args.remote or 'origin'
if not repository.config().get('remote.{}.url'.format(source_remote)):
sys.stderr.write("'{}' is not a remote in this repository\n".format(source_remote))
@@ -191,6 +226,12 @@ def create_pull_request(cls, repository, args, branch_point):
else:
branch_point = Branch.branch_point(repository)

if args.checks is None:
args.checks = repository.config().get('webkitscmpy.auto-check', 'false') == 'true'
if args.checks and not cls.pre_pr_checks(repository):
sys.stderr.write('Checks have failed, aborting pull request.\n')
return 1

remote_repo = repository.remote(name=source_remote)
if not remote_repo:
sys.stderr.write("'{}' doesn't have a recognized remote\n".format(repository.root_path))
@@ -301,7 +301,9 @@ def test_staged(self):
Creating commit...
Rebasing 'eng/pr-branch' on 'main'...
Rebased 'eng/pr-branch' on 'main!'
Found 1 commit...""")
Found 1 commit...
Running pre-PR checks...
No pre-PR checks to run""")
self.assertEqual(captured.stdout.getvalue(), "Created the local development branch 'eng/pr-branch'\n")
self.assertEqual(captured.stderr.getvalue(), "'{}' doesn't have a recognized remote\n".format(self.path))

@@ -325,7 +327,9 @@ def test_modified(self):
Creating commit...
Rebasing 'eng/pr-branch' on 'main'...
Rebased 'eng/pr-branch' on 'main!'
Found 1 commit...""")
Found 1 commit...
Running pre-PR checks...
No pre-PR checks to run""")

def test_github(self):
with OutputCapture(level=logging.INFO) as captured, mocks.remote.GitHub() as remote, mocks.local.Git(
@@ -356,6 +360,8 @@ def test_github(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'fork'...",
"Syncing 'main' to remote 'fork'",
"Creating pull-request for 'eng/pr-branch'...",
@@ -391,6 +397,8 @@ def test_github_draft(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'fork'...",
"Syncing 'main' to remote 'fork'",
"Creating pull-request for 'eng/pr-branch'...",
@@ -438,6 +446,8 @@ def test_github_update(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Checking PR labels for 'merging-blocked'...",
"Removing 'merging-blocked' from PR 1...",
"Pushing 'eng/pr-branch' to 'fork'...",
@@ -480,6 +490,8 @@ def test_github_append(self):
"Rebased 'eng/pr-branch' on 'main!'",
' Found 1 commit...',
' Found 2 commits...',
'Running pre-PR checks...',
'No pre-PR checks to run',
"Checking PR labels for 'merging-blocked'...",
"Pushing 'eng/pr-branch' to 'fork'...",
"Syncing 'main' to remote 'fork'",
@@ -527,6 +539,8 @@ def test_github_reopen(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Checking PR labels for 'merging-blocked'...",
"Pushing 'eng/pr-branch' to 'fork'...",
"Syncing 'main' to remote 'fork'",
@@ -586,6 +600,8 @@ def test_github_bugzilla(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'fork'...",
"Syncing 'main' to remote 'fork'",
"Creating pull-request for 'eng/pr-branch'...",
@@ -645,6 +661,8 @@ def test_github_reopen_bugzilla(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'fork'...",
"Syncing 'main' to remote 'fork'",
"Creating pull-request for 'eng/pr-branch'...",
@@ -683,6 +701,8 @@ def test_bitbucket(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'origin'...",
"Creating pull-request for 'eng/pr-branch'...",
],
@@ -716,6 +736,8 @@ def test_bitbucket_draft(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'origin'...",
],
)
@@ -752,6 +774,8 @@ def test_bitbucket_update(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'origin'...",
"Updating pull-request for 'eng/pr-branch'...",
],
@@ -790,6 +814,8 @@ def test_bitbucket_append(self):
"Rebased 'eng/pr-branch' on 'main!'",
' Found 1 commit...',
' Found 2 commits...',
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'origin'...",
"Updating pull-request for 'eng/pr-branch'...",
],
@@ -834,6 +860,8 @@ def test_bitbucket_reopen(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'origin'...",
"Updating pull-request for 'eng/pr-branch'...",
],
@@ -878,6 +906,8 @@ def test_bitbucket_radar(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'origin'...",
"Creating pull-request for 'eng/pr-branch'...",
'Checking issue assignee...',
@@ -925,6 +955,8 @@ def test_bitbucket_reopen_radar(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'origin'...",
"Creating pull-request for 'eng/pr-branch'...",
'Checking issue assignee...',
@@ -72,6 +72,8 @@ def test_github(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'fork'...",
"Syncing 'main' to remote 'fork'",
"Creating pull-request for 'eng/pr-branch'...",
@@ -104,6 +106,7 @@ def test_modified(self):
self.assertEqual(captured.stderr.getvalue(), 'Please commit your changes or stash them before you revert commit: d8bce26fa65c6fc8f39c17927abb77f69fab82fc')

def test_update(self):
self.maxDiff = None
with OutputCapture(level=logging.INFO) as captured, mocks.remote.GitHub() as remote, mocks.local.Git(
self.path, remote='https://{}'.format(remote.remote),
remotes=dict(fork='https://{}/Contributor/WebKit'.format(remote.hosts[0])),
@@ -138,6 +141,8 @@ def test_update(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
'Running pre-PR checks...',
'No pre-PR checks to run',
"Pushing 'eng/pr-branch' to 'fork'...",
"Syncing 'main' to remote 'fork'",
"Creating 'eng/pr-branch-1' as a reference branch",
@@ -148,6 +153,8 @@ def test_update(self):
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
' Found 1 commit...',
'Running pre-PR checks...',
'No pre-PR checks to run',
"Checking PR labels for 'merging-blocked'...",
"Pushing 'eng/pr-branch' to 'fork'...",
"Syncing 'main' to remote 'fork'",
@@ -4,6 +4,9 @@
pull-request = append
history = disabled
update-fork = true
auto-check = true
[webkitscmpy "remotes"]
origin = git@github.com:WebKit/WebKit.git
apple = git@github.com:apple/WebKit.git
[webkitscmpy "pre-pr"]
style-checker = python3 Tools/Scripts/check-webkit-style

0 comments on commit 9845664

Please sign in to comment.