From e6902afc05c0209b218c2c5907b4732602d02a11 Mon Sep 17 00:00:00 2001
From: Philippe Auriach
Date: Wed, 13 Nov 2024 16:40:51 +0100
Subject: [PATCH 1/3] feat: add linear previews links
---
lib/actions/amplify.js | 10 +++++++---
lib/actions/pullRequest.js | 24 ++++++++++++++----------
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/lib/actions/amplify.js b/lib/actions/amplify.js
index f5dfb24b..3fc208ca 100644
--- a/lib/actions/amplify.js
+++ b/lib/actions/amplify.js
@@ -20,18 +20,22 @@ exports.getAmplifyURIs = async function getAmplifyURI() {
const amplifyUris = JSON.parse(amplifyUri);
const hasAtLeastOnePackageOrConfig = labels.some(
- (label) => label.startsWith("packages/") || label.startsWith("configs/")
+ (label) => label.startsWith("packages/") || label.startsWith("configs/"),
);
if (hasAtLeastOnePackageOrConfig) {
- return { links: Object.values(amplifyUris) };
+ return {
+ links: Object.entries(amplifyUris).reduce((acc, [label, url]) => {
+ return { ...acc, label, url };
+ }, {}),
+ };
}
const links = [];
const hiddenLinks = [];
for (const label of labels) {
if (amplifyUris[label]) {
- links.push(amplifyUris[label]);
+ links.push({ label, url: amplifyUris[label] });
}
}
for (const [key, url] of Object.entries(amplifyUris)) {
diff --git a/lib/actions/pullRequest.js b/lib/actions/pullRequest.js
index 8fb5bf5d..45fe60ac 100644
--- a/lib/actions/pullRequest.js
+++ b/lib/actions/pullRequest.js
@@ -29,19 +29,19 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {
!baseRef.match(/^hotfix\//)
) {
throw new Error(
- `As this pull request is based on “${baseRef}”, its name should start with “${baseRef}--”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`
+ `As this pull request is based on “${baseRef}”, its name should start with “${baseRef}--”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`,
);
}
if (!isBranchNameValid(headRef)) {
throw new Error(
- `This pull request is based on a branch with in invalid name: “${headRef}”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`
+ `This pull request is based on a branch with in invalid name: “${headRef}”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`,
);
}
if (!isPullRequestTitleValid(title)) {
throw new Error(
- `The title of this pull request is invalid, please edit: “${title}”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`
+ `The title of this pull request is invalid, please edit: “${title}”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`,
);
}
@@ -90,21 +90,25 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {
pullRequest?.base.repo.name || issue?.repository_url?.split("/")[5];
const comments = await octokit.paginate(
"GET /repos/{owner}/{repo}/issues/{issue_number}/comments",
- { owner, repo, issue_number: pullNumber }
+ { owner, repo, issue_number: pullNumber },
);
// add a comment with the PR
const body =
"AWS Amplify live test URI:\n" +
"- " +
- amplifyUris.join("\n- ") +
+ amplifyUris
+ .map(
+ (elt) => `[${elt.label?.split("/")?.unshift()} preview](${elt.url})`,
+ )
+ .join("\n- ") +
hiddenAmplifyText;
const previousComments = comments.filter(({ body }) =>
- body.match(/AWS Amplify live/)
+ body.match(/AWS Amplify live/),
);
if (previousComments.length > 0) {
console.log(
- "A comment already exists with a link to AWS Amplify, editing it"
+ "A comment already exists with a link to AWS Amplify, editing it",
);
const firstComment = previousComments[0];
await octokit.request(
@@ -114,7 +118,7 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {
repo,
comment_id: firstComment.id,
body,
- }
+ },
);
} else {
console.log("Comment with link to Amplify URI missing, creating it");
@@ -125,13 +129,13 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {
repo,
issue_number: pullNumber,
body,
- }
+ },
);
}
// delete the bogus comments by the aws-amplify robot
const bogusComments = comments.filter(({ user: { login } }) =>
- login.match(/^aws-amplify-/)
+ login.match(/^aws-amplify-/),
);
for (const bogusComment of bogusComments) {
const { id: commentId } = bogusComment;
From 034e590ec90db7972a4c2031a740e8c781c5e71f Mon Sep 17 00:00:00 2001
From: Philippe Auriach
Date: Wed, 13 Nov 2024 16:56:40 +0100
Subject: [PATCH 2/3] try with pop
---
lib/actions/pullRequest.js | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/lib/actions/pullRequest.js b/lib/actions/pullRequest.js
index 45fe60ac..68b9298b 100644
--- a/lib/actions/pullRequest.js
+++ b/lib/actions/pullRequest.js
@@ -98,9 +98,7 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {
"AWS Amplify live test URI:\n" +
"- " +
amplifyUris
- .map(
- (elt) => `[${elt.label?.split("/")?.unshift()} preview](${elt.url})`,
- )
+ .map((elt) => `[${elt.label?.split("/")?.pop()} preview](${elt.url})`)
.join("\n- ") +
hiddenAmplifyText;
const previousComments = comments.filter(({ body }) =>
From bc0a215cf8d173e7e790581feff214749a09bef2 Mon Sep 17 00:00:00 2001
From: Philippe Auriach
Date: Wed, 13 Nov 2024 18:31:41 +0100
Subject: [PATCH 3/3] fix prettier
---
lib/actions/amplify.js | 2 +-
lib/actions/pullRequest.js | 18 +++++++++---------
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/lib/actions/amplify.js b/lib/actions/amplify.js
index 3fc208ca..2be2ca78 100644
--- a/lib/actions/amplify.js
+++ b/lib/actions/amplify.js
@@ -20,7 +20,7 @@ exports.getAmplifyURIs = async function getAmplifyURI() {
const amplifyUris = JSON.parse(amplifyUri);
const hasAtLeastOnePackageOrConfig = labels.some(
- (label) => label.startsWith("packages/") || label.startsWith("configs/"),
+ (label) => label.startsWith("packages/") || label.startsWith("configs/")
);
if (hasAtLeastOnePackageOrConfig) {
diff --git a/lib/actions/pullRequest.js b/lib/actions/pullRequest.js
index 68b9298b..48ff605b 100644
--- a/lib/actions/pullRequest.js
+++ b/lib/actions/pullRequest.js
@@ -29,19 +29,19 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {
!baseRef.match(/^hotfix\//)
) {
throw new Error(
- `As this pull request is based on “${baseRef}”, its name should start with “${baseRef}--”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`,
+ `As this pull request is based on “${baseRef}”, its name should start with “${baseRef}--”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`
);
}
if (!isBranchNameValid(headRef)) {
throw new Error(
- `This pull request is based on a branch with in invalid name: “${headRef}”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`,
+ `This pull request is based on a branch with in invalid name: “${headRef}”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`
);
}
if (!isPullRequestTitleValid(title)) {
throw new Error(
- `The title of this pull request is invalid, please edit: “${title}”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`,
+ `The title of this pull request is invalid, please edit: “${title}”. See https://github.com/mobsuccess-devops/rfc/blob/master/docs/decisions/0009-convention-nommage-branch-pr.md`
);
}
@@ -90,7 +90,7 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {
pullRequest?.base.repo.name || issue?.repository_url?.split("/")[5];
const comments = await octokit.paginate(
"GET /repos/{owner}/{repo}/issues/{issue_number}/comments",
- { owner, repo, issue_number: pullNumber },
+ { owner, repo, issue_number: pullNumber }
);
// add a comment with the PR
@@ -102,11 +102,11 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {
.join("\n- ") +
hiddenAmplifyText;
const previousComments = comments.filter(({ body }) =>
- body.match(/AWS Amplify live/),
+ body.match(/AWS Amplify live/)
);
if (previousComments.length > 0) {
console.log(
- "A comment already exists with a link to AWS Amplify, editing it",
+ "A comment already exists with a link to AWS Amplify, editing it"
);
const firstComment = previousComments[0];
await octokit.request(
@@ -116,7 +116,7 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {
repo,
comment_id: firstComment.id,
body,
- },
+ }
);
} else {
console.log("Comment with link to Amplify URI missing, creating it");
@@ -127,13 +127,13 @@ exports.validatePR = async function validatePR({ pullRequest, issue }) {
repo,
issue_number: pullNumber,
body,
- },
+ }
);
}
// delete the bogus comments by the aws-amplify robot
const bogusComments = comments.filter(({ user: { login } }) =>
- login.match(/^aws-amplify-/),
+ login.match(/^aws-amplify-/)
);
for (const bogusComment of bogusComments) {
const { id: commentId } = bogusComment;