From 79afb7107096461e3ef67813736525d56d05bac2 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Fri, 25 Jun 2021 13:06:09 +0200 Subject: [PATCH 1/3] Handle multiple APKs installable for an Installable Build --- org/pr/installable-build.ts | 11 +++++++---- tests/installable-build-test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/org/pr/installable-build.ts b/org/pr/installable-build.ts index 72ca0ea..38bcd8d 100644 --- a/org/pr/installable-build.ts +++ b/org/pr/installable-build.ts @@ -106,7 +106,7 @@ async function circleCIArtifacts(status) { } async function getDownloadCommentText(status) { - const artifacts = await circleCIArtifacts(status) + const artifacts: Array = await circleCIArtifacts(status) const commentJsonArtifact = artifacts.find(artifact => artifact.path.endsWith("comment.json")) if (commentJsonArtifact) { @@ -123,9 +123,12 @@ async function getDownloadCommentText(status) { } } - const apkArtifact = artifacts.find(artifact => artifact.path.endsWith(".apk")) - if (apkArtifact) { - return `You can test the changes on this Pull Request by downloading the APK [here](${apkArtifact.url}).` + const apkArtifacts: Array = artifacts.filter(artifact => artifact.path.endsWith(".apk")) + if (apkArtifacts.length == 1) { + return `You can test the changes on this Pull Request by downloading the APK [here](${apkArtifacts[0].url}).` + } else if (apkArtifacts.length > 1) { + const links = apkArtifacts.map(artifact => `- [${artifact.path}](${artifact.url})`).join(`\n`) + return `You can test the changes on this Pull Request by downloading the APKs:\n${links}.` } return undefined } diff --git a/tests/installable-build-test.ts b/tests/installable-build-test.ts index ccf659c..36b849d 100644 --- a/tests/installable-build-test.ts +++ b/tests/installable-build-test.ts @@ -151,4 +151,29 @@ describe("installable build handling", () => { expectComment(webhook, `You can test the changes on this Pull Request by downloading the APK [here](${mockedArtifacts[0].url}).`) }) + + it("Posts a download comment linking to multiple APKs", async () => { + mockedArtifacts = [{ + path: 'file1.apk', + url: 'https://circleci.com/file1.apk' + },{ + path: 'file2.apk', + url: 'https://circleci.com/file2.apk' + }] + + const webhook: any = { + state: "success", + context: "ci/circleci: Installable Build", + description: "Building", + target_url: "https://circleci.com/gh/Owner/Repo/12345?some=query", + repository: { + name: 'Repo', + owner: { login: 'Owner' } + }, + commit: { sha: 'abc' } + } + await installableBuild(webhook) + + expectComment(webhook, `You can test the changes on this Pull Request by downloading the APKs:\n- [file1.apk](${mockedArtifacts[0].url})\n- [file2.apk](${mockedArtifacts[1].url}).`) + }) }) From 78af5a8205f4e679f1e8bc5f932c68ed61f18bf9 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Fri, 25 Jun 2021 13:28:15 +0200 Subject: [PATCH 2/3] Only use file basename as link text instead of full path --- org/pr/installable-build.ts | 2 +- tests/installable-build-test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org/pr/installable-build.ts b/org/pr/installable-build.ts index 38bcd8d..ec6128e 100644 --- a/org/pr/installable-build.ts +++ b/org/pr/installable-build.ts @@ -127,7 +127,7 @@ async function getDownloadCommentText(status) { if (apkArtifacts.length == 1) { return `You can test the changes on this Pull Request by downloading the APK [here](${apkArtifacts[0].url}).` } else if (apkArtifacts.length > 1) { - const links = apkArtifacts.map(artifact => `- [${artifact.path}](${artifact.url})`).join(`\n`) + const links = apkArtifacts.map(artifact => `- [${artifact.path.split("/").pop()}](${artifact.url})`).join(`\n`) return `You can test the changes on this Pull Request by downloading the APKs:\n${links}.` } return undefined diff --git a/tests/installable-build-test.ts b/tests/installable-build-test.ts index 36b849d..7c1e3c1 100644 --- a/tests/installable-build-test.ts +++ b/tests/installable-build-test.ts @@ -154,8 +154,8 @@ describe("installable build handling", () => { it("Posts a download comment linking to multiple APKs", async () => { mockedArtifacts = [{ - path: 'file1.apk', - url: 'https://circleci.com/file1.apk' + path: 'Artifacts/file1.apk', + url: 'https://circleci.com/artifacts/file1.apk' },{ path: 'file2.apk', url: 'https://circleci.com/file2.apk' From 26fa0810726ad56bfb8dd11bd982c862a3e7ed38 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Fri, 25 Jun 2021 18:07:53 +0200 Subject: [PATCH 3/3] Fix wording Thanks @hypest --- org/pr/installable-build.ts | 4 ++-- tests/installable-build-test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org/pr/installable-build.ts b/org/pr/installable-build.ts index ec6128e..951da6a 100644 --- a/org/pr/installable-build.ts +++ b/org/pr/installable-build.ts @@ -127,8 +127,8 @@ async function getDownloadCommentText(status) { if (apkArtifacts.length == 1) { return `You can test the changes on this Pull Request by downloading the APK [here](${apkArtifacts[0].url}).` } else if (apkArtifacts.length > 1) { - const links = apkArtifacts.map(artifact => `- [${artifact.path.split("/").pop()}](${artifact.url})`).join(`\n`) - return `You can test the changes on this Pull Request by downloading the APKs:\n${links}.` + const links = apkArtifacts.map(artifact => ` - [${artifact.path.split("/").pop()}](${artifact.url})`).join(`\n`) + return `You can test the changes on this Pull Request by downloading the APKs:\n${links}` } return undefined } diff --git a/tests/installable-build-test.ts b/tests/installable-build-test.ts index 7c1e3c1..36eecb9 100644 --- a/tests/installable-build-test.ts +++ b/tests/installable-build-test.ts @@ -174,6 +174,6 @@ describe("installable build handling", () => { } await installableBuild(webhook) - expectComment(webhook, `You can test the changes on this Pull Request by downloading the APKs:\n- [file1.apk](${mockedArtifacts[0].url})\n- [file2.apk](${mockedArtifacts[1].url}).`) + expectComment(webhook, `You can test the changes on this Pull Request by downloading the APKs:\n - [file1.apk](${mockedArtifacts[0].url})\n - [file2.apk](${mockedArtifacts[1].url})`) }) })