Skip to content

Commit

Permalink
Prod Testing - open a backdoor to dump all export_notifier comments t…
Browse files Browse the repository at this point in the history
…o a dummy CL.

It will read the comment history and dump all comments to https://chromium-review.googlesource.com/c/chromium/src/+/2241634/. Also tweak the Gerrit CL SHA so that the SHA is unique identified to each CL.

Testing command:
third_party/blink/tools/wpt_export.py --credentials ~/.credentials --surface-failures-to-gerrit

Output:
https://chromium-review.googlesource.com/c/chromium/src/+/2241634

Bug: 1027618
Change-Id: I3a4932524488072cdbb820ccabdd4dd9a079cd3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2242001
Commit-Queue: Kyle Ju <kyleju@chromium.org>
Reviewed-by: Robert Ma <robertma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#777952}
  • Loading branch information
Kyle Ju authored and Commit Bot committed Jun 12, 2020
1 parent 35a6d38 commit 14dc6de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
27 changes: 20 additions & 7 deletions third_party/blink/tools/blinkpy/w3c/export_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,21 @@ def process_failing_prs(self, gerrit_dict):
"""Processes and comments on CLs with failed TackCluster status."""
_log.info('Processing %d CLs with failed Taskcluster status.',
len(gerrit_dict))

# Uses a dummy CL to test export_notifier on prod. The real comments will be dumped to
# https://chromium-review.googlesource.com/c/chromium/src/+/2241634.
try:
dummy_cl = self.gerrit.query_cl_comments_and_revisions(
'I4fd5039cd4ec991bb8f840eabe55574b37243ef2')
except GerritError as e:
_log.error('Could not process Dummy CL: %s', str(e))
return

for change_id, pr_status_info in gerrit_dict.items():
try:
cl = self.gerrit.query_cl_comments_and_revisions(change_id)
has_commented = self.has_latest_taskcluster_status_commented(
cl.messages, pr_status_info)
dummy_cl.messages, pr_status_info)
if has_commented:
continue

