Exemplo n.º 1
0
    def test_create_branch_with_patch(self):
        host = MockHost()
        host.filesystem = MockFileSystem()

        local_wpt = LocalWPT(host)
        local_wpt.fetch()

        local_branch_name = local_wpt.create_branch_with_patch(
            'message', 'patch', 'author')
        self.assertEqual(local_branch_name, 'chromium-export-try')
        self.assertEqual(
            host.executive.calls,
            [[
                'git', 'clone',
                'https://chromium.googlesource.com/external/w3c/web-platform-tests.git',
                '/tmp/wpt'
            ], ['git', 'remote'],
             [
                 'git', 'remote', 'add', 'github',
                 '[email protected]:w3c/web-platform-tests.git'
             ], ['git', 'reset', '--hard', 'HEAD'], ['git', 'clean', '-fdx'],
             ['git', 'checkout', 'origin/master'], ['git', 'branch', '-a'],
             ['git', 'branch', '-a'],
             ['git', 'checkout', '-b', 'chromium-export-try'],
             ['git', 'apply', '-'],
             ['git', 'commit', '--author', 'author', '-am', 'message'],
             ['git', 'push', 'github', 'chromium-export-try']])
Exemplo n.º 2
0
    def test_fetch_when_wpt_dir_does_not_exist(self):
        host = MockHost()
        local_wpt = LocalWPT(host, 'token')
        local_wpt.fetch()

        self.assertEqual(host.executive.calls, [
            ['git', 'clone', 'https://[email protected]/w3c/web-platform-tests.git', '/tmp/wpt'],
        ])
Exemplo n.º 3
0
    def test_last_wpt_exported_commit_not_found(self):
        host = MockHost()
        host.executive = MockExecutive(run_command_fn=lambda _: '')
        host.filesystem = MockFileSystem()
        local_wpt = LocalWPT(host, 'token')

        commit = local_wpt.most_recent_chromium_commit()
        self.assertEqual(commit, (None, None))
Exemplo n.º 4
0
    def test_create_branch_with_patch(self):
        host = MockHost()
        host.filesystem = MockFileSystem()

        local_wpt = LocalWPT(host)

        local_wpt.create_branch_with_patch('branch-name', 'message', 'patch')
        self.assertEqual(len(host.executive.calls), 9)
Exemplo n.º 5
0
    def test_seek_change_id(self):
        host = MockHost()
        local_wpt = LocalWPT(host, 'token')

        local_wpt.seek_change_id('Ifake-change-id')
        self.assertEqual(
            host.executive.calls,
            [['git', 'log', '-1', '--grep', '^Change-Id: Ifake-change-id']])
Exemplo n.º 6
0
    def test_last_wpt_exported_commit_not_found(self):
        host = MockHost()
        host.executive = MockExecutive2(run_command_fn=lambda _: None)
        host.filesystem = MockFileSystem()
        local_wpt = LocalWPT(host)

        commit = local_wpt.most_recent_chromium_commit()
        self.assertEqual(commit, (None, None))
Exemplo n.º 7
0
    def test_create_branch_with_patch(self):
        host = MockHost()
        host.filesystem = MockFileSystem()

        local_wpt = LocalWPT(host)

        local_wpt.create_branch_with_patch('branch-name', 'message', 'patch')
        self.assertEqual(len(host.executive.calls), 9)
Exemplo n.º 8
0
    def test_run(self):
        host = MockHost()
        host.filesystem = MockFileSystem()

        local_wpt = LocalWPT(host)

        local_wpt.run(['echo', 'rutabaga'])
        self.assertEqual(len(host.executive.calls), 2)
        self.assertEqual(host.executive.calls[1], ['echo', 'rutabaga'])
