1
0
Fork 0
robherley/dl-artifact-tmp
Rob Herley 2023-08-17 17:26:44 -04:00
parent 4047224a50
commit 59db55461a
No known key found for this signature in database
GPG Key ID: D1602042C3543B06
2 changed files with 43 additions and 5 deletions

View File

@ -1,11 +1,11 @@
import {ArtifactClient, Client} from './internal/client' import {ArtifactClient, Client} from './internal/client'
import {UploadOptions, UploadResponse} from './internal/shared/interfaces'
/** /**
* Exported functionality that we want to expose for any users of @actions/artifact * Exported functionality that we want to expose for any users of @actions/artifact
*/ */
export {ArtifactClient, UploadOptions, UploadResponse} export * from './internal/shared/interfaces'
export {ArtifactClient}
export function create(): ArtifactClient { export function create(): ArtifactClient {
return Client.create() return Client.create()
} }

View File

@ -1,7 +1,13 @@
import * as github from '@actions/github'
import * as core from '@actions/core'
import * as httpClient from '@actions/http-client'
import { import {
DownloadArtifactOptions, DownloadArtifactOptions,
DownloadArtifactResponse DownloadArtifactResponse
} from '../shared/interfaces' } from '../shared/interfaces'
// import { getUserAgentString } from '../shared/user-agent'
// import * as unzipper from 'unzipper'
export async function downloadArtifact( export async function downloadArtifact(
artifactId: number, artifactId: number,
@ -10,5 +16,37 @@ export async function downloadArtifact(
token: string, token: string,
options?: DownloadArtifactOptions options?: DownloadArtifactOptions
): Promise<DownloadArtifactResponse> { ): Promise<DownloadArtifactResponse> {
throw new Error('Not implemented') const api = github.getOctokit(token)
}
core.info(`Downloading artifact ${artifactId} from ${repositoryOwner}/${repositoryName}`)
const {headers, status} = await api.rest.actions.downloadArtifact({
owner: repositoryOwner,
repo: repositoryName,
artifact_id: artifactId,
archive_format: 'zip',
request: {
redirect: 'manual',
},
})
if (status !== 302) {
throw new Error(`Unable to download artifact. Unexpected status: ${status}`)
}
const { location } = headers
if (!location) {
throw new Error(`Unable to redirect to artifact download url`)
}
const scrubbedURL = new URL(location);
scrubbedURL.search = ''
console.log(`Redirecting to blob download url: ${scrubbedURL.toString()}`)
// const client = new httpClient.HttpClient(getUserAgentString(), [], {})
// const response = await client.get(location)
// response.message.pipe(unzipper.Extract({ path: options?.path }))
return {success: true}
}