def test_has_changes_in_wpt_looks_at_start_of_string(self): host = MockHost() def run_command_fn(_): return ("something/something.html\n" "something/third_party/WebKit/LayoutTests/imported/wpt/something.html\n") host.executive = MockExecutive2(run_command_fn=run_command_fn) chromium_wpt = ChromiumWPT(host) self.assertFalse(chromium_wpt.has_changes_in_wpt('sha'))
def test_has_changes_in_wpt_does_not_count_expectation_files(self): host = MockHost() def run_command_fn(_): return ("something/something.html\n" "third_party/WebKit/LayoutTests/imported/wpt/something-expected.html\n" "-expected.txt\n") host.executive = MockExecutive2(run_command_fn=run_command_fn) chromium_wpt = ChromiumWPT(host) self.assertFalse(chromium_wpt.has_changes_in_wpt('sha'))
def test_ignores_commits_that_start_with_import(self): host = MockHost() return_vals = [ 'Import rutabaga@deadbeef', # show (message) 'deadbeefcafe', # rev-list 'third_party/WebKit/LayoutTests/imported/wpt', # rev-parse ] host.executive = MockExecutive2(run_command_fn=lambda _: return_vals.pop()) chromium_wpt = ChromiumWPT(host) commits = chromium_wpt.exportable_commits_since('3dadcafe') self.assertEqual(len(commits), 0)
def test_exportable_commits_since(self): host = MockHost() def mock_command(args): git_command = args[1] if git_command == 'rev-list': return 'badbeef8' else: return '' host.executive = MockExecutive2(run_command_fn=mock_command) chromium_wpt = ChromiumWPT(host) commits = chromium_wpt.exportable_commits_since('3dadcafe') self.assertEqual(len(commits), 1)
def main(): configure_logging() parser = argparse.ArgumentParser(description='WPT Sync') parser.add_argument('--no-fetch', action='store_true') options = parser.parse_args() host = Host() # TODO(jeffcarp): the script does not handle reverted changes right now local_wpt = LocalWPT(host, no_fetch=options.no_fetch, use_github=True) chromium_wpt = ChromiumWPT(host) wpt_commit, chromium_commit = local_wpt.most_recent_chromium_commit() if chromium_commit: _log.info('Found last exported WPT commit:') _log.info('- web-platform-tests@%s', wpt_commit) _log.info('- chromium@%s', chromium_commit) else: _log.info('No Chromium export commits found in WPT, stopping.') return _log.info('Finding exportable commits in Chromium since %s...', chromium_commit) exportable_commits = chromium_wpt.exportable_commits_since(chromium_commit) if exportable_commits: _log.info('Found %s exportable commits in chromium:', len(exportable_commits)) for commit in exportable_commits: _log.info('- %s %s', commit, chromium_wpt.subject(commit)) else: _log.info('No exportable commits found in Chromium, stopping.') return for commit in exportable_commits: _log.info('Uploading %s', chromium_wpt.subject(commit)) patch = chromium_wpt.format_patch(commit) message = chromium_wpt.message(commit) try: commit_position = chromium_wpt.commit_position(commit) except ScriptError as exp: _log.error(exp) _log.error('This could mean you have local commits on your chromium branch ' '(That lack a Cr-Commit-Position footer).') # TODO(jeffcarp): include flag that lets you exclude local commits raise assert commit_position message += '\n\nCr-Commit-Position: {}'.format(commit_position) branch_name = 'chromium-try-{}'.format(commit) local_wpt.create_branch_with_patch(branch_name, message, patch) desc_title = chromium_wpt.subject(commit) user = os.environ.get('GH_USER') assert user pr_branch_name = '{}:{}'.format(user, branch_name) github_create_pr(pr_branch_name, desc_title)
def main(): configure_logging() options = parse_args() host = Host() github = GitHub(host) local_wpt = LocalWPT(host, no_fetch=options.no_fetch, use_github=True) chromium_wpt = ChromiumWPT(host) wpt_commit, chromium_commit = local_wpt.most_recent_chromium_commit() assert chromium_commit, 'No Chromium commit found, this is impossible' _log.info('web-platform-tests@%s (%d behind origin/master)', wpt_commit, local_wpt.commits_behind_master(wpt_commit)) _log.info('chromium@%s (%d behind origin/master)', chromium_commit.sha, chromium_commit.num_behind_master()) exportable_commits = chromium_wpt.exportable_commits_since( chromium_commit.sha) if exportable_commits: _log.info('Found %s exportable commits in chromium:', len(exportable_commits)) for commit in exportable_commits: _log.info('- %s %s', commit, chromium_wpt.subject(commit)) else: _log.info('No exportable commits found in Chromium, stopping.') return for commit in exportable_commits: _log.info('Uploading %s', chromium_wpt.subject(commit)) chromium_commit = ChromiumCommit(host, sha=commit) patch = chromium_wpt.format_patch(commit) message = chromium_wpt.message(commit) local_wpt.create_branch_with_patch(branch_name, message, patch) github.create_pr(local_branch_name='chromium-try-{}'.format(commit), desc_title=chromium_commit.subject(), body=chromium_commit.body())
def run(self): # First, poll for an in-flight pull request and merge if exists pull_requests = self.wpt_github.in_flight_pull_requests() if len(pull_requests) == 1: pull_request = pull_requests.pop() _log.info('In-flight PR found: #%d', pull_request['number']) _log.info(pull_request['title']) # TODO(jeffcarp): Check the PR status here if self.dry_run: _log.info('[dry_run] Would have attempted to merge PR') else: _log.info('Merging...') self.wpt_github.merge_pull_request(pull_request['number']) _log.info('PR merged!') elif len(pull_requests) > 1: _log.error(pull_requests) # TODO(jeffcarp): Print links to PRs raise Exception('More than two in-flight PRs!') # Second, look for exportable commits in Chromium # At this point, no in-flight PRs should exist # If there was an issue merging, it should have errored out local_wpt = LocalWPT(self.host, use_github=False) chromium_wpt = ChromiumWPT(self.host) # TODO(jeffcarp): have the script running this fetch Chromium origin/master # TODO(jeffcarp): move WPT fetch out of its constructor to match planned ChromiumWPT pattern wpt_commit, chromium_commit = local_wpt.most_recent_chromium_commit() assert chromium_commit, 'No Chromium commit found, this is impossible' wpt_behind_master = local_wpt.commits_behind_master(wpt_commit) _log.info('\nLast Chromium export commit in web-platform-tests:') _log.info('web-platform-tests@%s', wpt_commit) _log.info('(%d behind web-platform-tests@origin/master)', wpt_behind_master) _log.info('\nThe above WPT commit points to the following Chromium commit:') _log.info('chromium@%s', chromium_commit.sha) _log.info('(%d behind chromium@origin/master)', chromium_commit.num_behind_master()) # TODO(jeffcarp): Have this function return ChromiumCommits exportable_commits = chromium_wpt.exportable_commits_since(chromium_commit.sha) if not exportable_commits: _log.info('No exportable commits found in Chromium, stopping.') return _log.info('Found %d exportable commits in Chromium:', len(exportable_commits)) for commit in exportable_commits: _log.info('- %s %s', commit, chromium_wpt.subject(commit)) outbound_commit = ChromiumCommit(self.host, sha=exportable_commits[0]) _log.info('Picking the earliest commit and creating a PR') _log.info('- %s %s', outbound_commit.sha, outbound_commit.subject()) patch = outbound_commit.format_patch() message = outbound_commit.message() # TODO: now do a test comparison of patch against local WPT if self.dry_run: _log.info('[dry_run] Stopping before creating PR') _log.info('\n\n[dry_run] message:') _log.info(message) _log.info('\n\n[dry_run] patch:') _log.info(patch) return local_branch_name = local_wpt.create_branch_with_patch(message, patch) response_data = self.wpt_github.create_pr( local_branch_name=local_branch_name, desc_title=outbound_commit.subject(), body=outbound_commit.body()) _log.info('Create PR response: %s', response_data)