Display a Docs-Preview link for each modified MD file

Bug: skia:11824
Change-Id: I6bd557affca5ccf9f2936d86e2b0da168ceb2670
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/390577
Commit-Queue: Ravi Mistry <rmistry@google.com>
Reviewed-by: Joe Gregorio <jcgregorio@google.com>
This commit is contained in:
Ravi Mistry 2021-04-01 16:09:51 -04:00 committed by Skia Commit-Bot
parent 988b7043e5
commit 42d753031d

View File

@ -37,7 +37,9 @@ PUBLIC_API_OWNERS = (
AUTHORS_FILE_NAME = 'AUTHORS'
RELEASE_NOTES_FILE_NAME = 'RELEASE_NOTES.txt'
DOCS_PREVIEW_URL = 'https://skia.org/?cl={issue}'
DOCS_PREVIEW_URL_TMPL = 'https://skia.org/{path}?cl={issue}'
DOCS_INDEX = '_index'
GOLD_TRYBOT_URL = 'https://gold.skia.org/search?issue='
SERVICE_ACCOUNT_SUFFIX = [
@ -470,17 +472,22 @@ def PostUploadHook(gerrit, change, output_api):
return []
results = []
at_least_one_docs_change = False
all_docs_changes = True
docs_preview_links = []
for affected_file in change.AffectedFiles():
affected_file_path = affected_file.LocalPath()
file_path, _ = os.path.splitext(affected_file_path)
if 'site' == file_path.split(os.path.sep)[0]:
at_least_one_docs_change = True
top_level_dir = file_path.split(os.path.sep)[0]
if 'site' == top_level_dir:
site_path = os.path.sep.join(file_path.split(os.path.sep)[1:])
# Strip DOCS_INDEX from the site_path to construct the docs_preview_link.
if site_path.endswith(DOCS_INDEX):
site_path = site_path[:-len(DOCS_INDEX)]
docs_preview_link = DOCS_PREVIEW_URL_TMPL.format(
path=site_path, issue=change.issue)
docs_preview_links.append(docs_preview_link)
else:
all_docs_changes = False
if at_least_one_docs_change and not all_docs_changes:
break
footers = change.GitFootersFromDescription()
description_changed = False
@ -495,18 +502,18 @@ def PostUploadHook(gerrit, change, output_api):
'This change has only doc changes. Automatically added '
'\'No-Try: true\' to the CL\'s description'))
# If there is at least one docs change then add preview link in the CL's
# description if it does not already exist there.
docs_preview_link = DOCS_PREVIEW_URL.format(issue=change.issue)
if (at_least_one_docs_change
and docs_preview_link not in footers.get('Docs-Preview', [])):
# Automatically add a link to where the docs can be previewed.
description_changed = True
change.AddDescriptionFooter('Docs-Preview', docs_preview_link)
results.append(
output_api.PresubmitNotifyResult(
'Automatically added a link to preview the docs changes to the '
'CL\'s description'))
# Add all preview links that do not already exist in the description.
if len(docs_preview_links) > 0:
missing_preview_links = list(
set(docs_preview_links) - set(footers.get('Docs-Preview', [])))
if len(missing_preview_links) > 0:
description_changed = True
for missing_link in missing_preview_links:
change.AddDescriptionFooter('Docs-Preview', missing_link)
results.append(
output_api.PresubmitNotifyResult(
'Automatically added link(s) to preview the docs changes to '
'the CL\'s description'))
# If the description has changed update it.
if description_changed: