diff --git a/packages/artifact/src/artifact.ts b/packages/artifact/src/artifact.ts index b566df8e..733db18c 100644 --- a/packages/artifact/src/artifact.ts +++ b/packages/artifact/src/artifact.ts @@ -1,11 +1,11 @@ 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() -} +} \ No newline at end of file diff --git a/packages/artifact/src/internal/download/download-artifact.ts b/packages/artifact/src/internal/download/download-artifact.ts index 7e9dfbfd..739c5bfe 100644 --- a/packages/artifact/src/internal/download/download-artifact.ts +++ b/packages/artifact/src/internal/download/download-artifact.ts @@ -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 { - 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} +} \ No newline at end of file