mirror of
https://github.com/actions/toolkit.git
synced 2026-08-07 00:00:18 +02:00
@@ -6,12 +6,12 @@ describe('createStorageRecord', () => {
|
|||||||
const attestation = {foo: 'bar '}
|
const attestation = {foo: 'bar '}
|
||||||
const token = 'token'
|
const token = 'token'
|
||||||
const headers = {'X-GitHub-Foo': 'true'}
|
const headers = {'X-GitHub-Foo': 'true'}
|
||||||
const artifactParams = {
|
const artifactOptions = {
|
||||||
name: "my-lib",
|
name: "my-lib",
|
||||||
version: "1.0.0",
|
version: "1.0.0",
|
||||||
digest: "sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
digest: "sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
||||||
}
|
}
|
||||||
const registryParams = {
|
const registryOptions = {
|
||||||
registryUrl: 'https://my-registry.org',
|
registryUrl: 'https://my-registry.org',
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +50,8 @@ describe('createStorageRecord', () => {
|
|||||||
it('persists the storage record', async () => {
|
it('persists the storage record', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
createStorageRecord({
|
createStorageRecord({
|
||||||
artifactOptions: artifactParams,
|
artifactOptions: artifactOptions,
|
||||||
packageRegistryOptions: registryParams,
|
packageRegistryOptions: registryOptions,
|
||||||
token,
|
token,
|
||||||
writeOptions: {headers},
|
writeOptions: {headers},
|
||||||
})
|
})
|
||||||
@@ -80,8 +80,8 @@ describe('createStorageRecord', () => {
|
|||||||
it('throws an error', async () => {
|
it('throws an error', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
createStorageRecord({
|
createStorageRecord({
|
||||||
artifactOptions: artifactParams,
|
artifactOptions: artifactOptions,
|
||||||
packageRegistryOptions: registryParams,
|
packageRegistryOptions: registryOptions,
|
||||||
token,
|
token,
|
||||||
writeOptions: {retry: 0},
|
writeOptions: {retry: 0},
|
||||||
})
|
})
|
||||||
@@ -98,7 +98,7 @@ describe('createStorageRecord', () => {
|
|||||||
path: '/repos/foo/bar/attestations',
|
path: '/repos/foo/bar/attestations',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {authorization: `token ${token}`},
|
headers: {authorization: `token ${token}`},
|
||||||
body: JSON.stringify({...artifactParams, registry_url: registryParams.registryUrl})
|
body: JSON.stringify({...artifactOptions, registry_url: registryOptions.registryUrl})
|
||||||
})
|
})
|
||||||
.reply(500, 'oops')
|
.reply(500, 'oops')
|
||||||
.times(1)
|
.times(1)
|
||||||
@@ -115,9 +115,11 @@ describe('createStorageRecord', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('persists the attestation', async () => {
|
it('persists the attestation', async () => {
|
||||||
|
const { registryUrl, ...rest } = registryOptions
|
||||||
await expect(createStorageRecord({
|
await expect(createStorageRecord({
|
||||||
artifactOptions: artifactParams,
|
...artifactOptions,
|
||||||
packageRegistryOptions: registryParams,
|
...rest,
|
||||||
|
registry_url: registryUrl,
|
||||||
token,
|
token,
|
||||||
writeOptions: {},
|
writeOptions: {},
|
||||||
})).resolves.toEqual(['123', '456'])
|
})).resolves.toEqual(['123', '456'])
|
||||||
|
|||||||
@@ -44,10 +44,7 @@ export type StorageRecordOptions = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a storage record on behalf of an artifact that has been attested
|
* Writes a storage record on behalf of an artifact that has been attested
|
||||||
* @param artifactParams - parameters for the artifact.
|
* @param StorageRecordOptions - parameters for the storage record API request.
|
||||||
* @param packageRegistryParams - parameters for the package registry.
|
|
||||||
* @param token - The GitHub token for authentication.
|
|
||||||
* @param options - Optional parameters for the write operation.
|
|
||||||
* @returns The ID of the storage record.
|
* @returns The ID of the storage record.
|
||||||
* @throws Error if the storage record fails to persist.
|
* @throws Error if the storage record fails to persist.
|
||||||
*/
|
*/
|
||||||
@@ -73,14 +70,3 @@ export async function createStorageRecord(options: StorageRecordOptions): Promis
|
|||||||
throw new Error(`Failed to persist storage record: ${message}`)
|
throw new Error(`Failed to persist storage record: ${message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildRequestParams = (artifactParams: ArtifactParams, registryParams: PackageRegistryParams) => {
|
|
||||||
const { registryUrl, artifactUrl, ...rest } = registryParams
|
|
||||||
return {
|
|
||||||
...artifactParams,
|
|
||||||
...rest,
|
|
||||||
// rename parameters to match API expectations
|
|
||||||
artifact_url: artifactUrl,
|
|
||||||
registry_url: registryUrl,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export {createStorageRecord} from '.artifactMetadata'
|
export {createStorageRecord} from './artifactMetadata'
|
||||||
export {AttestOptions, attest} from './attest'
|
export {AttestOptions, attest} from './attest'
|
||||||
export {
|
export {
|
||||||
AttestProvenanceOptions,
|
AttestProvenanceOptions,
|
||||||
|
|||||||
Reference in New Issue
Block a user