From b86de6e08d6129b1cb77aac0ab85ec0f27aa18a7 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Thu, 25 Sep 2025 15:57:14 +0100 Subject: [PATCH 1/2] chore: re-run build --- main.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main.js b/main.js index 1ea28c8..3e3fbcf 100644 --- a/main.js +++ b/main.js @@ -1,9 +1,7 @@ - - import { fileURLToPath } from 'node:url'; +import { fileURLToPath } from 'node:url'; import { createRequire as topLevelCreateRequire } from 'node:module'; import { dirname as topLevelDirname } from 'path'; const require = topLevelCreateRequire(import.meta.url); - var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; From d825c4a9e41ca2ee1c474a80dea6d1b2d2076af8 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Thu, 25 Sep 2025 16:07:46 +0100 Subject: [PATCH 2/2] chore: fix up some stuff --- action.yml | 2 +- src/git.ts | 2 +- test/git_test.ts | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 4f0655b..53f0a0d 100644 --- a/action.yml +++ b/action.yml @@ -10,7 +10,7 @@ inputs: base-ref: description: 'Base ref to compare against (defaults to main or PR target)' required: true - default: 'main' + default: 'origin/main' github-token: description: 'The GitHub token for authentication.' required: true diff --git a/src/git.ts b/src/git.ts index 48a934e..4d4c63f 100644 --- a/src/git.ts +++ b/src/git.ts @@ -23,7 +23,7 @@ export function getFileFromRef( export function getBaseRef(): string { const inputBaseRef = core.getInput('base-ref'); if (inputBaseRef) { - return inputBaseRef; + return inputBaseRef.includes('/') ? inputBaseRef : `origin/${inputBaseRef}`; } const githubBaseRef = github.context.payload.pull_request?.base.ref; diff --git a/test/git_test.ts b/test/git_test.ts index d1f6290..415c064 100644 --- a/test/git_test.ts +++ b/test/git_test.ts @@ -1,19 +1,29 @@ import {describe, it, expect, beforeEach, vi} from 'vitest'; import * as git from '../src/git.js'; import * as github from '@actions/github'; -import process from 'process'; +import * as process from 'process'; import {fileURLToPath} from 'node:url'; -import path from 'node:path'; +import * as path from 'node:path'; const currentDir = path.dirname(fileURLToPath(import.meta.url)); const rootDir = path.join(currentDir, '..'); describe('getBaseRef', () => { it('should return input base ref if provided', () => { + try { + process.env['INPUT_BASE-REF'] = 'origin/feature-branch'; + const baseRef = git.getBaseRef(); + expect(baseRef).toBe('origin/feature-branch'); + } finally { + delete process.env['INPUT_BASE-REF']; + } + }); + + it('should prepend origin if not set', () => { try { process.env['INPUT_BASE-REF'] = 'feature-branch'; const baseRef = git.getBaseRef(); - expect(baseRef).toBe('feature-branch'); + expect(baseRef).toBe('origin/feature-branch'); } finally { delete process.env['INPUT_BASE-REF']; }