Skip to content

Commit

Permalink
Merge pull request #2 from sankichi92/fix-bug
Browse files Browse the repository at this point in the history
Fix bug that `git diff` fails on pull_request events
  • Loading branch information
sankichi92 authored Jul 2, 2024
2 parents 20199f7 + 0313729 commit bf3cad9
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 bf3cad9

Please sign in to comment.