コード例 #1
0
    def test_dry_run_stops_before_creating_pr(self):
        self.host.executive = mock_git_commands({
            'crrev-parse':
            'c2087acb00eee7960339a0be34ea27d6b20e1131',
        })
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(
                title='title1', number=1234, body='', state='open', labels=[]),
        ])
        test_exporter.gerrit = MockGerritAPI(self.host, 'gerrit-username',
                                             'gerrit-token')
        test_exporter.get_exportable_commits = lambda: ([
            ChromiumCommit(self.host, position='refs/heads/master@{#458475}'),
            ChromiumCommit(self.host, position='refs/heads/master@{#458476}'),
            ChromiumCommit(self.host, position='refs/heads/master@{#458477}'),
        ], [])
        success = test_exporter.main(
            ['--credentials-json', '/tmp/credentials.json', '--dry-run'])

        self.assertTrue(success)
        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_for_chromium_commit',
            'pr_for_chromium_commit',
            'pr_for_chromium_commit',
        ])
コード例 #2
0
    def test_merges_non_provisional_pr(self):
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(
                title='title1',
                number=1234,
                body='description\nWPT-Export-Revision: 9\nChange-Id: decafbad',
                state='open',
                labels=['']),
        ])
        test_exporter.get_exportable_commits = lambda: ([
            MockChromiumCommit(self.host, change_id='decafbad'),
        ], [])
        test_exporter.gerrit = MockGerritAPI(self.host, 'gerrit-username',
                                             'gerrit-token')
        test_exporter.gerrit.query_exportable_open_cls = lambda: []
        success = test_exporter.main(
            ['--credentials-json', '/tmp/credentials.json'])

        self.assertTrue(success)
        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_for_chromium_commit',
            'get_pr_branch',
            'merge_pull_request',
            'delete_remote_branch',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [])
        self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [1234])
コード例 #3
0
    def test_dry_run_stops_before_creating_pr(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'crrev-parse':
            'c2087acb00eee7960339a0be34ea27d6b20e1131',
        })
        test_exporter = TestExporter(host,
                                     'gh-username',
                                     'gh-token',
                                     gerrit_user=None,
                                     gerrit_token=None,
                                     dry_run=True)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(title='title1', number=1234, body='', state='open'),
        ])
        test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username',
                                             'gerrit-token')
        test_exporter.get_exportable_commits = lambda limit: [
            ChromiumCommit(host, position='refs/heads/master@{#458475}'),
            ChromiumCommit(host, position='refs/heads/master@{#458476}'),
            ChromiumCommit(host, position='refs/heads/master@{#458477}'),
        ]
        test_exporter.run()

        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_with_position',
            'pr_with_position',
            'pr_with_position',
        ])
コード例 #4
0
    def test_does_not_create_pr_if_cl_review_has_not_started(self):
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[])
        test_exporter.get_exportable_commits = lambda: ([], [])
        test_exporter.gerrit = MockGerritAPI()
        test_exporter.gerrit.exportable_open_cls = [MockGerritCL(
            data={
                'change_id': '1',
                'subject': 'subject',
                '_number': 1,
                'current_revision': '2',
                'has_review_started': False,
                'revisions': {
                    '1': {
                        'commit_with_footers': 'a commit with footers 1',
                        'description': 'subject 1',
                    },
                    '2': {
                        'commit_with_footers': 'a commit with footers 2',
                        'description': 'subject 2',
                    },
                },
                'owner': {'email': '*****@*****.**'},
            },
            api=test_exporter.gerrit,
            chromium_commit=MockChromiumCommit(self.host)
        )]
        success = test_exporter.main(['--credentials-json', '/tmp/credentials.json'])

        self.assertTrue(success)
        self.assertEqual(test_exporter.wpt_github.calls, [])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [])
        self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [])
