Skip to content

Commit

Permalink
Pass auth token to got request
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner committed Feb 15, 2021
1 parent 52024f7 commit 8819b4b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
23 changes: 13 additions & 10 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/input-providers/artifact-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class ArtifactProvider implements InputProvider {
readonly name: string,
readonly pattern: string[],
readonly sha: string,
readonly runId: number
readonly runId: number,
readonly token: string
) {
if (this.artifact.startsWith('/')) {
const endIndex = this.artifact.lastIndexOf('/')
Expand Down Expand Up @@ -66,7 +67,7 @@ export class ArtifactProvider implements InputProvider {
}

for (const art of artifacts) {
await downloadArtifact(this.octokit, art.id, art.name)
await downloadArtifact(this.octokit, art.id, art.name, this.token)
const reportName = this.getReportName(art.name)
const files: FileContent[] = []
const zip = new Zip(art.name)
Expand Down
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ class TestReporter {
const pattern = this.path.split(',')

const inputProvider = this.artifact
? new ArtifactProvider(this.octokit, this.artifact, this.name, pattern, this.context.sha, this.context.runId)
? new ArtifactProvider(
this.octokit,
this.artifact,
this.name,
pattern,
this.context.sha,
this.context.runId,
this.token
)
: new LocalFileProvider(this.name, pattern)

const parseErrors = this.maxAnnotations > 0
Expand Down
17 changes: 10 additions & 7 deletions src/utils/github-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export function getCheckRunContext(): {sha: string; runId: number} {
export async function downloadArtifact(
octokit: InstanceType<typeof GitHub>,
artifactId: number,
fileName: string
fileName: string,
token: string
): Promise<void> {
core.startGroup(`Downloading artifact ${fileName}`)
try {
Expand All @@ -44,9 +45,11 @@ export async function downloadArtifact(
archive_format: 'zip'
})

const resp = await got({
url: req.url,
headers: req.headers as {[header: string]: string},
const headers = {
Authorization: `Bearer ${token}`
}
const resp = await got(req.url, {
headers,
followRedirect: false
})

Expand All @@ -57,15 +60,15 @@ export async function downloadArtifact(

const url = resp.headers.location
if (url === undefined) {
const headers = Object.keys(resp.headers)
core.info(`Received headers: ${headers.join(', ')}`)
const receivedHeaders = Object.keys(resp.headers)
core.info(`Received headers: ${receivedHeaders.join(', ')}`)
throw new Error('Location header was not found in API response')
}
if (typeof url !== 'string') {
throw new Error(`Location header has unexpected value: ${url}`)
}

const downloadStream = got.stream(url)
const downloadStream = got.stream(url, {headers})
const fileWriterStream = createWriteStream(fileName)

core.info(`Downloading ${url}`)
Expand Down

0 comments on commit 8819b4b

Please sign in to comment.