def test_process_failing_prs_has_commented(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, 'bar', 'SHA', 3), "_revision_number": 2 }, ], 'revisions': { 'SHA': { '_number': 1 } } }, api=self.notifier.gerrit) gerrit_dict = {'abc': PRStatusInfo('bar', 123, 'SHA')} self.notifier.process_failing_prs(gerrit_dict) self.assertEqual(self.notifier.gerrit.cls_queried, ['abc']) self.assertEqual(self.notifier.gerrit.request_posted, [])
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, [])
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, [])
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, [])
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' ])
def test_query_cl_raise_exception(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(raise_error=True) 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'])
def test_process_failing_prs_success(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": ('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 Node ID: notfoo\n' 'Taskcluster Link: bar\n' 'Gerrit CL SHA: notnum\n' 'Patchset Number: 3'), "_revision_number": 2 }, ], 'revisions': { 'num': { '_number': 1 } } }, api=self.notifier.gerrit) gerrit_dict = {'abc': PRStatusInfo('foo', 'bar', 'num')} 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 Node ID: foo\n' 'Taskcluster Link: bar\n' 'Gerrit CL SHA: num\n' 'Patchset Number: 1') 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 })])
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.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.get_exportable_commits = lambda: ([ MockChromiumCommit(self.host, position='refs/heads/master@{#458475}'), MockChromiumCommit(self.host, position='refs/heads/master@{#458476}'), ], []) success = test_exporter.main( ['--credentials-json', '/tmp/credentials.json', '--dry-run']) self.assertTrue(success) self.assertEqual(test_exporter.wpt_github.calls, [ 'pr_with_change_id', 'pr_for_chromium_commit', 'pr_for_chromium_commit', ]) self.assertEqual(len(test_exporter.gerrit.request_posted), 0)
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': { 'SHA': { '_number': 1 } } }, api=self.notifier.gerrit) checks_results = {'key1': 'val1', 'key2': 'val2'} result_comment = '\nkey2 (val2)\nkey1 (val1)' expected = self.generate_notifier_comment(123, result_comment, '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 })])
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, '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_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 })])
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 })])
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 })])