コード例 #5
0
 def test_new_gerrit_cl(self):
     host = MockHost()
     test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None,
                                  gerrit_token=None, dry_run=False)
     test_exporter.wpt_github = MockWPTGitHub(pull_requests=[])
     test_exporter.get_exportable_commits = lambda: []
     test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token')
     test_exporter.gerrit.get = lambda path, raw: base64.b64encode('sample diff')  # pylint: disable=unused-argument
     test_exporter.gerrit.query_exportable_open_cls = lambda: [
         GerritCL(data={
             'change_id': '1',
             'subject': 'subject',
             '_number': '1',
             'current_revision': '1',
             'has_review_started': True,
             'revisions': {
                 '1': {'commit_with_footers': 'a commit with footers'}
             },
             'owner': {'email': '*****@*****.**'},
         }, api=test_exporter.gerrit),
     ]
     test_exporter.run()
     self.assertEqual(test_exporter.wpt_github.calls, [
         'pr_with_change_id',
         'create_pr',
         'add_label "chromium-export"',
         'add_label "do not merge yet"',
     ])
     self.assertEqual(test_exporter.wpt_github.pull_requests_created, [
         ('chromium-export-cl-1',
          'subject',
          'a commit with footers\nWPT-Export-Revision: 1'),
     ])
コード例 #6
0
    def test_attempts_to_merge_landed_gerrit_cl(self):
        host = MockHost()

        def mock_command(args):
            if args[1] != 'footers':
                return ''
            if args[2] == '--key':
                return 'decafbad\n'
            elif args[2] == '--position':
                return 'refs/heads/master@{#475994}'

        host.executive = MockExecutive(run_command_fn=mock_command)
        test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None,
                                     gerrit_token=None, dry_run=False)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(title='title1', number=1234,
                        body='description\nWPT-Export-Revision: 9\nChange-Id: decafbad',
                        state='open', labels=['do not merge yet']),
        ])
        test_exporter.get_exportable_commits = lambda: [
            ChromiumCommit(host, sha='c881563d734a86f7d9cd57ac509653a61c45c240'),
        ]
        test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token')
        test_exporter.gerrit.query_exportable_open_cls = lambda: []
        test_exporter.run()

        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_for_chromium_commit',
            'remove_label "do not merge yet"',
            'get_pr_branch',
            'merge_pull_request',
            'delete_remote_branch',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [])
        self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [1234])
コード例 #7
0
    def test_attempts_to_merge_landed_gerrit_cl(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'footers': 'decafbad',
        })
        test_exporter = TestExporter(host,
                                     'gh-username',
                                     'gh-token',
                                     gerrit_user=None,
                                     gerrit_token=None,
                                     dry_run=False)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(
                title='title1',
                number=1234,
                body='description\nWPT-Export-Revision: 9\nChange-Id: decafbad',
                state='open'),
        ])
        test_exporter.get_exportable_commits = lambda limit: [
            ChromiumCommit(host,
                           sha='c881563d734a86f7d9cd57ac509653a61c45c240'),
        ]
        test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username',
                                             'gerrit-token')
        test_exporter.gerrit.query_exportable_open_cls = lambda: []
        test_exporter.run()

        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_with_position',
            'get_pr_branch',
            'merge_pull_request',
            'delete_remote_branch',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [])
        self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [1234])
コード例 #8
0
    def test_attempts_to_merge_landed_gerrit_cl(self):
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(
                title='title1',
                number=1234,
                body='description\nWPT-Export-Revision: 9\nChange-Id: decafbad',
                state='open',
                labels=['do not merge yet']),
        ])
        test_exporter.get_exportable_commits = lambda: ([
            MockChromiumCommit(self.host, change_id='decafbad'),
        ], [])
        test_exporter.gerrit = MockGerritAPI()
        success = test_exporter.main(
            ['--credentials-json', '/tmp/credentials.json'])

        self.assertTrue(success)
        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_for_chromium_commit',
            'get_pr_branch',
            'update_pr',
            'remove_label "do not merge yet"',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [])
        self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [])
コード例 #9
0
 def test_gerrit_cl_no_update_if_pr_with_same_revision(self):
     host = MockHost()
     test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None,
                                  gerrit_token=None, dry_run=False)
     test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
         PullRequest(title='title1', number=1234,
                     body='description\nWPT-Export-Revision: 1',
                     state='open', labels=[]),
     ])
     test_exporter.get_exportable_commits = lambda: []
     test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token')
     test_exporter.gerrit.query_exportable_open_cls = lambda: [
         GerritCL(data={
             'change_id': '1',
             'subject': 'subject',
             '_number': '1',
             'current_revision': '1',
             'has_review_started': True,
             'revisions': {
                 '1': {'commit_with_footers': 'a commit with footers'}
             },
             'owner': {'email': '*****@*****.**'},
         }, api=test_exporter.gerrit),
     ]
     test_exporter.run()
     self.assertEqual(test_exporter.wpt_github.calls, [
         'pr_with_change_id',
     ])
     self.assertEqual(test_exporter.wpt_github.pull_requests_created, [])
