From db1106bcff3792946ea0e7abc75e67506cd8bee7 Mon Sep 17 00:00:00 2001 From: Flavio Wuensche Date: Mon, 22 Jan 2024 18:13:38 +0100 Subject: [PATCH] fix: checkout merge base for cherry diff (#37) * chore: cosmetic * chore: remove api key * chore: list branches * chore: echo head ref * chore: show ref * chore: rev parse head * chore: head ref * chore: origin/main * chore: origin/main * chore: fetch main * chore: fetch main * chore: checkout main * chore: checkout main via cli * chore: merge base with origin * feat: checkout merge base for cherry diff --- .github/workflows/cherry_diff.yml | 2 +- src/git.js | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cherry_diff.yml b/.github/workflows/cherry_diff.yml index db9c1391..08e10127 100644 --- a/.github/workflows/cherry_diff.yml +++ b/.github/workflows/cherry_diff.yml @@ -17,4 +17,4 @@ jobs: run: npm install - name: Raise if new JavaScript code is added - run: ./bin/cherry.js diff --metric='[loc] JavaScript' --api-key=${{ secrets.CHERRY_API_KEY }} --error-if-increase --quiet + run: ./bin/cherry.js diff --metric='[loc] JavaScript' --error-if-increase --quiet diff --git a/src/git.js b/src/git.js index bb3ed0af..c9dd2ab5 100644 --- a/src/git.js +++ b/src/git.js @@ -41,10 +41,8 @@ export const getDefaultBranchName = async () => { return defaultBranch.replace('origin/', '').trim() } -export const getMergeBase = async (currentBranchName, defaultBranchName) => { - const mergeBase = (await git(`merge-base ${currentBranchName} ${defaultBranchName}`)).toString() - return mergeBase.trim() -} +export const getMergeBase = async (currentBranchName, defaultBranchName) => + (await git(`merge-base ${currentBranchName} origin/${defaultBranchName}`)).toString().trim() export const authorName = async (sha) => (await git(`show ${sha} --format=%an --no-patch`))[0]