Skip to content

Commit

Permalink
use probot github adapter (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen committed Feb 11, 2021
1 parent a3b2539 commit 6f8e158
Show file tree
Hide file tree
Showing 5 changed files with 2,051 additions and 325 deletions.
39 changes: 2 additions & 37 deletions action.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
const { createProbot } = require('probot')
const core = require('@actions/core')
const { run } = require('@probot/adapter-github-actions')
const app = require('./index')

run().catch((err) => {
run(app).catch((err) => {
core.setFailed(`💥 Release drafter failed with error: ${err.message}`)
})

async function run() {
if (!process.env.GITHUB_TOKEN) {
throw new Error(
'env.GITHUB_TOKEN must be set, see https://github.com/probot/example-github-action#usage'
)
}

const envVariablesMissing = [
'GITHUB_RUN_ID',
'GITHUB_EVENT_NAME',
'GITHUB_EVENT_PATH',
].filter((name) => !process.env[name])

if (envVariablesMissing.length) {
const missingEnvs = envVariablesMissing.join(', ')
throw new Error(
`GitHub Action default environment variables missing: ${missingEnvs}. See https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables`
)
}

const probot = createProbot({
overrides: {
githubToken: process.env.GITHUB_TOKEN,
},
})

await probot.load(app)

return probot.receive({
id: process.env.GITHUB_RUN_ID,
name: process.env.GITHUB_EVENT_NAME,
payload: require(process.env.GITHUB_EVENT_PATH),
})
}
Loading

0 comments on commit 6f8e158

Please sign in to comment.