コード例 #10
0
    def test_creates_pull_request_for_all_exportable_commits(self):
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[], create_pr_fail_index=1)
        test_exporter.gerrit = MockGerritAPI()
        test_exporter.get_exportable_commits = lambda: ([
            MockChromiumCommit(self.host, position='refs/heads/master@{#1}', change_id='I001', subject='subject 1', body='body 1'),
            MockChromiumCommit(self.host, position='refs/heads/master@{#2}', change_id='I002', subject='subject 2', body='body 2'),
            MockChromiumCommit(self.host, position='refs/heads/master@{#3}', change_id='I003', subject='subject 3', body='body 3'),
        ], [])
        success = test_exporter.main(['--credentials-json', '/tmp/credentials.json'])

        self.assertTrue(success)
        self.assertEqual(test_exporter.wpt_github.calls, [
            # 1
            'pr_for_chromium_commit',
            'create_pr',
            'add_label "chromium-export"',
            # 2
            'pr_for_chromium_commit',
            'create_pr',
            'add_label "chromium-export"',
            # 3
            'pr_for_chromium_commit',
            'create_pr',
            'add_label "chromium-export"',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [
            ('chromium-export-96862edfc1', 'subject 1', 'body 1\n\nChange-Id: I001\n'),
            ('chromium-export-ce0e78bf18', 'subject 3', 'body 3\n\nChange-Id: I003\n'),
        ])
コード例 #11
0
 def test_does_not_create_pr_if_cl_review_has_not_started(self):
     host = MockHost()
     test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None,
                                  gerrit_token=None, dry_run=False)
     test_exporter.wpt_github = MockWPTGitHub(pull_requests=[])
     test_exporter.get_exportable_commits = lambda: []
     test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token')
     test_exporter.gerrit.get = lambda path, raw: base64.b64encode('sample diff')  # pylint: disable=unused-argument
     test_exporter.gerrit.query_exportable_open_cls = lambda: [
         GerritCL(data={
             'change_id': '1',
             'subject': 'subject',
             '_number': '1',
             'current_revision': '2',
             'has_review_started': False,
             'revisions': {
                 '1': {
                     'commit_with_footers': 'a commit with footers 1',
                     'description': 'subject 1',
                 },
                 '2': {
                     'commit_with_footers': 'a commit with footers 2',
                     'description': 'subject 2',
                 },
             },
             'owner': {'email': '*****@*****.**'},
         }, api=test_exporter.gerrit),
     ]
     test_exporter.run()
     self.assertEqual(test_exporter.wpt_github.calls, [])
     self.assertEqual(test_exporter.wpt_github.pull_requests_created, [])
コード例 #12
0
    def test_gerrit_cl_no_update_if_pr_with_same_revision(self):
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(title='title1', number=1234,
                        body='description\nWPT-Export-Revision: 1',
                        state='open', labels=[]),
        ])
        test_exporter.get_exportable_commits = lambda: ([], [])
        test_exporter.gerrit = MockGerritAPI()
        test_exporter.gerrit.exportable_open_cls = [MockGerritCL(
            data={
                'change_id': '1',
                'subject': 'subject',
                '_number': 1,
                'current_revision': '1',
                'has_review_started': True,
                'revisions': {
                    '1': {'commit_with_footers': 'a commit with footers'}
                },
                'owner': {'email': '*****@*****.**'},
            },
            api=test_exporter.gerrit,
            chromium_commit=MockChromiumCommit(self.host)
        )]
        success = test_exporter.main(['--credentials-json', '/tmp/credentials.json'])

        self.assertTrue(success)
        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_with_change_id',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [])
        self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [])
