File diff suppressed because one or more lines are too long
84
src/main.ts
84
src/main.ts
@@ -227,49 +227,55 @@ async function checkInputs() {
|
|||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
// #region author_name, author_email
|
// #region author_name, author_email
|
||||||
let author = event?.head_commit?.author
|
if (getInput('author_name') && getInput('author_email')) {
|
||||||
if (sha && !author) {
|
info('> Using author info from inputs...')
|
||||||
info(
|
} else {
|
||||||
'> Unable to get commit from workflow event: trying with the GitHub API...'
|
info('> Some author info is missing, filling from workflow event...')
|
||||||
)
|
let author = event?.head_commit?.author
|
||||||
|
|
||||||
// https://docs.github.com/en/rest/reference/repos#get-a-commit--code-samples
|
if (sha && !author) {
|
||||||
const url = `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}`,
|
info(
|
||||||
headers = token
|
'> Unable to get commit from workflow event: trying with the GitHub API...'
|
||||||
? {
|
)
|
||||||
Authorization: `Bearer ${token}`
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
commit = (
|
|
||||||
await axios.get(url, { headers }).catch((err) => {
|
|
||||||
startGroup('Request error:')
|
|
||||||
info(`> Request URL: ${url}\b${err}`)
|
|
||||||
endGroup()
|
|
||||||
return undefined
|
|
||||||
})
|
|
||||||
)?.data
|
|
||||||
|
|
||||||
author = commit?.commit?.author
|
// https://docs.github.com/en/rest/reference/repos#get-a-commit--code-samples
|
||||||
}
|
const url = `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}`,
|
||||||
|
headers = token
|
||||||
|
? {
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
commit = (
|
||||||
|
await axios.get(url, { headers }).catch((err) => {
|
||||||
|
startGroup('Request error:')
|
||||||
|
info(`> Request URL: ${url}\b${err}`)
|
||||||
|
endGroup()
|
||||||
|
return undefined
|
||||||
|
})
|
||||||
|
)?.data
|
||||||
|
|
||||||
if (author) {
|
author = commit?.commit?.author
|
||||||
setDefault('author_name', author.name)
|
}
|
||||||
setDefault('author_email', author.email)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!getInput('author_name') || !getInput('author_email')) {
|
if (typeof author == 'object') {
|
||||||
const reason = !eventPath
|
setDefault('author_name', author.name)
|
||||||
? 'event path'
|
setDefault('author_email', author.email)
|
||||||
: isPR
|
}
|
||||||
? sha
|
|
||||||
? 'fetch commit'
|
if (!getInput('author_name') || !getInput('author_email')) {
|
||||||
: 'find commit sha'
|
const reason = !eventPath
|
||||||
: !event?.head_commit
|
? 'event path'
|
||||||
? 'find commit'
|
: isPR
|
||||||
: 'find commit author'
|
? sha
|
||||||
warning(`Unable to fetch author info: couldn't ${reason}.`)
|
? 'fetch commit'
|
||||||
setDefault('author_name', 'Add & Commit Action')
|
: 'find commit sha'
|
||||||
setDefault('author_email', 'actions@github.com')
|
: !event?.head_commit
|
||||||
|
? 'find commit'
|
||||||
|
: 'find commit author'
|
||||||
|
warning(`Unable to fetch author info: couldn't ${reason}.`)
|
||||||
|
setDefault('author_name', 'Add & Commit Action')
|
||||||
|
setDefault('author_email', 'actions@github.com')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info(
|
info(
|
||||||
|
|||||||
Reference in New Issue
Block a user