Skip to content

Commit

Permalink
Merge pull request #113 from sankichi92/handle-no-base-commit
Browse files Browse the repository at this point in the history
Handle cases with no base commit
  • Loading branch information
sankichi92 authored Jan 18, 2025
2 parents e7fcdb5 + 892ec81 commit 8d98529
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ name: CI

on:
pull_request:
branches: ["main"]
push:
branches: ["main"]

jobs:
lint:
Expand Down
10 changes: 10 additions & 0 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.

6 changes: 6 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export function getBaseSHA(context: Context) {
}
case "push": {
const payload = context.payload as PushEvent;

// https://github.com/sankichi92/list-changed-directories/issues/107
if (payload.created) {
return null;
}

return payload.before;
}
default: {
Expand Down
8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export async function run() {

core.startGroup("Fetching the base commit");
const baseSHA = getBaseSHA(github.context);
if (baseSHA === null) {
core.endGroup();
core.info(
`No base commit found since "${github.context.ref}" was created by this push.`,
);
core.setOutput("changed-directories", candidateDirs);
return;
}
await gitFetch(baseSHA);
core.endGroup();

Expand Down

0 comments on commit 8d98529

Please sign in to comment.