コード例 #13
0
    def test_new_gerrit_cl(self):
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[])
        test_exporter.get_exportable_commits = lambda: ([], [])
        test_exporter.gerrit = MockGerritAPI()
        test_exporter.gerrit.exportable_open_cls = [MockGerritCL(
            data={
                'change_id': 'I001',
                'subject': 'subject',
                '_number': 1234,
                'current_revision': '1',
                'has_review_started': True,
                'revisions': {
                    '1': {'commit_with_footers': 'a commit with footers'}
                },
                'owner': {'email': '*****@*****.**'},
            },
            api=test_exporter.gerrit,
            chromium_commit=MockChromiumCommit(self.host, subject='subject', body='fake body', change_id='I001')
        )]
        test_exporter.main(['--credentials-json', '/tmp/credentials.json'])

        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_with_change_id',
            'create_pr',
            'add_label "chromium-export"',
            'add_label "do not merge yet"',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [
            ('chromium-export-cl-1234',
             'subject',
             'fake body\n\nChange-Id: I001\nReviewed-on: https://chromium-review.googlesource.com/1234\nWPT-Export-Revision: 1'),
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [])
コード例 #14
0
 def test_url(self):
     data = {
         'change_id': 'Ib58c7125d85d2fd71af711ea8bbd2dc927ed02cb',
         '_number': 638250,
     }
     gerrit_cl = GerritCL(data, MockGerritAPI())
     self.assertEqual(gerrit_cl.url,
                      'https://chromium-review.googlesource.com/638250')
コード例 #15
0
    def test_filter_transform_patch(self):
        host = Host()
        finder = PathFinder(host.filesystem)
        resources_path = finder.path_from_tools_scripts('webkitpy', 'w3c', 'resources')
        sample_patch = host.filesystem.read_text_file(host.filesystem.join(resources_path, 'sample.patch'))
        expected_patch = host.filesystem.read_text_file(host.filesystem.join(resources_path, 'expected.patch'))

        cl = GerritCL({'change_id': 1}, MockGerritAPI(None, None, None))
        actual_patch = cl.filter_transform_patch(sample_patch)
        self.assertEqual(actual_patch, expected_patch)
コード例 #16
0
    def test_run_returns_false_on_patch_failure(self):
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[])
        test_exporter.get_exportable_commits = lambda: ([], ['There was an error with the rutabaga.'])
        test_exporter.gerrit = MockGerritAPI()
        success = test_exporter.main(['--credentials-json', '/tmp/credentials.json'])

        self.assertFalse(success)
        self.assertLog(['INFO: Cloning GitHub w3c/web-platform-tests into /tmp/wpt\n',
                        'ERROR: There was an error with the rutabaga.\n'])
コード例 #17
0
 def test_empty_cl_is_not_exportable(self):
     data = {
         'change_id': 'Ib58c7125d85d2fd71af711ea8bbd2dc927ed02cb',
         'subject': 'fake subject',
         '_number': 638250,
         'owner': {
             'email': '*****@*****.**'
         },
     }
     gerrit_cl = GerritCL(data, MockGerritAPI())
     # It's important that this does not throw!
     self.assertFalse(gerrit_cl.is_exportable())
コード例 #18
0
    def test_run_returns_false_on_gerrit_search_error(self):
        def raise_gerrit_error():
            raise GerritError('Gerrit API fails.')

        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[])
        test_exporter.get_exportable_commits = lambda: ([], [])
        test_exporter.gerrit = MockGerritAPI()
        test_exporter.gerrit.query_exportable_open_cls = raise_gerrit_error
        success = test_exporter.main(['--credentials-json', '/tmp/credentials.json'])

        self.assertFalse(success)
        self.assertLog(['INFO: Cloning GitHub w3c/web-platform-tests into /tmp/wpt\n',
                        'ERROR: Gerrit API fails.\n'])
コード例 #19
0
    def test_creates_pull_request_for_all_exportable_commits(self):
        host = MockHost()

        def mock_command(args):
            canned_git_outputs = {
                'rev-list': '\n'.join([
                    'c881563d734a86f7d9cd57ac509653a61c45c240',
                    'add087a97844f4b9e307d9a216940582d96db306',
                    'cbcd201627f19f81a1697aaaa93cc3a41e644dab',
                ]),
                'footers': 'fake-cr-position',
                'remote': 'github',
                'format-patch': 'fake patch',
                'diff': 'fake patch diff',
                'diff-tree': 'fake\n\files\nchanged',
                'crrev-parse': 'c881563d734a86f7d9cd57ac509653a61c45c240',
            }
            if args[1] == 'show':
                if 'c881563d734a86f7d9cd57ac509653a61c45c240' in args:
                    return 'older fake text'
                elif 'add087a97844f4b9e307d9a216940582d96db306' in args:
                    return 'newer fake text'
                elif 'cbcd201627f19f81a1697aaaa93cc3a41e644dab' in args:
                    return 'newest fake text'
            return canned_git_outputs.get(args[1], '')

        host.executive = MockExecutive(run_command_fn=mock_command)
        test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None, gerrit_token=None)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[], create_pr_fail_index=1)
        test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token')
        test_exporter.run()

        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_for_chromium_commit',
            'pr_for_chromium_commit',
            'pr_for_chromium_commit',
            'pr_for_chromium_commit',
            'create_pr',
            'add_label "chromium-export"',
            'pr_for_chromium_commit',
            'create_pr',
            'add_label "chromium-export"',
            'pr_for_chromium_commit',
            'create_pr',
            'add_label "chromium-export"',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [
            ('chromium-export-c881563d73', 'older fake text', 'older fake text'),
            ('chromium-export-cbcd201627', 'newest fake text', 'newest fake text'),
        ])
