Accept json or string encoding of result
This commit is contained in:
@@ -19,6 +19,9 @@ inputs:
|
||||
default: actions/github-script
|
||||
previews:
|
||||
description: A comma-separated list of API previews to accept
|
||||
result-encoding:
|
||||
description: Either "string" or "json" (default "json")—how the result will be encoded
|
||||
default: json
|
||||
outputs:
|
||||
result:
|
||||
description: The return value of the script, stringified with `JSON.stringify`
|
||||
|
||||
Vendored
+20
-3
File diff suppressed because one or more lines are too long
+18
-1
@@ -18,7 +18,24 @@ async function main() {
|
||||
const script = core.getInput('script', {required: true})
|
||||
const fn = new AsyncFunction('require', 'github', 'context', script)
|
||||
const result = await fn(require, client, context)
|
||||
core.setOutput('result', JSON.stringify(result))
|
||||
|
||||
let encoding = core.getInput('result-enoding')
|
||||
encoding = encoding != null ? encoding : 'json'
|
||||
|
||||
let output
|
||||
|
||||
switch (encoding) {
|
||||
case 'json':
|
||||
result = JSON.stringify(result)
|
||||
break
|
||||
case 'string':
|
||||
result = String(result)
|
||||
break
|
||||
default:
|
||||
throw new Error('"result-encoding" must be either "string" or "json"')
|
||||
}
|
||||
|
||||
core.setOutput('result', result)
|
||||
}
|
||||
|
||||
function handleError(err) {
|
||||
|
||||
Reference in New Issue
Block a user