Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { createProbot } = require('probot');
const { GitHubAPI, ProbotOctokit } = require('../../lib/github/client');
const logger = require('../../lib/logger');
const nock = require('nock');
const slackbot = require('../slackbot');
const app = require('../../lib');
const models = require('../../lib/models');
const cache = require('../../lib/cache');
const probot = createProbot({});
const robot = probot.load(app);
// raise errors in tests
robot.catchErrors = false;
// Expect there are no more pending nock requests
beforeEach(async () => nock.cleanAll());
afterEach(() => expect(nock.pendingMocks()).toEqual([]));
// Ensure there is a connection established
beforeAll(async () => {
if (global.gc) {
global.gc();
}
models.sequelize.authenticate();
});
require('dotenv').config()
const throng = require('throng')
if (process.env.NEWRELIC_KEY) {
require('newrelic') // eslint-disable-line global-require
}
require('../lib/config/sentry').initializeSentry()
const { findPrivateKey } = require('probot/lib/private-key')
const { createProbot } = require('probot')
const app = require('./configure-robot')
const workers = process.env.WEB_CONCURRENCY || 1
const probot = createProbot({
id: process.env.APP_ID,
secret: process.env.WEBHOOK_SECRET,
cert: findPrivateKey(),
port: process.env.TUNNEL_PORT || process.env.PORT || 3000,
webhookPath: '/github/events',
webhookProxy: process.env.WEBHOOK_PROXY_URL
})
/**
* Start the probot worker.
*/
function start () {
probot.load(app)
probot.start()
}
module.exports = (...handlers) => {
// Setup Probot app
const githubToken = process.env.GITHUB_TOKEN;
const probot = createProbot({ githubToken });
probot.setup(handlers);
// Process the event
const event = process.env.GITHUB_EVENT_NAME;
const payloadPath = process.env.GITHUB_EVENT_PATH;
// eslint-disable-next-line global-require, import/no-dynamic-require
const payload = require(path.resolve(payloadPath));
core.debug(`Receiving event ${JSON.stringify(event)}`);
probot.receive({ name: event, payload, id: uuid.v4() }).catch(err => {
// setFailed logs the message and sets a failing exit code
core.setFailed(`Action failed with error: ${err.message}`);
});
};
export function main(port: number): Server {
/* Credentials */
if (
!process.env.APP_ID ||
!process.env.WEBHOOK_SECRET ||
!(process.env.PRIVATE_KEY || process.env.PRIVATE_KEY_PATH)
) {
throw new Error('Missing credentials.')
}
/* Probot setup */
const cert = findPrivateKey() as string
const probot = createProbot({
id: parseInt(process.env.APP_ID, 10),
secret: process.env.WEBHOOK_SECRET,
cert: cert,
port: port,
})
/* Load apps */
const apps: ApplicationFunction[] = [
opencollective,
require('probot/lib/apps/default'),
require('probot/lib/apps/sentry'),
require('probot/lib/apps/stats'),
]
;(process as NodeJS.EventEmitter).on(
'unhandledRejection',
const loadProbot = appFn => {
probot =
probot ||
createProbot({
id: process.env.APP_ID,
secret: process.env.WEBHOOK_SECRET,
cert: findPrivateKey(),
});
if (typeof appFn === 'string') {
appFn = resolve(appFn);
}
probot.load(appFn);
return probot;
};
function getProbot() {
const probot = createProbot({
id: process.env.APP_ID,
secret: process.env.WEBHOOK_SECRET,
cert: findPrivateKey(),
})
if (process.env.SENTRY_DSN) {
probot.load(require('probot/lib/apps/sentry'))
}
return probot
}
const loadProbot = appFn => {
probot = probot || createProbot({
id: process.env.APP_ID,
secret: process.env.WEBHOOK_SECRET,
cert: findPrivateKey()
})
if (typeof appFn === 'string') {
appFn = resolve(appFn)
}
probot.load(appFn)
return probot
}
async loadProbot(appFn: ApplicationFunction): Promise {
if (!this.probot) {
const cfg = await this.getProbotConfig();
this.probot = createProbot(cfg);
}
this.probot.load(appFn);
return this.probot;
}
const createProbot = () => {
const options = {
cert: String(findPrivateKey()),
id: Number(process.env.APP_ID),
secret: process.env.WEBHOOK_SECRET,
};
return _createProbot(options);
};