Skip to content

Commit

Permalink
Fix bug that git diff fails on pull_request events
Browse files Browse the repository at this point in the history
  • Loading branch information
sankichi92 committed Jul 2, 2024
1 parent 20199f7 commit 0313729
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/github.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Context } from "@actions/github/lib/context";
import type { PullRequestEvent, PushEvent } from "@octokit/webhooks-types";

export function getBaseRef(context: Context) {
export function getBaseSHA(context: Context) {
switch (context.eventName) {
case "pull_request": {
const payload = context.payload as PullRequestEvent;
return payload.pull_request.base.ref;
return payload.pull_request.base.sha;
}
case "push": {
const payload = context.payload as PushEvent;
Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as core from "@actions/core";
import * as github from "@actions/github";

import { gitDiffExists, gitFetch, gitLsFiles } from "./git";
import { getBaseRef } from "./github";
import { getBaseSHA } from "./github";

export async function run() {
try {
Expand All @@ -24,13 +24,13 @@ export async function run() {
core.endGroup();

core.startGroup("Fetching the base commit");
const baseRef = getBaseRef(github.context);
await gitFetch(baseRef);
const baseSHA = getBaseSHA(github.context);
await gitFetch(baseSHA);
core.endGroup();

core.startGroup("Comparing git diff");
const isChanged = await Promise.all(
candidateDirs.map((dir) => gitDiffExists(baseRef, dir)),
candidateDirs.map((dir) => gitDiffExists(baseSHA, dir)),
);
const changedDirs = candidateDirs.filter((_, i) => isChanged[i]);
core.endGroup();
Expand Down

0 comments on commit 0313729

Please sign in to comment.