Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions org/pr/installable-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async function circleCIArtifacts(status) {
}

async function getDownloadCommentText(status) {
const artifacts = await circleCIArtifacts(status)
const artifacts: Array<any> = await circleCIArtifacts(status)

const commentJsonArtifact = artifacts.find(artifact => artifact.path.endsWith("comment.json"))
if (commentJsonArtifact) {
Expand All @@ -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<any> = 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
}
Expand Down
25 changes: 25 additions & 0 deletions tests/installable-build-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Copy link
Contributor Author

@AliSoftware AliSoftware Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this unit test is just a shameless copy/paste of the previous unit test (lines 133-153) for single-APK case, adjusted to have a mockedArtifacts containing multiple APKs and an adjusted expectation.

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})`)
})
})