Exemplo n.º 9
0
    def __init__(self, host, gh_user, gh_token, gerrit_user, gerrit_token, dry_run=False):
        self.host = host
        self.wpt_github = WPTGitHub(host, gh_user, gh_token, pr_history_window=PR_HISTORY_WINDOW)

        self.gerrit = GerritAPI(self.host, gerrit_user, gerrit_token)

        self.dry_run = dry_run
        self.local_wpt = LocalWPT(self.host, gh_token)
        self.local_wpt.fetch()
Exemplo n.º 10
0
    def test_seek_commit_position(self):
        host = MockHost()
        local_wpt = LocalWPT(host, 'token')

        local_wpt.seek_commit_position('refs/heads/master@{12345}')
        self.assertEqual(host.executive.calls, [[
            'git', 'log', '-1', '--grep',
            '^Cr-Commit-Position: refs/heads/master@{12345}'
        ]])
Exemplo n.º 11
0
    def test_run(self):
        host = MockHost()
        host.filesystem = MockFileSystem()

        local_wpt = LocalWPT(host)

        local_wpt.run(['echo', 'rutabaga'])
        self.assertEqual(len(host.executive.calls), 2)
        self.assertEqual(host.executive.calls[1], ['echo', 'rutabaga'])
Exemplo n.º 12
0
    def test_fetch_when_wpt_dir_does_not_exist(self):
        host = MockHost()
        host.filesystem = MockFileSystem()

        local_wpt = LocalWPT(host)
        local_wpt.fetch()

        self.assertEqual(len(host.executive.calls), 3)
        self.assertEqual(host.executive.calls[0][1], 'clone')
Exemplo n.º 13
0
    def test_create_branch_with_patch(self):
        host = MockHost()
        host.filesystem = MockFileSystem()

        local_wpt = LocalWPT(host)

        local_branch_name = local_wpt.create_branch_with_patch('message', 'patch')
        self.assertEqual(len(host.executive.calls), 9)
        self.assertEqual(local_branch_name, 'chromium-export-try')
Exemplo n.º 14
0
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)
Exemplo n.º 15
0
 def test_apply_exportable_commits_locally_returns_none_on_failure(self):
     host = MockHost()
     wpt_github = MockWPTGitHub(pull_requests=[])
     importer = TestImporter(host, wpt_github=wpt_github)
     commit = MockChromiumCommit(host, subject='My fake commit')
     importer.exportable_but_not_exported_commits = lambda _: [commit]
     local_wpt = LocalWPT(host)
     local_wpt.apply_patch = lambda _: 'Failed'  # Failure to apply patch.
     applied = importer.apply_exportable_commits_locally(local_wpt)
     self.assertIsNone(applied)
Exemplo n.º 16
0
    def test_fetch_when_wpt_dir_exists(self):
        host = MockHost()
        host.filesystem = MockFileSystem(files={'/tmp/wpt': ''})

        local_wpt = LocalWPT(host, 'token')
        local_wpt.fetch()

        self.assertEqual(host.executive.calls, [
            ['git', 'fetch', 'origin'],
            ['git', 'checkout', 'origin/master'],
        ])
Exemplo n.º 17
0
    def test_test_patch_error(self):
        def _run_fn(args):
            if args[0] == 'git' and args[1] == 'apply':
                raise ScriptError('MOCK failed applying patch')
            return ''

        host = MockHost()
        host.executive = MockExecutive(run_command_fn=_run_fn)
        local_wpt = LocalWPT(host, 'token')

        self.assertEqual(local_wpt.test_patch('dummy patch'), (False, 'MOCK failed applying patch'))
Exemplo n.º 18
0
    def test_last_wpt_exported_commit(self):
        host = MockHost()
        return_vals = [
            '123',
            '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8',
        ]
        host.executive = MockExecutive2(run_command_fn=lambda _: return_vals.pop())
        host.filesystem = MockFileSystem()
        local_wpt = LocalWPT(host, no_fetch=True)

        commit = local_wpt.most_recent_chromium_commit()
        self.assertEqual(commit, ('9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8', '123'))
