@@ -15,12 +15,15 @@ checkInputs().then(() => {
|
|||||||
async function checkInputs() {
|
async function checkInputs() {
|
||||||
const eventPath = process.env.GITHUB_EVENT_PATH,
|
const eventPath = process.env.GITHUB_EVENT_PATH,
|
||||||
event = eventPath && require(eventPath),
|
event = eventPath && require(eventPath),
|
||||||
|
token = process.env.GITHUB_TOKEN,
|
||||||
isPR = process.env.GITHUB_EVENT_NAME?.includes('pull_request'),
|
isPR = process.env.GITHUB_EVENT_NAME?.includes('pull_request'),
|
||||||
sha = (event?.pull_request?.head?.sha || process.env.GITHUB_SHA) as string,
|
sha = (event?.pull_request?.head?.sha || process.env.GITHUB_SHA) as string,
|
||||||
defaultRef = isPR
|
defaultRef = isPR
|
||||||
? event?.pull_request?.head?.ref as string
|
? event?.pull_request?.head?.ref as string
|
||||||
: process.env.GITHUB_REF?.substring(11)
|
: process.env.GITHUB_REF?.substring(11)
|
||||||
|
|
||||||
|
if (!token) warning('The GITHUB_TOKEN env variable is missing: the action may not work as expected.')
|
||||||
|
|
||||||
const actualRef = setDefault('ref', defaultRef || '')
|
const actualRef = setDefault('ref', defaultRef || '')
|
||||||
|
|
||||||
let author = event?.head_commit?.author
|
let author = event?.head_commit?.author
|
||||||
@@ -29,8 +32,8 @@ async function checkInputs() {
|
|||||||
|
|
||||||
// https://docs.github.com/en/rest/reference/repos#get-a-commit--code-samples
|
// 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}`,
|
const url = `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}`,
|
||||||
headers = process.env.GITHUB_TOKEN ? {
|
headers = token ? {
|
||||||
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`
|
Authorization: `Bearer ${token}`
|
||||||
} : undefined,
|
} : undefined,
|
||||||
commit = (await axios.get(url, { headers }).catch(err => {
|
commit = (await axios.get(url, { headers }).catch(err => {
|
||||||
info('::group::Request error:')
|
info('::group::Request error:')
|
||||||
|
|||||||
Reference in New Issue
Block a user