mirror of https://github.com/actions/toolkit
wip
parent
4047224a50
commit
59db55461a
|
@ -1,10 +1,10 @@
|
|||
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
|
||||
*/
|
||||
export {ArtifactClient, UploadOptions, UploadResponse}
|
||||
export * from './internal/shared/interfaces'
|
||||
export {ArtifactClient}
|
||||
|
||||
export function create(): ArtifactClient {
|
||||
return Client.create()
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
|
||||
import * as github from '@actions/github'
|
||||
import * as core from '@actions/core'
|
||||
import * as httpClient from '@actions/http-client'
|
||||
import {
|
||||
DownloadArtifactOptions,
|
||||
DownloadArtifactResponse
|
||||
} from '../shared/interfaces'
|
||||
// import { getUserAgentString } from '../shared/user-agent'
|
||||
// import * as unzipper from 'unzipper'
|
||||
|
||||
export async function downloadArtifact(
|
||||
artifactId: number,
|
||||
|
@ -10,5 +16,37 @@ export async function downloadArtifact(
|
|||
token: string,
|
||||
options?: DownloadArtifactOptions
|
||||
): 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}
|
||||
}
|
Loading…
Reference in New Issue