Expand All @@ -110,7 +120,7 @@ def process_failing_prs(self, gerrit_dict):
_log.debug('Comments are:\n %s\n', cl_comment)
else:
_log.info('Commenting on CL %s\n', change_id)
cl.post_comment(cl_comment)
dummy_cl.post_comment(cl_comment)
except GerritError as e:
_log.error('Could not process Gerrit CL %s: %s', change_id,
str(e))
Expand All @@ -126,7 +136,8 @@ def has_latest_taskcluster_status_commented(self, messages,
"""
for message in reversed(messages):
cl_gerrit_sha = PRStatusInfo.get_gerrit_sha_from_comment(
message['message'])
message['message'], pr_status_info.pr_number)

if cl_gerrit_sha:
return cl_gerrit_sha == pr_status_info.gerrit_sha

Expand Down Expand Up @@ -196,10 +207,11 @@ def gerrit_sha(self):
return self._gerrit_sha

@staticmethod
def get_gerrit_sha_from_comment(comment):
def get_gerrit_sha_from_comment(comment, pr_number):
dummy_tag = str(pr_number) + PRStatusInfo.CL_SHA_TAG
for line in comment.splitlines():
if line.startswith(PRStatusInfo.CL_SHA_TAG):
return line[len(PRStatusInfo.CL_SHA_TAG):]
if line.startswith(dummy_tag):
return line[len(dummy_tag):]

return None

Expand All @@ -212,7 +224,8 @@ def to_gerrit_comment(self, patchset=None):
pr_url='%spull/%d' % (WPT_GH_URL, self.pr_number)
)
link_line = ('\n\n{}{}').format(PRStatusInfo.LINK_TAG, self.link)
sha_line = ('\n{}{}').format(PRStatusInfo.CL_SHA_TAG, self.gerrit_sha)
dummy_tag = str(self.pr_number) + PRStatusInfo.CL_SHA_TAG
sha_line = ('\n{}{}').format(dummy_tag, self.gerrit_sha)

comment = status_line + link_line + sha_line
if patchset is not None:
Expand Down
26 changes: 13 additions & 13 deletions third_party/blink/tools/blinkpy/w3c/export_notifier_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def test_get_gerrit_sha_from_comment_success(self):
gerrit_comment = self.generate_notifier_comment(
123, 'bar', 'num', None)

actual = PRStatusInfo.get_gerrit_sha_from_comment(gerrit_comment)
actual = PRStatusInfo.get_gerrit_sha_from_comment(gerrit_comment, 123)

self.assertEqual(actual, 'num')

def test_get_gerrit_sha_from_comment_fail(self):
gerrit_comment = 'ABC'

actual = PRStatusInfo.get_gerrit_sha_from_comment(gerrit_comment)
actual = PRStatusInfo.get_gerrit_sha_from_comment(gerrit_comment, 123)

self.assertIsNone(actual)

Expand Down Expand Up @@ -174,7 +174,7 @@ def test_process_failing_prs_success(self):

self.notifier.process_failing_prs(gerrit_dict)

self.assertEqual(self.notifier.gerrit.cls_queried, ['abc'])
self.assertEqual(self.notifier.gerrit.cls_queried, ['I4fd5039cd4ec991bb8f840eabe55574b37243ef2', 'abc'])
self.assertEqual(self.notifier.gerrit.request_posted,
[('/a/changes/abc/revisions/current/review', {
'message': expected
Expand All @@ -186,7 +186,7 @@ def test_process_failing_prs_has_commented(self):
self.notifier.gerrit.cl = MockGerritCL(
data={
'change_id':
'abc',
'I4fd5039cd4ec991bb8f840eabe55574b37243ef2',
'messages': [
{
"date": "2019-08-20 17:42:05.000000000",
Expand All @@ -212,7 +212,7 @@ def test_process_failing_prs_has_commented(self):

self.notifier.process_failing_prs(gerrit_dict)

self.assertEqual(self.notifier.gerrit.cls_queried, ['abc'])
self.assertEqual(self.notifier.gerrit.cls_queried, ['I4fd5039cd4ec991bb8f840eabe55574b37243ef2', 'abc'])
self.assertEqual(self.notifier.gerrit.request_posted, [])

def test_process_failing_prs_with_latest_sha(self):
Expand Down Expand Up @@ -248,7 +248,7 @@ def test_process_failing_prs_with_latest_sha(self):

self.notifier.process_failing_prs(gerrit_dict)

self.assertEqual(self.notifier.gerrit.cls_queried, ['abc'])
self.assertEqual(self.notifier.gerrit.cls_queried, ['I4fd5039cd4ec991bb8f840eabe55574b37243ef2', 'abc'])
self.assertEqual(self.notifier.gerrit.request_posted,
[('/a/changes/abc/revisions/current/review', {
'message': expected
Expand All @@ -261,11 +261,11 @@ def test_process_failing_prs_raise_gerrit_error(self):

self.notifier.process_failing_prs(gerrit_dict)

self.assertEqual(self.notifier.gerrit.cls_queried, ['abc'])
self.assertEqual(self.notifier.gerrit.cls_queried, ['I4fd5039cd4ec991bb8f840eabe55574b37243ef2'])
self.assertEqual(self.notifier.gerrit.request_posted, [])
self.assertLog([
'INFO: Processing 1 CLs with failed Taskcluster status.\n',
'ERROR: Could not process Gerrit CL abc: Error from query_cl\n'
'ERROR: Could not process Dummy CL: Error from query_cl\n'
])

def test_export_notifier_success(self):
Expand Down Expand Up @@ -323,7 +323,7 @@ def test_export_notifier_success(self):
'get_pr_branch',
'get_branch_statuses',
])
self.assertEqual(self.notifier.gerrit.cls_queried, ['decafbad'])
self.assertEqual(self.notifier.gerrit.cls_queried, ['I4fd5039cd4ec991bb8f840eabe55574b37243ef2', 'decafbad'])
self.assertEqual(self.notifier.gerrit.request_posted,
[('/a/changes/decafbad/revisions/current/review', {
'message': expected
Expand All @@ -337,11 +337,11 @@ def generate_notifier_comment(self, pr_number, link, sha, patchset=None):
'cross-broswer failures on the exported changes. Please contact '
'ecosystem-infra@ team for more information.\n\n'
'Taskcluster Link: {}\n'
'Gerrit CL SHA: {}\n'
'{}Gerrit CL SHA: {}\n'
'Patchset Number: {}'
'\n\nAny suggestions to improve this service is welcomed, '
'crbug.com/1027618.').format(
pr_number, link, sha, patchset
pr_number, link, pr_number, sha, patchset
)
else:
comment = (
Expand All @@ -350,9 +350,9 @@ def generate_notifier_comment(self, pr_number, link, sha, patchset=None):
'cross-broswer failures on the exported changes. Please contact '
'ecosystem-infra@ team for more information.\n\n'
'Taskcluster Link: {}\n'
'Gerrit CL SHA: {}'
'{}Gerrit CL SHA: {}'
'\n\nAny suggestions to improve this service is welcomed, '
'crbug.com/1027618.').format(
pr_number, link, sha
pr_number, link, pr_number, sha
)
return comment

0 comments on commit 14dc6de

Please sign in to comment.