コード例 #20
0
    def test_run_returns_false_on_patch_failure(self):
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[])
        test_exporter.get_exportable_commits = lambda: ([
        ], ['There was an error with the rutabaga.'])
        test_exporter.gerrit = MockGerritAPI(self.host, 'gerrit-username',
                                             'gerrit-token')
        test_exporter.gerrit.get = lambda path, raw: base64.b64encode(
            'sample diff')  # pylint: disable=unused-argument
        success = test_exporter.main(
            ['--credentials-json', '/tmp/credentials.json'])

        self.assertFalse(success)
        self.assertLog([
            'INFO: Cloning GitHub w3c/web-platform-tests into /tmp/wpt\n',
            'WARNING: There was an error with the rutabaga.\n'
        ])
コード例 #21
0
    def test_run_returns_false_on_patch_failure(self):
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[])
        test_exporter.get_exportable_commits = lambda: ([
        ], ['There was an error with the rutabaga.'])
        test_exporter.gerrit = MockGerritAPI()
        success = test_exporter.main(
            ['--credentials-json', '/tmp/credentials.json'])

        self.assertFalse(success)
        self.assertLog([
            'INFO: Cloning GitHub w3c/web-platform-tests into /tmp/wpt\n',
            'INFO: Searching for exportable in-flight CLs.\n',
            'INFO: Searching for exportable Chromium commits.\n',
            'INFO: Attention: The following errors have prevented some commits from being exported:\n',
            'ERROR: There was an error with the rutabaga.\n'
        ])
コード例 #22
0
    def test_gerrit_cl_updates_if_cl_has_new_revision(self):
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(title='title1',
                        number=1234,
                        body='description\nWPT-Export-Revision: 1',
                        state='open',
                        labels=[]),
        ])
        test_exporter.get_exportable_commits = lambda: ([], [])
        test_exporter.gerrit = MockGerritAPI(self.host, 'gerrit-username',
                                             'gerrit-token')
        test_exporter.gerrit.get = lambda path, raw: base64.b64encode(
            'sample diff')  # pylint: disable=unused-argument
        test_exporter.gerrit.query_exportable_open_cls = lambda: [
            GerritCL(data={
                'change_id': '1',
                'subject': 'subject',
                '_number': '1',
                'current_revision': '2',
                'has_review_started': True,
                'revisions': {
                    '1': {
                        'commit_with_footers': 'a commit with footers 1',
                        'description': 'subject 1',
                    },
                    '2': {
                        'commit_with_footers': 'a commit with footers 2',
                        'description': 'subject 2',
                    },
                },
                'owner': {
                    'email': '*****@*****.**'
                },
            },
                     api=test_exporter.gerrit),
        ]
        test_exporter.main(['--credentials-json', '/tmp/credentials.json'])

        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_with_change_id',
            'update_pr',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [])
        self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [])
コード例 #23
0
    def test_fetch_current_revision_commit(self):
        host = MockHost()
        host.executive = mock_git_commands(
            {
                'fetch': '',
                'rev-parse': '4de71d0ce799af441c1f106c5432c7fa7256be45',
                'footers': 'no-commit-position-yet'
            },
            strict=True)
        data = {
            'change_id': 'Ib58c7125d85d2fd71af711ea8bbd2dc927ed02cb',
            'subject': 'fake subject',
            '_number': 638250,
            'current_revision': '1',
            'revisions': {
                '1': {
                    'fetch': {
                        'http': {
                            'url':
                            'https://chromium.googlesource.com/chromium/src',
                            'ref': 'refs/changes/50/638250/1'
                        }
                    }
                }
            },
            'owner': {
                'email': '*****@*****.**'
            },
        }
        gerrit_cl = GerritCL(data, MockGerritAPI())
        commit = gerrit_cl.fetch_current_revision_commit(host)

        self.assertEqual(commit.sha,
                         '4de71d0ce799af441c1f106c5432c7fa7256be45')
        self.assertEqual(host.executive.calls,
                         [[
                             'git', 'fetch',
                             'https://chromium.googlesource.com/chromium/src',
                             'refs/changes/50/638250/1'
                         ], ['git', 'rev-parse', 'FETCH_HEAD'],
                          [
                              'git', 'footers', '--position',
                              '4de71d0ce799af441c1f106c5432c7fa7256be45'
                          ]])