Exemplo n.º 19
0
    def test_is_commit_affecting_directory(self):
        host = MockHost()
        # return_exit_code=True is passed to run() in the method under test,
        # so the mock return value should be exit code instead of output.
        host.executive = mock_git_commands({'diff-tree': 1}, strict=True)
        local_wpt = LocalWPT(host, 'token')

        self.assertTrue(local_wpt.is_commit_affecting_directory(
            'HEAD', 'css/'))
        self.assertEqual(host.executive.calls, [[
            'git', 'diff-tree', '--quiet', '--no-commit-id', 'HEAD', '--',
            'css/'
        ]])
Exemplo n.º 20
0
    def test_test_patch_empty_diff(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'apply': '',
            'add': '',
            'diff': '',
            'reset': '',
            'clean': '',
            'checkout': '',
        }, strict=True)
        local_wpt = LocalWPT(host, 'token')

        self.assertEqual(local_wpt.test_patch('dummy patch'), (False, ''))
Exemplo n.º 21
0
    def exportable_but_not_exported_commits(self, wpt_path):
        """Checks for commits that might be overwritten by importing.

        Args:
            wpt_path: The path to a local checkout of web-platform-tests.

        Returns:
            A list of commits in the Chromium repo that are exportable
            but not yet exported to the web-platform-tests repo.
        """
        local_wpt = LocalWPT(self.host, path=wpt_path)
        assert self.host.filesystem.exists(wpt_path)
        _, chromium_commit = local_wpt.most_recent_chromium_commit()
        return exportable_commits_since(chromium_commit.sha, self.host, local_wpt)
Exemplo n.º 22
0
    def test_last_wpt_exported_commit(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'rev-list': '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8',
            'footers': 'Cr-Commit-Position: 123',
            'crrev-parse': 'add087a97844f4b9e307d9a216940582d96db306',
        }, strict=True)
        host.filesystem = MockFileSystem()
        local_wpt = LocalWPT(host, 'token')

        wpt_sha, chromium_commit = local_wpt.most_recent_chromium_commit()
        self.assertEqual(wpt_sha, '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8')
        self.assertEqual(chromium_commit.position, '123')
        self.assertEqual(chromium_commit.sha, 'add087a97844f4b9e307d9a216940582d96db306')
Exemplo n.º 23
0
    def test_fetch_when_wpt_dir_exists(self):
        host = MockHost()
        host.filesystem = MockFileSystem(files={'/tmp/wpt': ''})

        local_wpt = LocalWPT(host)
        local_wpt.fetch()

        self.assertEqual(
            host.executive.calls,
            [['git', 'fetch', '--all'], ['git', 'checkout', 'origin/master'],
             ['git', 'remote'],
             [
                 'git', 'remote', 'add', 'github',
                 '[email protected]:w3c/web-platform-tests.git'
             ]])
Exemplo n.º 24
0
    def test_commits_in_range(self):
        host = MockHost()
        host.executive = mock_git_commands(
            {
                'rev-list':
                '34ab6c3f5aee8bf05207b674edbcb6affb179545 Fix presubmit errors\n'
                '8c596b820634a623dfd7a2b0f36007ce2f7a0c9f test\n'
            },
            strict=True)
        local_wpt = LocalWPT(host, 'token')

        self.assertTrue(local_wpt.commits_in_range('HEAD~2', 'HEAD'))
        self.assertEqual(
            host.executive.calls,
            [['git', 'rev-list', '--pretty=oneline', 'HEAD~2..HEAD']])
Exemplo n.º 25
0
    def __init__(self,
                 host,
                 gh_user,
                 gh_token,
                 gerrit_user,
                 gerrit_token,
                 dry_run=False):
        self.host = host
        self.wpt_github = WPTGitHub(host, gh_user, gh_token)

        self.gerrit = GerritAPI(self.host, gerrit_user, gerrit_token)

        self.dry_run = dry_run
        self.local_wpt = LocalWPT(self.host, gh_token)
        self.local_wpt.fetch()
