2018-02-06 12:47:21 +00:00
|
|
|
const MemCache = require('mem-cache')
|
2018-02-06 11:17:58 +00:00
|
|
|
const slackGitHubCache = new MemCache({ timeoutDisabled: true })
|
2018-02-06 12:47:21 +00:00
|
|
|
const SlackGitHubCacheBuilder = require('./lib/retrieve-slack-github-users')
|
2018-02-14 11:37:49 +00:00
|
|
|
const Slack = require('./lib/slack')
|
2018-02-04 18:09:13 +00:00
|
|
|
|
|
|
|
module.exports = async (robot) => {
|
2018-01-22 13:48:57 +00:00
|
|
|
console.log('Yay, the app was loaded!')
|
|
|
|
|
2018-02-14 11:37:49 +00:00
|
|
|
Slack(robot, slack => {})
|
|
|
|
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
robot.on('slack.connected', event => {
|
|
|
|
robot.log.info(`Connected to Slack`)
|
|
|
|
|
|
|
|
// Copy Slack RTM and Slack Web clients to the robot object
|
|
|
|
robot['slack'] = event.payload.slack
|
|
|
|
robot['slackWeb'] = event.payload.slackWeb
|
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-02-06 12:47:21 +00:00
|
|
|
const slackCachePromise = SlackGitHubCacheBuilder.build(robot, slackGitHubCache)
|
2018-02-04 18:09:13 +00:00
|
|
|
|
2018-02-05 14:33:43 +00:00
|
|
|
require('./bot_scripts/assign-new-pr-to-review')(robot)
|
|
|
|
require('./bot_scripts/assign-approved-pr-to-test')(robot)
|
|
|
|
require('./bot_scripts/assign-to-bounty-awaiting-for-approval')(robot)
|
|
|
|
require('./bot_scripts/greet-new-contributor')(robot)
|
2018-02-07 16:59:55 +00:00
|
|
|
require('./bot_scripts/trigger-automation-test-build')(robot)
|
2018-01-22 13:48:57 +00:00
|
|
|
|
2018-02-04 18:09:13 +00:00
|
|
|
await slackCachePromise
|
2018-02-06 12:47:21 +00:00
|
|
|
robot.log.info('Slack user ID cache populated, loading remainder of scripts')
|
2018-02-04 18:09:13 +00:00
|
|
|
|
|
|
|
// Add scripts which require using the Slack/GitHub cache after this comment
|
2018-02-06 11:17:58 +00:00
|
|
|
require('./bot_scripts/bounty-awaiting-approval-slack-ping')(robot, getSlackMentionFromGitHubId)
|
2018-02-12 18:43:12 +00:00
|
|
|
require('./bot_scripts/notify-reviewers-via-slack')(robot, getSlackIdFromGitHubId)
|
2018-02-04 18:09:13 +00:00
|
|
|
|
2018-01-22 13:48:57 +00:00
|
|
|
// For more information on building apps:
|
|
|
|
// https://probot.github.io/docs/
|
|
|
|
|
|
|
|
// To get your app running against GitHub, see:
|
|
|
|
// https://probot.github.io/docs/development/
|
|
|
|
}
|
2018-02-06 11:17:58 +00:00
|
|
|
|
|
|
|
function getSlackMentionFromGitHubId (gitHubId) {
|
|
|
|
const id = SlackGitHubCacheBuilder.getSlackIdFromGitHubId(gitHubId, slackGitHubCache)
|
|
|
|
if (!id) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
return `<@${id}>`
|
|
|
|
}
|
2018-02-12 18:43:12 +00:00
|
|
|
|
|
|
|
function getSlackIdFromGitHubId (gitHubId) {
|
|
|
|
return SlackGitHubCacheBuilder.getSlackIdFromGitHubId(gitHubId, slackGitHubCache)
|
|
|
|
}
|