feat: add default_author (#181)

* feat: add deafult_author and start using actions-toolkit

* fix: go back to @actions/core for logs

* chore: add debug after fetching user

* test: keep build not minified

* fix: don't use tools.exit

* fix: author_displayname

* fix: check github_token

* fix: back to minified builds

* fix: fetch email too

* fix: change option names

* docs: document changes

* docs: update "github-actions" example
This commit is contained in:
Federico Grandi
2021-04-22 17:15:47 +02:00
committed by GitHub
parent eb4e956492
commit c698699df7
7 changed files with 1459 additions and 113 deletions

View File

@@ -1,5 +1,6 @@
import * as core from '@actions/core'
import { parseArgsStringToArgv } from 'string-argv'
import * as core from '@actions/core'
import { Toolkit } from 'actions-toolkit'
export type Input =
| 'add'
@@ -7,22 +8,49 @@ export type Input =
| 'author_email'
| 'branch'
| 'cwd'
| 'default_author'
| 'message'
| 'pull_strategy'
| 'push'
| 'remove'
| 'signoff'
| 'tag'
| 'github_token'
export const outputs = {
export type Output = 'committed' | 'pushed' | 'tagged'
type RecordOf<T extends string> = Record<T, string | undefined>
export const tools = new Toolkit<RecordOf<Input>, RecordOf<Output>>({
secrets: [
'GITHUB_EVENT_PATH',
'GITHUB_EVENT_NAME',
'GITHUB_REF',
'GITHUB_ACTOR'
]
})
tools.outputs = {
committed: 'false',
pushed: 'false',
tagged: 'false'
}
export type Output = keyof typeof outputs
export function getInput(name: Input) {
return core.getInput(name)
return tools.inputs[name] || ''
}
export async function getUserInfo(username?: string) {
if (!username) return undefined
const res = await tools.github.users.getByUsername({ username })
core.debug(
`Fetched github actor from the API: ${JSON.stringify(res?.data, null, 2)}`
)
return {
name: res?.data?.name,
email: res?.data?.email
}
}
export function log(err: any | Error, data?: any) {
@@ -72,7 +100,5 @@ export function parseBool(value: any) {
export function setOutput(name: Output, value: 'true' | 'false') {
core.debug(`Setting output: ${name}=${value}`)
outputs[name] = value
return core.setOutput(name, value)
tools.outputs[name] = value
}
for (const key in outputs) setOutput(key as Output, outputs[key])