Exemplo n.º 26
0
    def test_last_wpt_exported_commit(self):
        host = MockHost()
        return_vals = [
            'deadbeefcafe',
            '123',
            '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8',
        ]
        host.executive = MockExecutive(run_command_fn=lambda _: return_vals.pop())
        host.filesystem = MockFileSystem()
        local_wpt = LocalWPT(host)

        wpt_sha, chromium_commit = local_wpt.most_recent_chromium_commit()
        self.assertEqual(wpt_sha, '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8')
        self.assertEqual(chromium_commit.position, '123')
        self.assertEqual(chromium_commit.sha, 'deadbeefcafe')
Exemplo n.º 27
0
    def main(self, argv=None):
        """Creates PRs for in-flight CLs and merges changes that land on master.

        Returns:
            A boolean: True if success, False if there were any patch failures.
        """
        args = self.parse_args(argv)
        self.dry_run = args.dry_run

        configure_logging(logging_level=logging.INFO, include_time=True)

        credentials = read_credentials(self.host, args.credentials_json)
        if not (credentials['GH_USER'] and credentials['GH_TOKEN']):
            _log.error('Must provide both user and token for GitHub.')
            return False

        self.wpt_github = self.wpt_github or WPTGitHub(self.host, credentials['GH_USER'], credentials['GH_TOKEN'])
        self.gerrit = self.gerrit or GerritAPI(self.host, credentials['GERRIT_USER'], credentials['GERRIT_TOKEN'])
        self.local_wpt = self.local_wpt or LocalWPT(self.host, credentials['GH_TOKEN'])
        self.local_wpt.fetch()

        open_gerrit_cls = self.gerrit.query_exportable_open_cls()
        self.process_gerrit_cls(open_gerrit_cls)

        exportable_commits, errors = self.get_exportable_commits()
        for error in errors:
            _log.warn(error)
        self.process_chromium_commits(exportable_commits)

        return not bool(errors)
Exemplo n.º 28
0
    def test_no_fetch_flag(self):
        host = MockHost()
        host.filesystem = MockFileSystem(files={'/tmp/wpt': ''})

        LocalWPT(host, no_fetch=True)

        self.assertEqual(len(host.executive.calls), 0)
Exemplo n.º 29
0
 def test_apply_exportable_commits_locally(self):
     host = MockHost()
     importer = TestImporter(host, wpt_github=MockWPTGitHub(pull_requests=[]))
     fake_commit = MockChromiumCommit(
         host, subject='My fake commit',
         patch=(
             'Fake patch contents...\n'
             '--- a/third_party/WebKit/LayoutTests/external/wpt/css/css-ui-3/outline-004.html\n'
             '+++ b/third_party/WebKit/LayoutTests/external/wpt/css/css-ui-3/outline-004.html\n'
             '@@ -20,7 +20,7 @@\n'
             '...'))
     importer.exportable_but_not_exported_commits = lambda _: [fake_commit]
     applied = importer.apply_exportable_commits_locally(LocalWPT(host))
     self.assertEqual(applied, [fake_commit])
     self.assertEqual(host.executive.full_calls, [
         MockCall(
             ['git', 'apply', '-'],
             {
                 'input': (
                     'Fake patch contents...\n'
                     '--- a/css/css-ui-3/outline-004.html\n'
                     '+++ b/css/css-ui-3/outline-004.html\n'
                     '@@ -20,7 +20,7 @@\n'
                     '...'),
                 'cwd': '/tmp/wpt',
                 'env': None
             }),
         MockCall(
             ['git', 'add', '.'],
             kwargs={'input': None, 'cwd': '/tmp/wpt', 'env': None}),
         MockCall(
             ['git', 'commit', '--all', '-F', '-'],
             kwargs={'cwd': '/tmp/wpt', 'env': None})
     ])
