feat: add support for forcing the use of GitHub’s REST API (#1849)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack
2024-01-13 01:48:42 -07:00
committed by GitHub
parent a57f4dcc81
commit 0ca1c07b47
7 changed files with 79 additions and 13 deletions

26
dist/index.js generated vendored
View File

@@ -1553,6 +1553,9 @@ const getInputs = () => {
const negationPatternsFirst = core.getBooleanInput('negation_patterns_first', {
required: false
});
const useRestApi = core.getBooleanInput('use_rest_api', {
required: false
});
const inputs = {
files,
filesSeparator,
@@ -1605,7 +1608,8 @@ const getInputs = () => {
outputRenamedFilesAsDeletedAndAdded,
token,
apiUrl,
negationPatternsFirst
negationPatternsFirst,
useRestApi
};
if (fetchDepth) {
inputs.fetchDepth = Math.max(parseInt(fetchDepth, 10), 2);
@@ -1793,7 +1797,7 @@ const getChangedFilesFromRESTAPI = ({ inputs, filePatterns, yamlFilePatterns })
});
});
function run() {
var _a;
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
core.startGroup('changed-files');
const env = yield (0, env_1.getEnv)();
@@ -1815,21 +1819,31 @@ function run() {
workingDirectory
});
core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`);
if (inputs.useRestApi && !((_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number)) {
throw new Error("Only pull_request* events are supported when using GitHub's REST API.");
}
if (inputs.token &&
((_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number) &&
!hasGitDirectory) {
((_b = github.context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.number) &&
(!hasGitDirectory || inputs.useRestApi)) {
core.info("Using GitHub's REST API to get changed files");
const unsupportedInputs = [
'sha',
'baseSha',
'since',
'until',
'path',
'quotePath',
'diffRelative',
'sinceLastRemoteCommit',
'recoverDeletedFiles',
'recoverDeletedFilesToDestination',
'recoverFiles',
'recoverFilesSeparator',
'recoverFilesIgnore',
'recoverFilesIgnoreSeparator',
'includeAllOldNewRenamedFiles',
'oldNewSeparator',
'oldNewFilesSeparator',
'skipInitialFetch',
'fetchSubmoduleHistory',
'dirNamesDeletedFilesIncludeOnlyDeletedDirs'
@@ -1848,8 +1862,7 @@ function run() {
else {
if (!hasGitDirectory) {
core.info(`Running on a ${github.context.eventName} event...`);
core.setFailed("Can't find local .git directory. Please run actions/checkout before this action. If you intend to use Github's REST API note that only pull_request* events are supported.");
return;
throw new Error("Can't find local .git directory. Please run actions/checkout before this action (Make sure the path specified in the 'path' input is correct). If you intend to use Github's REST API note that only pull_request* events are supported.");
}
core.info('Using local .git directory');
yield getChangedFilesFromLocalGitHistory({
@@ -1868,6 +1881,7 @@ if (!process.env.TESTING) {
// eslint-disable-next-line github/no-then
run().catch(e => {
core.setFailed(e.message || e);
process.exit(1);
});
}

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long