Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #79 from Automattic/installable-builds/multiple-apks
Browse files Browse the repository at this point in the history
Handle multiple APKs installable for an Installable Build
  • Loading branch information
AliSoftware authored Jun 25, 2021
2 parents 40b5f17 + 26fa081 commit 7831693
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
11 changes: 7 additions & 4 deletions org/pr/installable-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,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 @@ -125,9 +125,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 @@ -176,4 +176,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})`)
})
})

0 comments on commit 7831693

Please sign in to comment.