def test_process_failing_prs_with_latest_sha(self):
        self.notifier.dry_run = False
        self.notifier.gerrit = MockGerritAPI()
        self.notifier.gerrit.cl = MockGerritCL(data={
            'change_id':
            'abc',
            'messages': [
                {
                    "date": "2019-08-20 17:42:05.000000000",
                    "message": "Uploaded patch set 1.\nInitial upload",
                    "_revision_number": 1
                },
                {
                    "date":
                    "2019-08-21 17:41:05.000000000",
                    "message":
                    self.generate_notifier_comment(123, 'notbar', 'notnum', 3),
                    "_revision_number":
                    2
                },
            ],
            'revisions': {
                'num': {
                    '_number': 1
                }
            }
        },
                                               api=self.notifier.gerrit)
        expected = self.generate_notifier_comment(123, 'bar', 'Latest')
        gerrit_dict = {'abc': PRStatusInfo('bar', 123, None)}

        self.notifier.process_failing_prs(gerrit_dict)

        self.assertEqual(self.notifier.gerrit.cls_queried,
                         ['I4fd5039cd4ec991bb8f840eabe55574b37243ef2', 'abc'])
        self.assertEqual(self.notifier.gerrit.request_posted,
                         [('/a/changes/abc/revisions/current/review', {
                             'message': expected
                         })])
    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, [])
Beispiel #3
0
 def test_main_successful_close_no_exportable_changes(self):
     pr_cleanup = PrCleanupTool(self.host)
     pr_cleanup.wpt_github = MockWPTGitHub(pull_requests=[
         PullRequest(title='title1',
                     number=1234,
                     body='Change-Id: 99',
                     state='open',
                     labels=[]),
     ])
     pr_cleanup.gerrit = MockGerritAPI()
     pr_cleanup.gerrit.cl = MockGerritCL(data={
         'change_id': 'I001',
         'subject': 'subject',
         '_number': 1234,
         'status': 'MERGED',
         'current_revision': '1',
         'has_review_started': True,
         'revisions': {
             '1': {
                 'commit_with_footers': 'a commit with footers',
                 'files': {
                     RELATIVE_WEB_TESTS + 'foo/bar.html': '',
                 }
             }
         },
         'owner': {
             'email': '*****@*****.**'
         },
     },
                                         api=pr_cleanup.gerrit)
     pr_cleanup.main(['--credentials-json', '/tmp/credentials.json'])
     self.assertEqual(pr_cleanup.gerrit.cls_queried, ['99'])
     self.assertEqual(pr_cleanup.wpt_github.calls, [
         'all_pull_requests',
         'add_comment "Close this PR because the Chromium'
         ' CL does not have exportable changes."', 'update_pr',
         'get_pr_branch', 'delete_remote_branch'
     ])
    def test_process_failing_prs_with_latest_sha(self):
        self.notifier.dry_run = False
        self.notifier.gerrit = MockGerritAPI()
        self.notifier.gerrit.cl = MockGerritCL(data={
            'change_id':
            'abc',
            'messages': [
                {
                    "date": "2019-08-20 17:42:05.000000000",
                    "message": "Uploaded patch set 1.\nInitial upload",
                    "_revision_number": 1
                },
                {
                    "date": "2019-08-21 17:41:05.000000000",
                    "message":
                    self.generate_notifier_comment(123, {}, 'notnum', 3),
                    "_revision_number": 2
                },
            ],
            'revisions': {
                'SHA': {
                    '_number': 1
                }
            }
        }, api=self.notifier.gerrit)
        checks_results = {'key1': 'val1', 'key2': 'val2'}
        expected = self.generate_notifier_comment(123, checks_results,
                                                  'Latest')
        gerrit_dict = {'abc': PRStatusInfo(checks_results, 123, None)}

        self.notifier.process_failing_prs(gerrit_dict)

        self.assertEqual(self.notifier.gerrit.cls_queried, ['abc'])
        self.assertEqual(self.notifier.gerrit.request_posted,
                         [('/a/changes/abc/revisions/current/review', {
                             'message': expected
                         })])