Exemplo n.º 30
0
    def test_clones_if_wpt_does_not_exist(self):
        host = MockHost()
        host.filesystem = MockFileSystem()

        LocalWPT(host)

        self.assertEqual(len(host.executive.calls), 1)
        self.assertEqual(host.executive.calls[0][1], 'clone')
Exemplo n.º 31
0
    def main(self, argv=None):
        """Creates PRs for in-flight CLs and merges changes that land on master.

        Returns:
            A boolean: True if success, False if there were any patch failures.
        """
        options = self.parse_args(argv)

        self.dry_run = options.dry_run
        log_level = logging.DEBUG if options.verbose else logging.INFO
        configure_logging(logging_level=log_level, include_time=True)
        if options.verbose:
            # Print out the full output when executive.run_command fails.
            self.host.executive.error_output_limit = None

        credentials = read_credentials(self.host, options.credentials_json)
        if not (credentials.get('GH_USER') and credentials.get('GH_TOKEN')):
            _log.error('You must provide your GitHub credentials for this '
                       'script to work.')
            _log.error('See https://chromium.googlesource.com/chromium/src'
                       '/+/master/docs/testing/web_platform_tests.md'
                       '#GitHub-credentials for instructions on how to set '
                       'your credentials up.')
            return False

        self.wpt_github = self.wpt_github or WPTGitHub(
            self.host, credentials['GH_USER'], credentials['GH_TOKEN'])
        self.gerrit = self.gerrit or GerritAPI(
            self.host, credentials['GERRIT_USER'], credentials['GERRIT_TOKEN'])
        self.local_wpt = self.local_wpt or LocalWPT(self.host,
                                                    credentials['GH_TOKEN'])
        self.local_wpt.fetch()

        _log.info('Searching for exportable in-flight CLs.')
        # The Gerrit search API is slow and easy to fail, so we wrap it in a try
        # statement to continue exporting landed commits when it fails.
        try:
            open_gerrit_cls = self.gerrit.query_exportable_open_cls()
        except GerritError as e:
            _log.info(
                'In-flight CLs cannot be exported due to the following error:')
            _log.error(str(e))
            gerrit_error = True
        else:
            self.process_gerrit_cls(open_gerrit_cls)
            gerrit_error = False

        _log.info('Searching for exportable Chromium commits.')
        exportable_commits, git_errors = self.get_exportable_commits()
        self.process_chromium_commits(exportable_commits)
        if git_errors:
            _log.info(
                'Attention: The following errors have prevented some commits from being '
                'exported:')
            for error in git_errors:
                _log.error(error)

        return not (gerrit_error or git_errors)
Exemplo n.º 32
0
    def test_fetches_if_wpt_exists(self):
        host = MockHost()
        host.filesystem = MockFileSystem(files={'/tmp/wpt': ''})

        LocalWPT(host)

        self.assertEqual(len(host.executive.calls), 2)
        self.assertEqual(host.executive.calls[0][1], 'fetch')
        self.assertEqual(host.executive.calls[1][1], 'checkout')
    def test_create_branch_with_patch(self):
        host = MockHost()
        host.filesystem = MockFileSystem()

        local_wpt = LocalWPT(host, 'token')
        local_wpt.fetch()

        local_wpt.create_branch_with_patch('chromium-export-decafbad',
                                           'message', 'patch',
                                           'author <*****@*****.**>')
        self.assertEqual(
            host.executive.calls,
            [[
                'git', 'clone',
                'https://[email protected]/w3c/web-platform-tests.git',
                '/tmp/wpt'
            ], ['git', 'reset', '--hard', 'HEAD'], ['git', 'clean', '-fdx'],
             ['git', 'checkout', 'origin/master'],
             ['git', 'branch', '-D', 'chromium-export-decafbad'],
             ['git', 'checkout', '-b', 'chromium-export-decafbad'],
             ['git', 'apply', '-'], ['git', 'add', '.'],
             [
                 'git', 'commit', '--author', 'author <*****@*****.**>',
                 '-am', 'message'
             ], ['git', 'push', 'origin', 'chromium-export-decafbad']])
