Skip to content

Commit

Permalink
fix: changed_keys and modified_keys output to handle json and escape_…
Browse files Browse the repository at this point in the history
…json inputs (#1585)

Co-authored-by: Arthur Volant <arthur.volant@adevinta.com>
Co-authored-by: Tonye Jack <jtonye@ymail.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Sep 19, 2023
1 parent dbf0700 commit 951140b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 48 deletions.
12 changes: 8 additions & 4 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.

18 changes: 7 additions & 11 deletions src/changedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
gitSubmoduleDiffSHA,
isWindows,
jsonOutput,
setOutput
setArrayOutput
} from './utils'

export const processChangedFiles = async ({
Expand Down Expand Up @@ -85,22 +85,18 @@ export const processChangedFiles = async ({
}

if (modifiedKeys.length > 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
})
}
}
Expand Down
48 changes: 16 additions & 32 deletions src/changedFilesOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
26 changes: 26 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
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,
Expand Down

0 comments on commit 951140b

Please sign in to comment.