Beispiel #5
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, [])
Beispiel #6
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',
        ])
 def test_main_successful_close_abandoned_cl(self):
     pr_cleanup = PrCleanupTool(self.host)
     pr_cleanup.wpt_github = MockWPTGitHub(pull_requests=[
         PullRequest(
             title='title1',
             number=1234,
             body='Change-Id: 88',
             state='open',
             labels=[]),
     ])
     pr_cleanup.gerrit = MockGerritAPI()
     pr_cleanup.gerrit.cl = MockGerritCL(
         data={
             'change_id': 'I001',
             'subject': 'subject',
             '_number': 1234,
             'status': 'ABANDONED',
             'current_revision': '1',
             'has_review_started': True,
             'revisions': {
                 '1': {
                     'commit_with_footers': 'a commit with footers'
                 }
             },
             'owner': {
                 'email': '*****@*****.**'
             },
         },
         api=pr_cleanup.gerrit)
     pr_cleanup.main(['--credentials-json', '/tmp/credentials.json'])
     self.assertEqual(pr_cleanup.gerrit.cls_queried, ['88'])
     self.assertEqual(pr_cleanup.wpt_github.calls, [
         'all_pull_requests',
         'add_comment "Close this PR because the Chromium CL has been abandoned."',
         'update_pr', 'get_pr_branch', 'delete_remote_branch'
     ])
Beispiel #8
0
    def test_export_notifier_success(self):
        self.notifier.wpt_github = MockWPTGitHub(pull_requests=[])
        self.notifier.wpt_github.recent_failing_pull_requests = [
            PullRequest(
                title='title1',
                number=1234,
                body=
                'description\nWPT-Export-Revision: hash\nChange-Id: decafbad',
                state='open',
                labels=[''])
        ]
        self.notifier.wpt_github.check_runs = [
            {
                "id": "123",
                "conclusion": "failure",
                "name": "wpt-chrome-dev-stability"
            },
            {
                "id": "456",
                "conclusion": "success",
                "name": "firefox"
            },
        ]
        checks_results_comment = ('\nwpt-chrome-dev-stability ('
                                  'https://github.com/web-platform-tests/wpt'
                                  '/pull/1234/checks?check_run_id=123)')

        self.notifier.dry_run = False
        self.notifier.gerrit = MockGerritAPI()
        self.notifier.gerrit.cl = MockGerritCL(data={
            'change_id':
            'decafbad',
            'messages': [
                {
                    "date": "2019-08-20 17:42:05.000000000",
                    "message": "Uploaded patch set 1.\nInitial upload",
                    "_revision_number": 1
                },
                {
                    "date":
                    "2019-08-21 17:41:05.000000000",
                    "message":
                    self.generate_notifier_comment(1234, 'notbar', 'notnum',
                                                   3),
                    "_revision_number":
                    2
                },
            ],
            'revisions': {
                'hash': {
                    '_number': 2
                }
            }
        },
                                               api=self.notifier.gerrit)
        expected = self.generate_notifier_comment(1234, checks_results_comment,
                                                  'hash', 2)

        exit_code = self.notifier.main()

        self.assertFalse(exit_code)
        self.assertEqual(self.notifier.wpt_github.calls, [
            'recent_failing_chromium_exports',
            'get_pr_branch',
            'get_branch_check_runs',
        ])
        self.assertEqual(self.notifier.gerrit.cls_queried, ['decafbad'])
        self.assertEqual(self.notifier.gerrit.request_posted,
                         [('/a/changes/decafbad/revisions/current/review', {
                             'message': expected
                         })])
Beispiel #9
0
 def setUp(self):
     super(ExportNotifierTest, self).setUp()
     self.host = MockHost()
     self.git = self.host.git()
     self.gerrit = MockGerritAPI()
     self.notifier = ExportNotifier(self.host, self.git, self.gerrit)
Beispiel #10
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',
                # 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])
