From 42d753031d3f8a7d1bfed9cecfda0bd0f082280f Mon Sep 17 00:00:00 2001 From: Ravi Mistry Date: Thu, 1 Apr 2021 16:09:51 -0400 Subject: [PATCH] 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 Reviewed-by: Joe Gregorio --- PRESUBMIT.py | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 75c4b70149..6d9e6b25ed 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -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: