From e051da3065eaaf109851e806ce898ec99de97f63 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Thu, 19 Sep 2024 05:04:49 +0000 Subject: [PATCH] ci: get-changed-files-with-git-diff: stable branch names --- .circleci/scripts/git-diff-develop.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.circleci/scripts/git-diff-develop.ts b/.circleci/scripts/git-diff-develop.ts index 6b4a67f81e79..7e19da1bbe6a 100644 --- a/.circleci/scripts/git-diff-develop.ts +++ b/.circleci/scripts/git-diff-develop.ts @@ -6,7 +6,7 @@ import { promisify } from 'util'; const exec = promisify(execCallback); const MAIN_BRANCH = 'develop'; - +const SOURCE_BRANCH = `refs/pull/${process.env.CIRCLE_PR_NUMBER}/head`; /** * Get the target branch for the given pull request. * @@ -29,8 +29,8 @@ async function getBaseRef(): Promise { */ async function fetchWithDepth(depth: number): Promise { try { - await exec(`git fetch --depth ${depth} origin develop`); - await exec(`git fetch --depth ${depth} origin ${process.env.CIRCLE_BRANCH}`); + await exec(`git fetch --depth ${depth} origin ${MAIN_BRANCH}`); + await exec(`git fetch --depth ${depth} origin ${SOURCE_BRANCH}`); return true; } catch (error: unknown) { console.error(`Failed to fetch with depth ${depth}:`, error); @@ -57,6 +57,7 @@ async function fetchUntilMergeBaseFound() { if ( error instanceof Error && Object.hasOwnProperty.call(error, 'code') && + // @ts-expect-error error.code === 1 ) { console.error(`Error 'no merge base' encountered with depth ${depth}. Incrementing depth...`); @@ -65,7 +66,7 @@ async function fetchUntilMergeBaseFound() { } } } - await exec(`git fetch --unshallow origin develop`); + await exec(`git fetch --unshallow origin ${MAIN_BRANCH}`); } /** @@ -77,7 +78,7 @@ async function fetchUntilMergeBaseFound() { */ async function gitDiff(): Promise { await fetchUntilMergeBaseFound(); - const { stdout: diffResult } = await exec(`git diff --name-only origin/HEAD...${process.env.CIRCLE_BRANCH}`); + const { stdout: diffResult } = await exec(`git diff --name-only origin/HEAD...${SOURCE_BRANCH}`); if (!diffResult) { throw new Error('Unable to get diff after full checkout.'); }