From 9d9ca21d4f76f6084c9d69ad6d7507694cb56556 Mon Sep 17 00:00:00 2001 From: hulk510 Date: Wed, 17 Jan 2024 22:31:18 +0900 Subject: [PATCH] fix: lint errors --- __tests__/main.test.ts | 19 ++++++++------- src/main.ts | 52 +++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 39 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index f282a90..6c8e4c3 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -13,24 +13,24 @@ import * as main from '../src/main' const runMock = jest.spyOn(main, 'run') // Other utilities -const timeRegex = /^\d{2}:\d{2}:\d{2}/ +// const timeRegex = /^\d{2}:\d{2}:\d{2}/ // Mock the GitHub Actions core library -let debugMock: jest.SpyInstance +// let debugMock: jest.SpyInstance let errorMock: jest.SpyInstance let getInputMock: jest.SpyInstance -let setFailedMock: jest.SpyInstance -let setOutputMock: jest.SpyInstance +// let setFailedMock: jest.SpyInstance +// let setOutputMock: jest.SpyInstance describe('action', () => { beforeEach(() => { jest.clearAllMocks() - debugMock = jest.spyOn(core, 'debug').mockImplementation() + // debugMock = jest.spyOn(core, 'debug').mockImplementation() errorMock = jest.spyOn(core, 'error').mockImplementation() getInputMock = jest.spyOn(core, 'getInput').mockImplementation() - setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() - setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() + // setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() + // setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() }) it('sets the time output', async () => { @@ -51,7 +51,6 @@ describe('action', () => { expect(errorMock).not.toHaveBeenCalled() }) - it('sets a failed status', async () => { - // Set the action's inputs as return values from core.getInput() - }) + it.todo('sets a failed status') + // Set the action's inputs as return values from core.getInput() }) diff --git a/src/main.ts b/src/main.ts index 651f906..e809beb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,50 +19,44 @@ export async function run(): Promise { if (headRef) { // Get the list of cache IDs // https://github.com/octokit/plugin-paginate-rest.js#octokitpaginate - const cacheIdList = await octokit.paginate( + const iterator = octokit.paginate.iterator( octokit.rest.actions.getActionsCacheList, { ...repo, - ref - }, - response => response.data.flatMap(cache => cache.id ?? []) + ref: headRef + } ) - if (cacheIdList.length === 0) { - core.info('No cache found.') - return - } - // Delete the caches - cacheIdList.forEach(async id => { - await octokit.rest.actions.deleteActionsCacheById({ - ...repo, - cache_id: id - }) - }) + for await (const { data: cacheList } of iterator) { + for (const { id: cacheId } of cacheList) { + if (!cacheId) continue + await octokit.rest.actions.deleteActionsCacheById({ + ...repo, + cache_id: cacheId + }) + } + } } // Get the list of cache IDs // https://github.com/octokit/plugin-paginate-rest.js#octokitpaginate - const cacheIdList = await octokit.paginate( + const iterator = octokit.paginate.iterator( octokit.rest.actions.getActionsCacheList, { ...repo, ref - }, - response => response.data.flatMap(cache => cache.id ?? []) + } ) - if (cacheIdList.length === 0) { - core.info('No cache found.') - return - } - // Delete the caches - cacheIdList.forEach(async id => { - await octokit.rest.actions.deleteActionsCacheById({ - ...repo, - cache_id: id - }) - }) + for await (const { data: cacheList } of iterator) { + for (const { id: cacheId } of cacheList) { + if (!cacheId) continue + await octokit.rest.actions.deleteActionsCacheById({ + ...repo, + cache_id: cacheId + }) + } + } } catch (error) { // Fail the workflow run if an error occurs if (error instanceof Error) core.setFailed(error.message)