From 951140b94a6a58dd2c62d7fb0b4d73898c79b196 Mon Sep 17 00:00:00 2001 From: Arthur <37664438+V0lantis@users.noreply.github.com> Date: Tue, 19 Sep 2023 21:18:22 +0200 Subject: [PATCH] fix: changed_keys and modified_keys output to handle json and escape_json inputs (#1585) Co-authored-by: Arthur Volant Co-authored-by: Tonye Jack Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com> --- dist/index.js | Bin 1703993 -> 1704300 bytes dist/index.js.map | Bin 1710575 -> 1710906 bytes src/changedFiles.ts | 18 ++++++-------- src/changedFilesOutput.ts | 48 +++++++++++++------------------------- src/utils.ts | 26 +++++++++++++++++++++ 5 files changed, 49 insertions(+), 43 deletions(-) diff --git a/dist/index.js b/dist/index.js index 47ebd7398bf1de90de4626e9288f2b08095dee79..7cde3de9de09fa7ecf19da63f7665ee6379d3dc9 100644 GIT binary patch delta 316 zcmdnlknyG|W5W)S=?XI#S*Jgk!N@lGzaZ=6+ENZ?@6^ia8}%7Q_;d49GSf0sQ-A`+ znzaejAAS`SoxD#ZZ1V0}ZV3f@1!Q>zD=2qzzSxS%9|E|h&yE-2oIJBgdGc{l4>Vf> zQrY3Q@Fiy?=A~m;qCeS1ObuiaKhPp1B?^->#MYymFEzPf8e6lCc)N`_BM>tIF*6Xe z05K~NvjH(X5OV-AClGT1F*gwN05LBR^8qnG5DNgYAP@@yu`m#e0I?_#ivcmnY>DkQ J;*x(~007jGY4HF6 delta 203 zcmZw7s}9027zWS`Mj55!wstLwSukt~?}ES}Cvf$ofdm}p7quuH2@Vh>@HPluV2)2B z5XYU*ro6lIa+7|#l#H^MpyNV$Hx5F|RY8w=L_2k&Y8}%d5j2`{a_QvH&U8*Ieg2uu uyJx_+*6ghbpayjap#cn<5J3w#v_U`&9q2+2`Y?b5Bq&HhgSlEWtlnSX??Q3_ diff --git a/dist/index.js.map b/dist/index.js.map index 3b6d5aedd88a22f210da1cf7a416bf57df1ed078..58bd710ea680b713512ebc2a2795f792bc36ab47 100644 GIT binary patch delta 375 zcmaFAIb+whj18OECkBX2Qs!dHi`;xsO_pPlGI#Sc{`P15j6lq^{TV;=?at}``Yf!| zKTKohp5Fh5nS=lr8C`^}~#k_g?*~dV0Yb;r~r{8|etTcVOE33@(2R%F- z(|^rkR!3Mp?F}CJ6xzrV^YKeq%Bv)rQRnjfyC@L?nw+zYA0(}23X z59r9tHz{o9r154)!~br~98&V1*gU(F%GZG``Ef+>T^STmL4yJmK?eg$V1fl@s6Z8J QU_%`m&;%!oqt 0) { - await setOutput({ + await setArrayOutput({ key: 'modified_keys', - value: modifiedKeys.join(inputs.separator), - writeOutputFiles: inputs.writeOutputFiles, - outputDir: inputs.outputDir, - json: inputs.json + inputs, + value: modifiedKeys }) } if (changedKeys.length > 0) { - await setOutput({ + await setArrayOutput({ key: 'changed_keys', - value: changedKeys.join(inputs.separator), - writeOutputFiles: inputs.writeOutputFiles, - outputDir: inputs.outputDir, - json: inputs.json + inputs, + value: changedKeys }) } } diff --git a/src/changedFilesOutput.ts b/src/changedFilesOutput.ts index 5cdc7742..8905fc9d 100644 --- a/src/changedFilesOutput.ts +++ b/src/changedFilesOutput.ts @@ -6,11 +6,7 @@ import { getChangeTypeFiles } from './changedFiles' import {Inputs} from './inputs' -import {setOutput} from './utils' - -const getOutputKey = (key: string, outputPrefix: string): string => { - return outputPrefix ? `${outputPrefix}_${key}` : key -} +import {getOutputKey, setArrayOutput, setOutput} from './utils' const getArrayFromPaths = ( paths: string | string[], @@ -283,15 +279,11 @@ export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({ json: inputs.json }) - await setOutput({ - key: getOutputKey('other_changed_files', outputPrefix), - value: inputs.json - ? otherChangedFiles - : otherChangedFiles.join(inputs.separator), - writeOutputFiles: inputs.writeOutputFiles, - outputDir: inputs.outputDir, - json: inputs.json, - shouldEscape: inputs.escapeJson + await setArrayOutput({ + key: 'other_changed_files', + inputs, + value: otherChangedFiles, + outputPrefix }) await setOutput({ @@ -376,15 +368,11 @@ export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({ json: inputs.json }) - await setOutput({ - key: getOutputKey('other_modified_files', outputPrefix), - value: inputs.json - ? otherModifiedFiles - : otherModifiedFiles.join(inputs.separator), - writeOutputFiles: inputs.writeOutputFiles, - outputDir: inputs.outputDir, - json: inputs.json, - shouldEscape: inputs.escapeJson + await setArrayOutput({ + key: 'other_modified_files', + inputs, + value: otherModifiedFiles, + outputPrefix }) await setOutput({ @@ -457,15 +445,11 @@ export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({ json: inputs.json }) - await setOutput({ - key: getOutputKey('other_deleted_files', outputPrefix), - value: inputs.json - ? otherDeletedFiles - : otherDeletedFiles.join(inputs.separator), - writeOutputFiles: inputs.writeOutputFiles, - outputDir: inputs.outputDir, - json: inputs.json, - shouldEscape: inputs.escapeJson + await setArrayOutput({ + key: 'other_deleted_files', + inputs, + value: otherDeletedFiles, + outputPrefix }) await setOutput({ diff --git a/src/utils.ts b/src/utils.ts index 2fe25192..65975e0e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1222,6 +1222,32 @@ export const getRecoverFilePatterns = ({ return filePatterns.filter(Boolean) } +export const getOutputKey = (key: string, outputPrefix: string): string => { + return outputPrefix ? `${outputPrefix}_${key}` : key +} + +export const setArrayOutput = async ({ + key, + inputs, + value, + outputPrefix +}: { + key: string + inputs: Inputs + value: string[] + outputPrefix?: string +}): Promise => { + core.debug(`${key}: ${JSON.stringify(value)}`) + await setOutput({ + key: outputPrefix ? getOutputKey(key, outputPrefix) : key, + value: inputs.json ? value : value.join(inputs.separator), + writeOutputFiles: inputs.writeOutputFiles, + outputDir: inputs.outputDir, + json: inputs.json, + shouldEscape: inputs.escapeJson + }) +} + export const setOutput = async ({ key, value,