fix: add warning when GITHUB_TOKEN is not present

Ref issue #51
This commit is contained in:
Federico Grandi
2020-08-21 13:32:46 +02:00
parent f7d13fceb9
commit 208182ae37

View File

@@ -15,12 +15,15 @@ checkInputs().then(() => {
async function checkInputs() {
const eventPath = process.env.GITHUB_EVENT_PATH,
event = eventPath && require(eventPath),
token = process.env.GITHUB_TOKEN,
isPR = process.env.GITHUB_EVENT_NAME?.includes('pull_request'),
sha = (event?.pull_request?.head?.sha || process.env.GITHUB_SHA) as string,
defaultRef = isPR
? event?.pull_request?.head?.ref as string
: 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 || '')
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
const url = `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}`,
headers = process.env.GITHUB_TOKEN ? {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`
headers = token ? {
Authorization: `Bearer ${token}`
} : undefined,
commit = (await axios.get(url, { headers }).catch(err => {
info('::group::Request error:')