From 84b7e683e3860fd3e4a68a7b978093094d588489 Mon Sep 17 00:00:00 2001 From: Prajjwal Date: Thu, 20 Jun 2024 12:15:48 +0530 Subject: [PATCH] changes restore refs to be set --- packages/warp-cache/package.json | 2 +- .../warp-cache/src/internal/cacheHttpClient.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/warp-cache/package.json b/packages/warp-cache/package.json index 7b27bae7..5861ba8c 100644 --- a/packages/warp-cache/package.json +++ b/packages/warp-cache/package.json @@ -1,6 +1,6 @@ { "name": "github-actions.warp-cache", - "version": "1.2.1", + "version": "1.2.2", "preview": true, "description": "Github action to use WarpBuild's in-house cache offering", "keywords": [ diff --git a/packages/warp-cache/src/internal/cacheHttpClient.ts b/packages/warp-cache/src/internal/cacheHttpClient.ts index 482e7c0e..0de77942 100644 --- a/packages/warp-cache/src/internal/cacheHttpClient.ts +++ b/packages/warp-cache/src/internal/cacheHttpClient.ts @@ -149,23 +149,23 @@ export async function getCacheEntry( options?.enableCrossArchArchive ) - const restoreBranches: Array = [] - const restoreRepos: Array = [] + const restoreBranches: Set = new Set() + const restoreRepos: Set = new Set() switch (github.context.eventName) { case 'pull_request': { const pullPayload = github.context.payload as PullRequestEvent // Adds PR head branch and base branch to restoreBranches - restoreBranches.push( + restoreBranches.add( `refs/heads/${pullPayload?.pull_request?.head?.ref}` ) - restoreBranches.push( + restoreBranches.add( `refs/heads/${pullPayload?.pull_request?.base?.ref}` ) // Adds default branch to restoreBranches - restoreBranches.push( + restoreBranches.add( `refs/heads/${pullPayload?.repository?.default_branch}` ) @@ -174,7 +174,7 @@ export async function getCacheEntry( pullPayload?.pull_request?.head?.repo?.name !== pullPayload?.repository?.name ) { - restoreRepos.push(pullPayload?.pull_request?.head?.repo?.name) + restoreRepos.add(pullPayload?.pull_request?.head?.repo?.name) } } break @@ -184,7 +184,7 @@ export async function getCacheEntry( const pushPayload = github.context.payload as PushEvent // Default branch is not in the complete format // Ref: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push - restoreBranches.push( + restoreBranches.add( `refs/heads/${pushPayload?.repository?.default_branch}` ) } @@ -200,8 +200,8 @@ export async function getCacheEntry( vcs_repository: getVCSRepository(), vcs_ref: getVCSRef(), annotations: getAnnotations(), - restore_branches: restoreBranches, - restore_repos: restoreRepos + restore_branches: Array.from(restoreBranches), + restore_repos: Array.from(restoreRepos) } const response = await retryTypedResponse('getCacheEntry', async () =>