コード例 #24
0
    def test_dry_run_stops_before_creating_pr(self):
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(title='title1', number=1234, body='', state='open', labels=[]),
        ])
        test_exporter.gerrit = MockGerritAPI()
        test_exporter.get_exportable_commits = lambda: ([
            MockChromiumCommit(self.host, position='refs/heads/master@{#458475}'),
            MockChromiumCommit(self.host, position='refs/heads/master@{#458476}'),
            MockChromiumCommit(self.host, position='refs/heads/master@{#458477}'),
        ], [])
        success = test_exporter.main(['--credentials-json', '/tmp/credentials.json', '--dry-run'])

        self.assertTrue(success)
        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_for_chromium_commit',
            'pr_for_chromium_commit',
            'pr_for_chromium_commit',
        ])
コード例 #25
0
 def test_new_gerrit_cl(self):
     host = MockHost()
     test_exporter = TestExporter(host,
                                  'gh-username',
                                  'gh-token',
                                  gerrit_user=None,
                                  gerrit_token=None,
                                  dry_run=False)
     test_exporter.wpt_github = MockWPTGitHub(pull_requests=[])
     test_exporter.get_exportable_commits = lambda limit: []
     test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username',
                                          'gerrit-token')
     test_exporter.gerrit.query_exportable_open_cls = lambda: [
         GerritCL(data={
             'change_id': '1',
             'subject': 'subject',
             '_number': '1',
             'current_revision': '1',
             'revisions': {
                 '1': {
                     'commit_with_footers': 'a commit with footers'
                 }
             },
             'owner': {
                 'email': '*****@*****.**'
             },
         },
                  api=test_exporter.gerrit),
     ]
     test_exporter.run()
     self.assertEqual(test_exporter.wpt_github.calls, [
         'pr_with_change_id',
         'create_pr',
         'add_label',
     ])
     self.assertEqual(test_exporter.wpt_github.pull_requests_created, [
         ('chromium-export-cl-1', 'subject',
          'a commit with footers\nWPT-Export-Revision: 1'),
     ])
