Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions main.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions test/git_test.ts
Original file line number Diff line number Diff line change
@@ -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'];
}
Expand Down