From ddd91ca1dd1291e8c9408322fa5ead2eb1814d51 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Thu, 19 Sep 2024 05:12:00 +0000 Subject: [PATCH] ci: get-changed-files-with-git-diff: stable branch names --- .circleci/scripts/git-diff-develop.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.circleci/scripts/git-diff-develop.ts b/.circleci/scripts/git-diff-develop.ts index 5d057ca242ff..82fdeccb64d7 100644 --- a/.circleci/scripts/git-diff-develop.ts +++ b/.circleci/scripts/git-diff-develop.ts @@ -6,6 +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 +30,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}:${SOURCE_BRANCH}`); return true; } catch (error: unknown) { console.error(`Failed to fetch with depth ${depth}:`, error); @@ -58,6 +59,7 @@ async function fetchUntilMergeBaseFound() { error instanceof Error && // @ts-expect-error Object.hasOwnProperty.call(error, 'code') && + // @ts-expect-error error.code === 1 ) { console.error(`Error 'no merge base' encountered with depth ${depth}. Incrementing depth...`); @@ -66,7 +68,7 @@ async function fetchUntilMergeBaseFound() { } } } - await exec(`git fetch --unshallow origin develop`); + await exec(`git fetch --unshallow origin ${MAIN_BRANCH}`); } /** @@ -78,7 +80,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.'); }