Exemplo n.º 34
0
    def main(self, argv=None):
        """Creates PRs for in-flight CLs and merges changes that land on master.

        Returns:
            A boolean: True if success, False if there were any patch failures.
        """
        options = self.parse_args(argv)

        self.dry_run = options.dry_run
        log_level = logging.DEBUG if options.verbose else logging.INFO
        configure_logging(logging_level=log_level, include_time=True)
        if options.verbose:
            # Print out the full output when executive.run_command fails.
            self.host.executive.error_output_limit = None

        credentials = read_credentials(self.host, options.credentials_json)
        if not (credentials['GH_USER'] and credentials['GH_TOKEN']):
            _log.error('Must provide both user and token for GitHub.')
            return False

        self.wpt_github = self.wpt_github or WPTGitHub(
            self.host, credentials['GH_USER'], credentials['GH_TOKEN'])
        self.gerrit = self.gerrit or GerritAPI(
            self.host, credentials['GERRIT_USER'], credentials['GERRIT_TOKEN'])
        self.local_wpt = self.local_wpt or LocalWPT(self.host,
                                                    credentials['GH_TOKEN'])
        self.local_wpt.fetch()

        # The Gerrit search API is slow and easy to fail, so we wrap it in a try
        # statement to continue exporting landed commits when it fails.
        try:
            open_gerrit_cls = self.gerrit.query_exportable_open_cls()
        except GerritError as e:
            _log.error(str(e))
            gerrit_error = True
        else:
            self.process_gerrit_cls(open_gerrit_cls)
            gerrit_error = False

        exportable_commits, git_errors = self.get_exportable_commits()
        for error in git_errors:
            _log.error(error)
        self.process_chromium_commits(exportable_commits)

        return not (gerrit_error or git_errors)
Exemplo n.º 35
0
 def test_apply_exportable_commits_locally(self):
     # TODO(robertma): Consider using MockLocalWPT.
     host = MockHost()
     importer = TestImporter(host,
                             wpt_github=MockWPTGitHub(pull_requests=[]))
     importer.wpt_git = MockGit(cwd='/tmp/wpt', executive=host.executive)
     fake_commit = MockChromiumCommit(
         host,
         subject='My fake commit',
         patch=
         ('Fake patch contents...\n'
          '--- a/third_party/WebKit/LayoutTests/external/wpt/css/css-ui-3/outline-004.html\n'
          '+++ b/third_party/WebKit/LayoutTests/external/wpt/css/css-ui-3/outline-004.html\n'
          '@@ -20,7 +20,7 @@\n'
          '...'))
     importer.exportable_but_not_exported_commits = lambda _: [fake_commit]
     applied = importer.apply_exportable_commits_locally(LocalWPT(host))
     self.assertEqual(applied, [fake_commit])
     # This assertion is implementation details of LocalWPT.apply_patch.
     # TODO(robertma): Move this to local_wpt_unittest.py.
     self.assertEqual(host.executive.full_calls, [
         MockCall(
             ['git', 'apply', '-'], {
                 'input': ('Fake patch contents...\n'
                           '--- a/css/css-ui-3/outline-004.html\n'
                           '+++ b/css/css-ui-3/outline-004.html\n'
                           '@@ -20,7 +20,7 @@\n'
                           '...'),
                 'cwd':
                 '/tmp/wpt',
                 'env':
                 None
             }),
         MockCall(['git', 'add', '.'],
                  kwargs={
                      'input': None,
                      'cwd': '/tmp/wpt',
                      'env': None
                  })
     ])
     self.assertEqual(
         importer.wpt_git.local_commits(),
         [['Applying patch 14fd77e88e42147c57935c49d9e3b2412b8491b7']])
Exemplo n.º 36
0
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())
Exemplo n.º 37
0
    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)