Fixed error with output

This commit is contained in:
Tonye Jack 2023-05-22 22:32:30 -06:00
parent d499479423
commit 0557d055c4
7 changed files with 40 additions and 9 deletions

View File

@ -92,6 +92,10 @@ inputs:
description: "Output list of changed files in a JSON formatted string which can be used for matrix jobs."
required: false
default: "false"
escape_json:
description: "Escape JSON output."
required: false
default: "true"
fetch_depth:
description: "Depth of additional branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history."
required: false

18
dist/index.js generated vendored
View File

@ -83,7 +83,7 @@ const getRenamedFiles = ({ inputs, workingDirectory, hasSubmodule, shaResult })
}));
}
if (inputs.json) {
return (0, utils_1.jsonOutput)({ value: renamedFiles });
return (0, utils_1.jsonOutput)({ value: renamedFiles, escape: inputs.escape_json });
}
return renamedFiles.join(inputs.oldNewFilesSeparator);
});
@ -131,7 +131,7 @@ const getDiffFiles = ({ inputs, workingDirectory, hasSubmodule, shaResult, diffF
}));
}
if (inputs.json) {
return (0, utils_1.jsonOutput)({ value: files });
return (0, utils_1.jsonOutput)({ value: files, escape: inputs.escape_json });
}
return files.join(inputs.separator);
});
@ -633,6 +633,7 @@ const getInputs = () => {
required: false
});
const json = core.getBooleanInput('json', { required: false });
const escape_json = core.getBooleanInput('escape_json', { required: false });
const fetchDepth = core.getInput('fetch_depth', { required: false });
const sinceLastRemoteCommit = core.getBooleanInput('since_last_remote_commit', { required: false });
const writeOutputFiles = core.getBooleanInput('write_output_files', {
@ -665,6 +666,7 @@ const getInputs = () => {
dirNames,
dirNamesExcludeRoot,
json,
escape_json,
sinceLastRemoteCommit,
writeOutputFiles,
outputDir,
@ -736,7 +738,9 @@ function run() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const env = (0, env_1.getEnv)();
core.debug(`Env: ${JSON.stringify(env, null, 2)}`);
const inputs = (0, inputs_1.getInputs)();
core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`);
yield (0, utils_1.verifyMinimumGitVersion)();
let quotePathValue = 'on';
if (!inputs.quotePath) {
@ -1502,8 +1506,14 @@ const getDirnameMaxDepth = ({ pathStr, dirNamesMaxDepth, excludeRoot }) => {
return output;
};
exports.getDirnameMaxDepth = getDirnameMaxDepth;
const jsonOutput = ({ value }) => {
return JSON.stringify(value);
const jsonOutput = ({ value, escape }) => {
return JSON.stringify(value, (key, value) => {
if (typeof value === 'string') {
// if escape is true, escape quotes and backslashes
return escape ? value.replace(/\\/g, '\\\\').replace(/"/g, '\\"') : value;
}
return value;
});
};
exports.jsonOutput = jsonOutput;
const getFilePatterns = ({ inputs }) => __awaiter(void 0, void 0, void 0, function* () {

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -73,7 +73,7 @@ export const getRenamedFiles = async ({
}
if (inputs.json) {
return jsonOutput({value: renamedFiles})
return jsonOutput({value: renamedFiles, escape: inputs.escape_json})
}
return renamedFiles.join(inputs.oldNewFilesSeparator)
@ -146,7 +146,7 @@ export const getDiffFiles = async ({
}
if (inputs.json) {
return jsonOutput({value: files})
return jsonOutput({value: files, escape: inputs.escape_json})
}
return files.join(inputs.separator)

View File

@ -24,6 +24,7 @@ export type Inputs = {
dirNamesMaxDepth?: number
dirNamesExcludeRoot: boolean
json: boolean
escape_json: boolean
fetchDepth?: number
sinceLastRemoteCommit: boolean
writeOutputFiles: boolean
@ -94,6 +95,7 @@ export const getInputs = (): Inputs => {
required: false
})
const json = core.getBooleanInput('json', {required: false})
const escape_json = core.getBooleanInput('escape_json', {required: false})
const fetchDepth = core.getInput('fetch_depth', {required: false})
const sinceLastRemoteCommit = core.getBooleanInput(
'since_last_remote_commit',
@ -130,6 +132,7 @@ export const getInputs = (): Inputs => {
dirNames,
dirNamesExcludeRoot,
json,
escape_json,
sinceLastRemoteCommit,
writeOutputFiles,
outputDir,

View File

@ -19,7 +19,9 @@ import {
export async function run(): Promise<void> {
const env = getEnv()
core.debug(`Env: ${JSON.stringify(env, null, 2)}`)
const inputs = getInputs()
core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`)
await verifyMinimumGitVersion()

View File

@ -641,8 +641,20 @@ export const getDirnameMaxDepth = ({
return output
}
export const jsonOutput = ({value}: {value: string | string[]}): string => {
return JSON.stringify(value)
export const jsonOutput = ({
value,
escape
}: {
value: string | string[]
escape: boolean
}): string => {
return JSON.stringify(value, (key, value) => {
if (typeof value === 'string') {
// if escape is true, escape quotes and backslashes
return escape ? value.replace(/\\/g, '\\\\').replace(/"/g, '\\"') : value
}
return value
})
}
export const getFilePatterns = async ({