コード例 #26
0
    def test_creates_and_merges_pull_requests(self):
        # This tests 4 exportable commits:
        # 1. #458475 has a provisional in-flight PR associated with it. The PR needs to be updated but not merged.
        # 2. #458476 has no PR associated with it and should have one created.
        # 3. #458477 has a closed PR associated with it and should be skipped.
        # 4. #458478 has an in-flight PR associated with it and should be merged successfully.
        # 5. #458479 has an in-flight PR associated with it but can not be merged.
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(
                title='Open PR',
                number=1234,
                body='rutabaga\nCr-Commit-Position: refs/heads/master@{#458475}\nChange-Id: I0005',
                state='open',
                labels=['do not merge yet']
            ),
            PullRequest(
                title='Merged PR',
                number=2345,
                body='rutabaga\nCr-Commit-Position: refs/heads/master@{#458477}\nChange-Id: Idead',
                state='closed',
                labels=[]
            ),
            PullRequest(
                title='Open PR',
                number=3456,
                body='rutabaga\nCr-Commit-Position: refs/heads/master@{#458478}\nChange-Id: I0118',
                state='open',
                labels=[]  # It's important that this is empty.
            ),
            PullRequest(
                title='Open PR',
                number=4747,
                body='rutabaga\nCr-Commit-Position: refs/heads/master@{#458479}\nChange-Id: I0147',
                state='open',
                labels=[]  # It's important that this is empty.
            ),
        ], unsuccessful_merge_index=3)  # Mark the last PR as unmergable.
        test_exporter.gerrit = MockGerritAPI()
        test_exporter.get_exportable_commits = lambda: ([
            MockChromiumCommit(self.host, position='refs/heads/master@{#458475}', change_id='I0005'),
            MockChromiumCommit(self.host, position='refs/heads/master@{#458476}', change_id='I0476'),
            MockChromiumCommit(self.host, position='refs/heads/master@{#458477}', change_id='Idead'),
            MockChromiumCommit(self.host, position='refs/heads/master@{#458478}', change_id='I0118'),
            MockChromiumCommit(self.host, position='refs/heads/master@{#458479}', change_id='I0147'),
        ], [])
        success = test_exporter.main(['--credentials-json', '/tmp/credentials.json'])

        self.assertTrue(success)
        self.assertEqual(test_exporter.wpt_github.calls, [
            # 1. #458475
            'pr_for_chromium_commit',
            'get_pr_branch',
            'update_pr',
            'remove_label "do not merge yet"',
            # 2. #458476
            'pr_for_chromium_commit',
            'create_pr',
            'add_label "chromium-export"',
            # 3. #458477
            'pr_for_chromium_commit',
            # 4. #458478
            'pr_for_chromium_commit',
            # Testing the lack of remove_label here. The exporter should not
            # try to remove the provisional label from PRs it has already
            # removed it from.
            'get_pr_branch',
            'merge_pr',
            'delete_remote_branch',
            # 5. #458479
            'pr_for_chromium_commit',
            'get_pr_branch',
            'merge_pr',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [
            ('chromium-export-52c3178508', 'Fake subject', 'Fake body\n\nChange-Id: I0476\n'),
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [3456])
コード例 #27
0
 def test_creates_and_merges_pull_requests(self):
     # This tests 4 exportable commits:
     # 1. #458475 has an in-flight PR associated with it but cannot be merged.
     # 2. #458476 has no PR associated with it and should have one created.
     # 3. #458477 has a closed PR associated with it and should be skipped.
     # 4. #458478 has an in-flight PR associated with it and should be merged successfully.
     host = MockHost()
     host.executive = mock_git_commands({
         'show':
         'git show text\nCr-Commit-Position: refs/heads/master@{#458476}',
         'crrev-parse':
         'c2087acb00eee7960339a0be34ea27d6b20e1131',
     })
     test_exporter = TestExporter(host,
                                  'gh-username',
                                  'gh-token',
                                  gerrit_user=None,
                                  gerrit_token=None)
     test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
         PullRequest(
             title='Open PR',
             number=1234,
             body=
             'rutabaga\nCr-Commit-Position: refs/heads/master@{#458475}',
             state='open'),
         PullRequest(
             title='Merged PR',
             number=2345,
             body=
             'rutabaga\nCr-Commit-Position: refs/heads/master@{#458477}',
             state='closed'),
         PullRequest(
             title='Open PR',
             number=3456,
             body=
             'rutabaga\nCr-Commit-Position: refs/heads/master@{#458478}',
             state='open'),
     ],
                                              unsuccessful_merge_index=0)
     test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username',
                                          'gerrit-token')
     test_exporter.get_exportable_commits = lambda limit: [
         ChromiumCommit(host, position='refs/heads/master@{#458475}'),
         ChromiumCommit(host, position='refs/heads/master@{#458476}'),
         ChromiumCommit(host, position='refs/heads/master@{#458477}'),
         ChromiumCommit(host, position='refs/heads/master@{#458478}'),
     ]
     test_exporter.run()
     self.assertEqual(test_exporter.wpt_github.calls, [
         'pr_with_position',
         'get_pr_branch',
         'merge_pull_request',
         'pr_with_position',
         'create_pr',
         'add_label',
         'pr_with_position',
         'pr_with_position',
         'get_pr_branch',
         'merge_pull_request',
         'delete_remote_branch',
     ])
     self.assertEqual(test_exporter.wpt_github.pull_requests_created, [
         ('chromium-export-c2087acb00',
          'git show text\nCr-Commit-Position: refs/heads/master@{#458476}',
          'git show text\nCr-Commit-Position: refs/heads/master@{#458476}'),
     ])
