Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py (293556 => 293557)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py 2022-04-28 02:46:27 UTC (rev 293556)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py 2022-04-28 03:03:33 UTC (rev 293557)
@@ -81,6 +81,12 @@
'--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=""
+ )
@classmethod
def create_commit(cls, args, repository, **kwargs):
@@ -173,8 +179,37 @@
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 @@
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))
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py (293556 => 293557)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py 2022-04-28 02:46:27 UTC (rev 293556)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py 2022-04-28 03:03:33 UTC (rev 293557)
@@ -301,7 +301,9 @@
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 @@
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 @@
"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 @@
"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 @@
"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 @@
"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 @@
"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 @@
"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 @@
"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 @@
"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 @@
"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 @@
"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 @@
"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 @@
"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 @@
"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 @@
"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...',
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/revert_unittest.py (293556 => 293557)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/revert_unittest.py 2022-04-28 02:46:27 UTC (rev 293556)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/revert_unittest.py 2022-04-28 03:03:33 UTC (rev 293557)
@@ -72,6 +72,8 @@
"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 @@
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 @@
"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 @@
"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'",