Skip to content

Commit 4afb29e

Browse files
authored
Add support for multiple amplify URIs in monorepos (#67)
* Add support for multiple amplify URIs in monorepos * Remove comment
1 parent abc50f1 commit 4afb29e

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ The MS robot will automatically create a PR on your repository.
1717
If your repository is linked to AWS Amplify, you can dynamically update the
1818
Amplify hostname link. To do so, create a secret in your repository named
1919
`AWS_AMPLIFY_URI` with a value such as `https://pr-%.foo.live.mobsuccess.com`.
20+
21+
If your repository supports multiple domains, this value can be a JSON:
22+
23+
```json
24+
{
25+
"webapps/lcm": "https://pr-%.platform-lcm.live.mobsuccess.com",
26+
"webapps/lco": "https://pr-%.platform-lco.live.mobsuccess.com"
27+
}
28+
```

action.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,24 @@ async function checkIfCanMergeWithoutAsanaTask({ repository, pullRequest }) {
340340
return false;
341341
}
342342

343+
function getAwsAmplifyLiveUrls({ id, labels, amplifyUri }) {
344+
if (!amplifyUri) {
345+
return [];
346+
}
347+
const result = [];
348+
if (amplifyUri.match(/^{/)) {
349+
const amplifyUris = JSON.parse(amplifyUri);
350+
for (const label of labels) {
351+
if (amplifyUris[label]) {
352+
result.push(amplifyUris[label].replace("%", id));
353+
}
354+
}
355+
} else {
356+
result.push(amplifyUri.replace("%", id));
357+
}
358+
return result;
359+
}
360+
343361
exports.action = async function action() {
344362
// check if we run on a merge_group
345363
const {
@@ -366,6 +384,7 @@ exports.action = async function action() {
366384
});
367385
//console.log("pull", pullRequest);
368386
console.log("asanaPRStatus", asanaPRStatus);
387+
const labels = pullRequest.labels.map(({ name }) => name);
369388

370389
console.info(`Calling action ${action}`);
371390
switch (action) {
@@ -379,14 +398,16 @@ exports.action = async function action() {
379398
if (!taskId) {
380399
console.log("Cannot update Asana task: no taskId was found");
381400
} else {
401+
const amplifyLiveUrls = getAwsAmplifyLiveUrls({
402+
id: pullRequest.html_url.split("/"),
403+
labels,
404+
amplifyUri,
405+
});
382406
const updateOptions = {
383407
custom_fields: {
384-
...(amplifyUri
408+
...(amplifyLiveUrls.length
385409
? {
386-
[customFieldLive.gid]: amplifyUri.replace(
387-
"%",
388-
pullRequest.html_url.split("/").pop()
389-
),
410+
[customFieldLive.gid]: amplifyLiveUrls.join(" "),
390411
}
391412
: {}),
392413
...(storybookAmplifyUri

0 commit comments

Comments
 (0)