probot/bin/probot-run.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

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-08-23 11:06:31 +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...>')
.option('-p, --port <n>', 'Port to start the server on', process.env.PORT || 3000)
.option('-t, --tunnel <subdomain>', 'Expose your local bot to the internet', process.env.SUBDOMAIN || process.env.NODE_ENV !== 'production')
.option('-w, --webhook-path <path>', 'URL path which receives webhooks. Ex: `/webhook`', process.env.WEBHOOK_PATH)
.option('-a, --app <id>', 'ID of the GitHub App', process.env.APP_ID)
.option('-s, --secret <secret>', 'Webhook secret of the GitHub App', process.env.WEBHOOK_SECRET)
.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
if (!program.app) {
2017-08-23 11:06:31 +08:00
console.warn('Missing GitHub App ID.\nUse --app flag or set APP_ID environment variable.')
program.help()
2017-03-20 00:51:45 +08:00
}
if (!program.privateKey) {
2017-08-23 11:06:31 +08:00
program.privateKey = findPrivateKey()
}
2017-08-23 11:06:31 +08:00
const createProbot = require('../')
2017-03-18 12:04:23 +08:00
const probot = createProbot({
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,
port: program.port,
webhookPath: program.webhookPath
2017-08-23 11:06:31 +08:00
})
2017-03-18 12:04:23 +08:00
if (program.tunnel && !process.env.DISABLE_TUNNEL) {
try {
const setupTunnel = require('../lib/tunnel')
setupTunnel(program.tunnel, program.port)
} catch (err) {
probot.logger.debug('Run `npm install --save-dev localtunnel` to enable localtunnel.')
}
}
2017-03-18 12:04:23 +08:00
pkgConf('probot').then(pkg => {
probot.setup(program.args.concat(pkg.apps || pkg.plugins || []))
2017-08-23 11:06:31 +08:00
probot.start()
})