コード例 #28
0
    def test_creates_and_merges_pull_requests(self):
        # This tests 4 exportable commits:
        # 1. #458475 has an in-flight PR associated with it but cannot be merged.
        # 2. #458476 has no PR associated with it and should have one created.
        # 3. #458477 has a closed PR associated with it and should be skipped.
        # 4. #458478 has an in-flight PR associated with it and should be merged successfully.
        host = MockHost()
        host.executive = mock_git_commands({
            'show': 'git show text\nCr-Commit-Position: refs/heads/master@{#458476}\nChange-Id: I0476',
            'crrev-parse': 'c2087acb00eee7960339a0be34ea27d6b20e1131',

        })
        test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None, gerrit_token=None)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(
                title='Open PR',
                number=1234,
                body='rutabaga\nCr-Commit-Position: refs/heads/master@{#458475}\nChange-Id: I0005',
                state='open',
                labels=['do not merge yet']
            ),
            PullRequest(
                title='Merged PR',
                number=2345,
                body='rutabaga\nCr-Commit-Position: refs/heads/master@{#458477}\nChange-Id: Idead',
                state='closed',
                labels=[]
            ),
            PullRequest(
                title='Open PR',
                number=3456,
                body='rutabaga\nCr-Commit-Position: refs/heads/master@{#458478}\nChange-Id: I0118',
                state='open',
                labels=[]  # It's important that this is empty.
            ),
        ], unsuccessful_merge_index=0)
        test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token')
        test_exporter.get_exportable_commits = lambda: [
            MockChromiumCommit(host, position='refs/heads/master@{#458475}', change_id='I0005'),
            MockChromiumCommit(host, position='refs/heads/master@{#458476}', change_id='I0476'),
            MockChromiumCommit(host, position='refs/heads/master@{#458477}', change_id='Idead'),
            MockChromiumCommit(host, position='refs/heads/master@{#458478}', change_id='I0118'),
        ]
        test_exporter.run()
        self.assertEqual(test_exporter.wpt_github.calls, [
            'pr_for_chromium_commit',
            'remove_label "do not merge yet"',
            'get_pr_branch',
            'merge_pull_request',
            'pr_for_chromium_commit',
            'create_pr',
            'add_label "chromium-export"',
            'pr_for_chromium_commit',
            'pr_for_chromium_commit',
            # Testing the lack of remove_label here. The exporter should not
            # try to remove the provisional label from PRs it has already
            # removed it from.
            'get_pr_branch',
            'merge_pull_request',
            'delete_remote_branch',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [
            ('chromium-export-52c3178508', 'Fake subject', 'Fake body\n\nChange-Id: I0476'),
        ])
コード例 #29
0
    def test_creates_pull_request_for_all_exportable_commits(self):

        # TODO(robertma): Use MockChromiumCommit instead.
        def mock_command(args):
            canned_git_outputs = {
                'rev-list':
                '\n'.join([
                    'c881563d734a86f7d9cd57ac509653a61c45c240',
                    'add087a97844f4b9e307d9a216940582d96db306',
                    'cbcd201627f19f81a1697aaaa93cc3a41e644dab',
                ]),
                'footers':
                'fake-cr-position',
                'remote':
                'github',
                'format-patch':
                'fake patch',
                'diff':
                'fake patch diff',
                'diff-tree':
                'third_party/WebKit/LayoutTests/external/wpt/some_files',
                'crrev-parse':
                'c881563d734a86f7d9cd57ac509653a61c45c240',
            }
            if args[1] == 'show':
                if 'c881563d734a86f7d9cd57ac509653a61c45c240' in args:
                    return 'older fake text'
                elif 'add087a97844f4b9e307d9a216940582d96db306' in args:
                    return 'newer fake text'
                elif 'cbcd201627f19f81a1697aaaa93cc3a41e644dab' in args:
                    return 'newest fake text'
            return canned_git_outputs.get(args[1], '')

        self.host.executive = MockExecutive(run_command_fn=mock_command)
        test_exporter = TestExporter(self.host)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[],
                                                 create_pr_fail_index=1)
        test_exporter.gerrit = MockGerritAPI(self.host, 'gerrit-username',
                                             'gerrit-token')
        success = test_exporter.main(
            ['--credentials-json', '/tmp/credentials.json'])

        self.assertTrue(success)
        self.assertEqual(
            test_exporter.wpt_github.calls,
            [
                # get_exportable_commits
                'pr_for_chromium_commit',
                'pr_for_chromium_commit',
                'pr_for_chromium_commit',
                # 1
                'pr_for_chromium_commit',
                'create_pr',
                'add_label "chromium-export"',
                # 2
                'pr_for_chromium_commit',
                'create_pr',
                'add_label "chromium-export"',
                # 3
                'pr_for_chromium_commit',
                'create_pr',
                'add_label "chromium-export"',
            ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [
            ('chromium-export-c881563d73', 'older fake text',
             'older fake text'),
            ('chromium-export-cbcd201627', 'newest fake text',
             'newest fake text'),
        ])