Skip to content

Commit

Permalink
Add Display all monorepo amplify urls (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippeauriach committed Aug 22, 2023
1 parent b7292b8 commit 198998d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
31 changes: 24 additions & 7 deletions lib/actions/amplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,43 @@ exports.getAmplifyURIs = async function getAmplifyURI() {
const issue = github.context.payload.issue;
const pullNumber = pullRequest?.number || issue?.number;
const labels =
pullRequest?.labels.map((label) => label.name) ||
issue?.labels.map((label) => label.name);
pullRequest?.labels.map((label) => label.name) ??
issue?.labels.map((label) => label.name) ??
[];

const amplifyUriRaw = core.getInput("amplify-uri");
if (!amplifyUriRaw) {
console.log("No input for amplify-uri");
return;
}
const amplifyUri = amplifyUriRaw.replace(/%/g, pullNumber);
if (amplifyUri.match(/^{/)) {
const result = [];
const amplifyUris = JSON.parse(amplifyUri);

const hasAtLeastOnePackageOrConfig = labels.some(
(label) => label.startsWith("packages/") || label.startsWith("configs/")
);

if (hasAtLeastOnePackageOrConfig) {
return { links: Object.values(amplifyUris) };
}

const links = [];
const hiddenLinks = [];
for (const label of labels) {
if (amplifyUris[label]) {
result.push(amplifyUris[label]);
links.push(amplifyUris[label]);
}
}
for (const [key, url] of Object.entries(amplifyUris)) {
if (!labels.includes(key)) {
hiddenLinks.push(url);
}
}
return result;
return { links, hiddenLinks };
} else if (!amplifyUri) {
return null;
return {};
} else {
return [amplifyUri];
return { links: [amplifyUri] };
}
};
26 changes: 21 additions & 5 deletions lib/actions/pullRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,23 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {

// do we have an AWS Amplify URI? If so, make sure that at least one comment
// exists with a link to it
const amplifyUris = await getAmplifyURIs();
if (!amplifyUris) {
console.log("No AWS Amplify URI for this repository");
const {
links: amplifyUris,
hiddenLinks: hiddenAmplifyUris,
} = await getAmplifyURIs();
const hiddenAmplifyText =
hiddenAmplifyUris && hiddenAmplifyUris.length > 0
? `\n<details>
<summary>More uris</summary>
- ${hiddenAmplifyUris.join("\n -")}
</details>`
: "";
if (!amplifyUris || amplifyUris.length === 0) {
console.log("No AWS Amplify URI for this repository" + hiddenAmplifyText);
} else {
console.log("AWS Amplify URIs: ", amplifyUris);
console.log("AWS Amplify URIs: ", amplifyUris, "hidden", hiddenAmplifyUris);
const pullNumber = pullRequest?.number || issue?.number;
const owner =
pullRequest?.base.repo.owner.login ||
Expand All @@ -138,7 +150,11 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {
);

// add a comment with the PR
const body = "AWS Amplify live test URI:\n" + amplifyUris.join("\n");
const body =
"AWS Amplify live test URI:\n" +
"- " +
amplifyUris.join("\n- ") +
hiddenAmplifyText;
const previousComments = comments.filter(({ body }) =>
body.match(/AWS Amplify live/)
);
Expand Down

0 comments on commit 198998d

Please sign in to comment.