From 883707a85881793630235d6f1bbdd0c5733f2650 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 27 Nov 2023 01:26:27 -0700 Subject: [PATCH] Fixed test --- src/commitSha.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/commitSha.ts b/src/commitSha.ts index 848e75de952..62ef68b7f28 100644 --- a/src/commitSha.ts +++ b/src/commitSha.ts @@ -184,6 +184,28 @@ export const getSHAForNonPullRequestEvent = async ( currentBranch = currentBranchName } + if (inputs.baseSha && inputs.sha && currentBranch && targetBranch) { + if (previousSha === currentSha) { + core.error( + `Similar commit hashes detected: previous sha: ${previousSha} is equivalent to the current sha: ${currentSha}.` + ) + core.error( + `Please verify that both commits are valid, and increase the fetch_depth to a number higher than ${inputs.fetchDepth}.` + ) + throw new Error('Similar commit hashes detected.') + } + + core.debug(`Previous SHA: ${previousSha}`) + + return { + previousSha, + currentSha, + currentBranch, + targetBranch, + diff + } + } + if (!previousSha || previousSha === currentSha) { core.debug('Getting previous SHA...') if (inputs.since) { @@ -383,6 +405,28 @@ export const getSHAForPullRequestEvent = async ( }) let diff = '...' + if (inputs.baseSha && inputs.sha && currentBranch && targetBranch) { + if (previousSha === currentSha) { + core.error( + `Similar commit hashes detected: previous sha: ${previousSha} is equivalent to the current sha: ${currentSha}.` + ) + core.error( + `Please verify that both commits are valid, and increase the fetch_depth to a number higher than ${inputs.fetchDepth}.` + ) + throw new Error('Similar commit hashes detected.') + } + + core.debug(`Previous SHA: ${previousSha}`) + + return { + previousSha, + currentSha, + currentBranch, + targetBranch, + diff + } + } + if ( !github.context.payload.pull_request?.base?.ref || github.context.payload.head?.repo?.fork === 'true'