From 7f387002096e8d90d6af481a824568d2ed3be21e Mon Sep 17 00:00:00 2001 From: Philippe Auriach <920265+philippeauriach@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:34:16 +0100 Subject: [PATCH] fix: which links ends up in linear preview [DEVOP-665] (#105) --- lib/actions/amplify.js | 32 ++++++++++++-------------------- lib/actions/pullRequest.js | 10 +++++++++- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/actions/amplify.js b/lib/actions/amplify.js index 07e7dc03..f53fff4f 100644 --- a/lib/actions/amplify.js +++ b/lib/actions/amplify.js @@ -23,30 +23,22 @@ exports.getAmplifyURIs = async function getAmplifyURI() { (label) => label.startsWith("packages/") || label.startsWith("configs/") ); - if (hasAtLeastOnePackageOrConfig) { + const allLinks = Object.entries(amplifyUris).map(([label, url]) => { + const hasLabel = labels.some((l) => label.includes(l)); return { - links: Object.entries(amplifyUris).map(([label, url]) => { - return { label, url }; - }), + label, + url, + isVisibleInComment: hasAtLeastOnePackageOrConfig || hasLabel, + hasPreview: hasLabel, }; - } - - const links = []; - const hiddenLinks = []; - for (const label of labels) { - if (amplifyUris[label]) { - links.push({ label, url: amplifyUris[label] }); - } - } - for (const [key, url] of Object.entries(amplifyUris)) { - if (!labels.includes(key)) { - hiddenLinks.push(url); - } - } - return { links, hiddenLinks }; + }); + return { + links: allLinks.filter((l) => l.isVisibleInComment), + hiddenLinks: allLinks.filter((l) => !l.isVisibleInComment), + }; } else if (!amplifyUri) { return {}; } else { - return { links: [amplifyUri] }; + return { links: [{ url: amplifyUri, hasPreview: true }] }; } }; diff --git a/lib/actions/pullRequest.js b/lib/actions/pullRequest.js index 48ff605b..44ddcbe5 100644 --- a/lib/actions/pullRequest.js +++ b/lib/actions/pullRequest.js @@ -98,7 +98,15 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) { "AWS Amplify live test URI:\n" + "- " + amplifyUris - .map((elt) => `[${elt.label?.split("/")?.pop()} preview](${elt.url})`) + .map( + (elt) => + `[${[ + elt.label?.split("/")?.pop(), + elt.hasPreview ? " preview" : undefined, // any link with "preview" in the label will be displayed in the linked linear issue + ] + .filter(Boolean) + .join(" ")}](${elt.url})` + ) .join("\n- ") + hiddenAmplifyText; const previousComments = comments.filter(({ body }) =>