diff --git a/org/pr/installable-build.ts b/org/pr/installable-build.ts index 72ca0ea..951da6a 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.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 ccf659c..36eecb9 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: 'Artifacts/file1.apk', + url: 'https://circleci.com/artifacts/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})`) + }) })