From 10d3b034e071972608dbd4dd0f25c5edcde154f7 Mon Sep 17 00:00:00 2001 From: Meredith Lancaster Date: Mon, 8 Dec 2025 16:22:59 -0800 Subject: [PATCH] fix linter issues Signed-off-by: Meredith Lancaster --- .../attest/__tests__/artifactMetadata.test.ts | 52 ++++++++++--------- packages/attest/src/artifactMetadata.ts | 23 ++++---- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/packages/attest/__tests__/artifactMetadata.test.ts b/packages/attest/__tests__/artifactMetadata.test.ts index 3416eed1..051ea314 100644 --- a/packages/attest/__tests__/artifactMetadata.test.ts +++ b/packages/attest/__tests__/artifactMetadata.test.ts @@ -3,21 +3,20 @@ import {createStorageRecord} from '../src/artifactMetadata' describe('createStorageRecord', () => { const originalEnv = process.env - const attestation = {foo: 'bar '} const token = 'token' const headers = {'X-GitHub-Foo': 'true'} const options = { artifactOptions: { - name: "my-lib", - version: "1.0.0", - digest: "sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", + name: 'my-lib', + version: '1.0.0', + digest: `sha256:${'a'.repeat(64)}` }, packageRegistryOptions: { - registryUrl: 'https://my-registry.org', + registryUrl: 'https://my-registry.org' }, token, - writeOptions: {headers}, + writeOptions: {headers} } const mockAgent = new MockAgent() @@ -43,19 +42,20 @@ describe('createStorageRecord', () => { method: 'POST', headers: {authorization: `token ${token}`, ...headers}, body: JSON.stringify({ - name: "my-lib", - version: "1.0.0", - digest: "sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", - registry_url: "https://my-registry.org" + name: 'my-lib', + version: '1.0.0', + digest: `sha256:${'a'.repeat(64)}`, + registry_url: 'https://my-registry.org' }) }) .reply(201, {storage_records: [{id: '123'}, {id: '456'}]}) }) it('persists the storage record', async () => { - await expect( - createStorageRecord(options) - ).resolves.toEqual(['123', '456']) + await expect(createStorageRecord(options)).resolves.toEqual([ + '123', + '456' + ]) }) }) @@ -68,10 +68,10 @@ describe('createStorageRecord', () => { method: 'POST', headers: {authorization: `token ${token}`}, body: JSON.stringify({ - name: "my-lib", - version: "1.0.0", - digest: "sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", - registry_url: "https://my-registry.org" + name: 'my-lib', + version: '1.0.0', + digest: `sha256:${'a'.repeat(64)}`, + registry_url: 'https://my-registry.org' }) }) .reply(500, 'oops') @@ -81,7 +81,7 @@ describe('createStorageRecord', () => { await expect( createStorageRecord({ ...options, - writeOptions: {retry: 0}, + writeOptions: {retry: 0} }) ).rejects.toThrow(/oops/) }) @@ -98,7 +98,7 @@ describe('createStorageRecord', () => { headers: {authorization: `token ${token}`}, body: JSON.stringify({ ...options.artifactOptions, - registry_url: options.packageRegistryOptions.registryUrl, + registry_url: options.packageRegistryOptions.registryUrl }) }) .reply(500, 'oops') @@ -111,18 +111,20 @@ describe('createStorageRecord', () => { headers: {authorization: `token ${token}`}, body: JSON.stringify({ ...options.artifactOptions, - registry_url: options.packageRegistryOptions.registryUrl, + registry_url: options.packageRegistryOptions.registryUrl }) }) .reply(201, {storage_records: [{id: '123'}, {id: '456'}]}) .times(1) }) - it('persists the attestation', async () => { - await expect(createStorageRecord({ - ...options, - writeOptions: {}, - })).resolves.toEqual(['123', '456']) + it('persists the storage record', async () => { + await expect( + createStorageRecord({ + ...options, + writeOptions: {} + }) + ).resolves.toEqual(['123', '456']) }) }) }) diff --git a/packages/attest/src/artifactMetadata.ts b/packages/attest/src/artifactMetadata.ts index 6b94dc20..f24b6806 100644 --- a/packages/attest/src/artifactMetadata.ts +++ b/packages/attest/src/artifactMetadata.ts @@ -2,7 +2,8 @@ import * as github from '@actions/github' import {retry} from '@octokit/plugin-retry' import {RequestHeaders} from '@octokit/types' -const CREATE_STORAGE_RECORD_REQUEST = 'POST /orgs/{owner}/artifacts/metadata/storage-record' +const CREATE_STORAGE_RECORD_REQUEST = + 'POST /orgs/{owner}/artifacts/metadata/storage-record' const DEFAULT_RETRY_COUNT = 5 /** @@ -19,7 +20,7 @@ export type StorageRecordOptions = { version?: string // The status of the artifact status?: string - }, + } // Includes details about the package registry the artifact was published to packageRegistryOptions: { // The URL of the package registry @@ -30,14 +31,14 @@ export type StorageRecordOptions = { repo?: string // The path of the artifact in the package registry repository. path?: string - }, + } // GitHub token for writing attestations. token: string // Optional parameters for the write operation. writeOptions: { // The number of times to retry the request. retry?: number - // HTTP headers to include in request to Artifact Metadata API. + // HTTP headers to include in request to Artifact Metadata API. headers?: RequestHeaders } } @@ -48,7 +49,9 @@ export type StorageRecordOptions = { * @returns The ID of the storage record. * @throws Error if the storage record fails to persist. */ -export async function createStorageRecord(options: StorageRecordOptions): Promise> { +export async function createStorageRecord( + options: StorageRecordOptions +): Promise { const retries = options.writeOptions.retry ?? DEFAULT_RETRY_COUNT const octokit = github.getOctokit(options.token, {retry: {retries}}, retry) @@ -56,7 +59,7 @@ export async function createStorageRecord(options: StorageRecordOptions): Promis const response = await octokit.request(CREATE_STORAGE_RECORD_REQUEST, { owner: github.context.repo.owner, headers: options.writeOptions.headers, - ...buildRequestParams(options), + ...buildRequestParams(options) }) const data = @@ -64,19 +67,19 @@ export async function createStorageRecord(options: StorageRecordOptions): Promis ? JSON.parse(response.data) : response.data - return data?.storage_records.map((r: { id: any }) => r.id) + return data?.storage_records.map((r: {id: number}) => String(r.id)) } catch (err) { const message = err instanceof Error ? err.message : err throw new Error(`Failed to persist storage record: ${message}`) } } -const buildRequestParams = (options: StorageRecordOptions) => { - const { registryUrl, artifactUrl, ...rest } = options.packageRegistryOptions +function buildRequestParams(options: StorageRecordOptions): Object { + const {registryUrl, artifactUrl, ...rest} = options.packageRegistryOptions return { ...options.artifactOptions, registry_url: registryUrl, artifact_url: artifactUrl, - ...rest, + ...rest } }