Skip to content

Commit 45f16f1

Browse files
authored
Merge pull request #133 from frouioui/main
Compare base and ref when token is empty
2 parents 1441771 + 5da0e4c commit 45f16f1

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

dist/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ function getConfigFileContent(configPath) {
555555
return fs.readFileSync(configPath, { encoding: 'utf8' });
556556
}
557557
async function getChangedFiles(token, base, ref, initialFetchDepth) {
558+
var _a, _b;
558559
// if base is 'HEAD' only local uncommitted changes will be detected
559560
// This is the simplest case as we don't need to fetch more commits or evaluate current/before refs
560561
if (base === git.HEAD) {
@@ -581,8 +582,11 @@ async function getChangedFiles(token, base, ref, initialFetchDepth) {
581582
// At the same time we don't want to fetch any code from forked repository
582583
throw new Error(`'token' input parameter is required if action is triggered by 'pull_request_target' event`);
583584
}
584-
core.info('Github token is not available - changes will be detected from PRs merge commit');
585-
return await git.getChangesInLastCommit();
585+
core.info('Github token is not available - changes will be detected using git diff');
586+
const baseSha = (_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.base.sha;
587+
const defaultBranch = (_b = github.context.payload.repository) === null || _b === void 0 ? void 0 : _b.default_branch;
588+
const currentRef = await git.getCurrentRef();
589+
return await git.getChanges(base || baseSha || defaultBranch, currentRef);
586590
}
587591
else {
588592
return getChangedFilesFromGit(base, ref, initialFetchDepth);

src/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ async function getChangedFiles(token: string, base: string, ref: string, initial
8686
// At the same time we don't want to fetch any code from forked repository
8787
throw new Error(`'token' input parameter is required if action is triggered by 'pull_request_target' event`)
8888
}
89-
core.info('Github token is not available - changes will be detected from PRs merge commit')
90-
return await git.getChangesInLastCommit()
89+
core.info('Github token is not available - changes will be detected using git diff')
90+
const baseSha = github.context.payload.pull_request?.base.sha
91+
const defaultBranch = github.context.payload.repository?.default_branch
92+
const currentRef = await git.getCurrentRef()
93+
return await git.getChanges(base || baseSha || defaultBranch, currentRef)
9194
} else {
9295
return getChangedFilesFromGit(base, ref, initialFetchDepth)
9396
}

0 commit comments

Comments
 (0)