2017-03-18 12:04:23 +08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2017-08-23 11:06:31 +08:00
|
|
|
require('dotenv').config()
|
2017-03-18 12:04:23 +08:00
|
|
|
|
2017-08-23 11:06:31 +08:00
|
|
|
const pkgConf = require('pkg-conf')
|
|
|
|
const program = require('commander')
|
2017-04-27 05:39:01 +08:00
|
|
|
|
2019-01-28 02:13:40 +08:00
|
|
|
const { findPrivateKey } = require('../lib/private-key')
|
2017-03-18 12:04:23 +08:00
|
|
|
|
|
|
|
program
|
2017-08-20 23:42:51 +08:00
|
|
|
.usage('[options] <apps...>')
|
2017-11-27 10:42:04 +08:00
|
|
|
.option('-p, --port <n>', 'Port to start the server on', process.env.PORT || 3000)
|
2017-12-08 02:30:18 +08:00
|
|
|
.option('-W, --webhook-proxy <url>', 'URL of the webhook proxy service.`', process.env.WEBHOOK_PROXY_URL)
|
2017-11-27 10:42:04 +08:00
|
|
|
.option('-w, --webhook-path <path>', 'URL path which receives webhooks. Ex: `/webhook`', process.env.WEBHOOK_PATH)
|
2017-06-06 10:04:26 +08:00
|
|
|
.option('-a, --app <id>', 'ID of the GitHub App', process.env.APP_ID)
|
2017-06-28 00:50:21 +08:00
|
|
|
.option('-s, --secret <secret>', 'Webhook secret of the GitHub App', process.env.WEBHOOK_SECRET)
|
2017-06-06 10:04:26 +08:00
|
|
|
.option('-P, --private-key <file>', 'Path to certificate of the GitHub App', findPrivateKey)
|
2017-08-23 11:06:31 +08:00
|
|
|
.parse(process.argv)
|
2017-03-18 12:04:23 +08:00
|
|
|
|
2018-09-27 03:22:11 +08:00
|
|
|
program.privateKey = findPrivateKey()
|
2017-04-29 20:50:59 +08:00
|
|
|
|
2019-01-28 02:13:40 +08:00
|
|
|
const { createProbot } = require('../')
|
2017-03-18 12:04:23 +08:00
|
|
|
|
|
|
|
const probot = createProbot({
|
2017-06-06 10:04:26 +08:00
|
|
|
id: program.app,
|
2017-03-18 12:04:23 +08:00
|
|
|
secret: program.secret,
|
2017-03-20 00:58:12 +08:00
|
|
|
cert: program.privateKey,
|
2017-08-14 10:31:58 +08:00
|
|
|
port: program.port,
|
2017-12-08 02:30:18 +08:00
|
|
|
webhookPath: program.webhookPath,
|
|
|
|
webhookProxy: program.webhookProxy
|
2017-08-23 11:06:31 +08:00
|
|
|
})
|
2017-03-18 12:04:23 +08:00
|
|
|
|
2018-09-27 03:22:11 +08:00
|
|
|
const setupMode = !program.app || !program.privateKey
|
|
|
|
|
|
|
|
if (setupMode) {
|
|
|
|
const setupApp = require('../lib/apps/setup')
|
|
|
|
probot.load(setupApp)
|
2017-08-23 11:06:31 +08:00
|
|
|
probot.start()
|
2018-09-27 03:22:11 +08:00
|
|
|
} else {
|
|
|
|
pkgConf('probot').then(pkg => {
|
|
|
|
probot.setup(program.args.concat(pkg.apps || pkg.plugins || []))
|
|
|
|
probot.start()
|
|
|
|
})
|
|
|
|
}
|