Beispiel #11
0
    def test_export_notifier_success(self):
        self.notifier.wpt_github = MockWPTGitHub(pull_requests=[])
        self.notifier.wpt_github.recent_failing_pull_requests = [
            PullRequest(
                title='title1',
                number=1234,
                body=
                'description\nWPT-Export-Revision: hash\nChange-Id: decafbad',
                state='open',
                labels=[''])
        ]
        status = [{
            "state": "failure",
            "context": "Community-TC (pull_request)",
            "node_id": "foo",
            "target_url": "bar"
        }]
        self.notifier.wpt_github.status = status

        self.notifier.dry_run = False
        self.notifier.gerrit = MockGerritAPI()
        self.notifier.gerrit.cl = MockGerritCL(data={
            'change_id':
            'decafbad',
            'messages': [
                {
                    "date": "2019-08-20 17:42:05.000000000",
                    "message": "Uploaded patch set 1.\nInitial upload",
                    "_revision_number": 1
                },
                {
                    "date":
                    "2019-08-21 17:41:05.000000000",
                    "message":
                    self.generate_notifier_comment(1234, 'notbar', 'notnum',
                                                   3),
                    "_revision_number":
                    2
                },
            ],
            'revisions': {
                'hash': {
                    '_number': 2
                }
            }
        },
                                               api=self.notifier.gerrit)
        expected = self.generate_notifier_comment(1234, 'bar', 'hash', 2)

        exit_code = self.notifier.main()

        self.assertFalse(exit_code)
        self.assertEqual(self.notifier.wpt_github.calls, [
            'recent_failing_chromium_exports',
            'get_pr_branch',
            'get_branch_statuses',
        ])
        self.assertEqual(self.notifier.gerrit.cls_queried, ['decafbad'])
        self.assertEqual(self.notifier.gerrit.request_posted,
                         [('/a/changes/decafbad/revisions/current/review', {
                             'message': expected
                         })])
Beispiel #12
0
    def test_export_notifier_success(self):
        self.notifier.wpt_github = MockWPTGitHub(pull_requests=[])
        self.notifier.wpt_github.recent_failing_pull_requests = [
            PullRequest(
                title='title1',
                number=1234,
                body=
                'description\nWPT-Export-Revision: hash\nChange-Id: decafbad',
                state='open',
                labels=[''])
        ]
        status = [{
            "state": "failure",
            "context": "Community-TC (pull_request)",
            "node_id": "foo",
            "target_url": "bar"
        }]
        self.notifier.wpt_github.status = status

        self.notifier.dry_run = False
        self.notifier.gerrit = MockGerritAPI()
        self.notifier.gerrit.cl = MockGerritCL(data={
            'change_id':
            'decafbad',
            'messages': [
                {
                    "date": "2019-08-20 17:42:05.000000000",
                    "message": "Uploaded patch set 1.\nInitial upload",
                    "_revision_number": 1
                },
                {
                    "date":
                    "2019-08-21 17:41:05.000000000",
                    "message":
                    ('The exported PR for the current patch failed Taskcluster check(s) '
                     'on GitHub, which could indict cross-broswer failures on the '
                     'exportable changes. Please contact ecosystem-infra@ team for '
                     'more information.\n\n'
                     'Taskcluster Link: notbar\n'
                     'Gerrit CL SHA: notnum\n'
                     'Patchset Number: 3'),
                    "_revision_number":
                    2
                },
            ],
            'revisions': {
                'hash': {
                    '_number': 2
                }
            }
        },
                                               api=self.notifier.gerrit)
        expected = (
            'The exported PR for the current patch failed Taskcluster check(s) '
            'on GitHub, which could indict cross-broswer failures on the '
            'exportable changes. Please contact ecosystem-infra@ team for '
            'more information.\n\n'
            'Taskcluster Link: bar\n'
            'Gerrit CL SHA: hash\n'
            'Patchset Number: 2')

        exit_code = self.notifier.main()

        self.assertFalse(exit_code)
        self.assertEqual(self.notifier.wpt_github.calls, [
            'recent_failing_chromium_exports',
            'get_pr_branch',
            'get_branch_statuses',
        ])
        self.assertEqual(self.notifier.gerrit.cls_queried, ['decafbad'])
        self.assertEqual(self.notifier.gerrit.request_posted,
                         [('/a/changes/decafbad/revisions/current/review', {
                             'message': expected
                         })])
    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 <html>',
                             change_id='I001')),
            MockGerritCL(data={
                'change_id': 'I002',
                'subject': 'subject',
                '_number': 1235,
                '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='body',
                                                            change_id=None)),
        ]
        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"',
            '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 \\<html>\n\nChange-Id: I001\nReviewed-on: '
             'https://chromium-review.googlesource.com/1234\n'
             'WPT-Export-Revision: 1'),
            ('chromium-export-cl-1235', 'subject',
             'body\nChange-Id: I002\nReviewed-on: '
             'https://chromium-review.googlesource.com/1235\n'
             'WPT-Export-Revision: 1'),
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [])