Skip to content

Commit

Permalink
fix: which links ends up in linear preview [DEVOP-665] (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippeauriach authored Nov 26, 2024
1 parent 8d34e4e commit 7f38700
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
32 changes: 12 additions & 20 deletions lib/actions/amplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }] };
}
};
10 changes: 9 additions & 1 deletion lib/actions/pullRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) =>
Expand Down

0 comments on commit 7f38700

Please sign in to comment.