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/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; 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']; }