mirror of
https://github.com/actions/toolkit
synced 2025-05-10 09:03:02 +00:00
consistent promise behavior for get artifact
This commit is contained in:
parent
75a3586061
commit
d3c5f358d1
4 changed files with 29 additions and 40 deletions
|
@ -10,6 +10,7 @@ import {getBackendIdsFromToken} from '../shared/util'
|
|||
import {getUserAgentString} from '../shared/user-agent'
|
||||
import {internalArtifactTwirpClient} from '../shared/artifact-twirp-client'
|
||||
import {ListArtifactsRequest, StringValue, Timestamp} from '../../generated'
|
||||
import {ArtifactNotFoundError, InvalidResponseError} from '../shared/errors'
|
||||
|
||||
export async function getArtifactPublic(
|
||||
artifactName: string,
|
||||
|
@ -41,17 +42,13 @@ export async function getArtifactPublic(
|
|||
)
|
||||
|
||||
if (getArtifactResp.status !== 200) {
|
||||
core.warning(`non-200 response from GitHub API: ${getArtifactResp.status}`)
|
||||
return {
|
||||
success: false
|
||||
}
|
||||
throw new InvalidResponseError(
|
||||
`Invalid response from GitHub API: ${getArtifactResp.status} (${getArtifactResp?.headers?.['x-github-request-id']})`
|
||||
)
|
||||
}
|
||||
|
||||
if (getArtifactResp.data.artifacts.length === 0) {
|
||||
core.warning('no artifacts found')
|
||||
return {
|
||||
success: false
|
||||
}
|
||||
throw new ArtifactNotFoundError(artifactName)
|
||||
}
|
||||
|
||||
let artifact = getArtifactResp.data.artifacts[0]
|
||||
|
@ -63,7 +60,6 @@ export async function getArtifactPublic(
|
|||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
artifact: {
|
||||
name: artifact.name,
|
||||
id: artifact.id,
|
||||
|
@ -90,10 +86,7 @@ export async function getArtifactInternal(
|
|||
const res = await artifactClient.ListArtifacts(req)
|
||||
|
||||
if (res.artifacts.length === 0) {
|
||||
core.warning('no artifacts found')
|
||||
return {
|
||||
success: false
|
||||
}
|
||||
throw new ArtifactNotFoundError(artifactName)
|
||||
}
|
||||
|
||||
let artifact = res.artifacts[0]
|
||||
|
@ -103,12 +96,11 @@ export async function getArtifactInternal(
|
|||
)[0]
|
||||
|
||||
core.debug(
|
||||
`more than one artifact found for a single name, returning newest (id: ${artifact.databaseId})`
|
||||
`More than one artifact found for a single name, returning newest (id: ${artifact.databaseId})`
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
artifact: {
|
||||
name: artifact.name,
|
||||
id: Number(artifact.databaseId),
|
||||
|
|
|
@ -19,3 +19,11 @@ export class InvalidResponseError extends Error {
|
|||
this.name = 'InvalidResponseError'
|
||||
}
|
||||
}
|
||||
|
||||
export class ArtifactNotFoundError extends Error {
|
||||
constructor(name: string) {
|
||||
const message = `No artifact found for name: ${name}`
|
||||
super(message)
|
||||
this.name = 'ArtifactNotFoundError'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,11 +53,6 @@ export interface UploadArtifactOptions {
|
|||
*****************************************************************************/
|
||||
|
||||
export interface GetArtifactResponse {
|
||||
/**
|
||||
* If an artifact was found
|
||||
*/
|
||||
success: boolean
|
||||
|
||||
/**
|
||||
* Metadata about the artifact that was found
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue