Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
/ pr-police Public archive

Commit

Permalink
feat: add support for slack private groups
Browse files Browse the repository at this point in the history
the package slackbots distinguishes channels from private groups in its
API, so this commit refactors the code to support both channels and
groups and use the correct api method for each.
  • Loading branch information
rogeriopvl committed Apr 27, 2017
1 parent 74fdd3c commit 3d55c24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"description": "Slack channels to post the announcements, comma separated",
"value": ""
},
"SLACK_GROUPS": {
"description": "Slack private groups to post the announcements, comma separated",
"value": ""
},
"CHECK_INTERVAL": {
"description": "Time interval to check for new pull requests, in milliseconds",
"value": "3600000"
Expand Down
22 changes: 14 additions & 8 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ const pullhub = require('pullhub')
const debounce = require('lodash.debounce')

module.exports = function server () {
const requiredEnvs = ['SLACK_TOKEN', 'GH_TOKEN', 'SLACK_CHANNELS', 'GH_REPOS']
const env = process.env
const requiredEnvs = ['SLACK_TOKEN', 'GH_TOKEN', 'GH_REPOS']

if (!requiredEnvs.every((k) => !!process.env[k])) {
if (!requiredEnvs.every((k) => !!env[k])) {
throw (
new Error('Missing one of this required ENV vars: ' + requiredEnvs.join(','))
)
}

const channels = process.env.SLACK_CHANNELS.split(',') || []
const repos = process.env.GH_REPOS.split(',') || []
const labels = process.env.GH_LABELS
const checkInterval = process.env.CHECK_INTERVAL || 3600000 // 1 hour default
const channels = env.SLACK_CHANNELS ? env.SLACK_CHANNELS.split(',') : []
const groups = env.SLACK_GROUPS ? env.SLACK_GROUPS.split(',') : []
const repos = env.GH_REPOS ? env.GH_REPOS.split(',') : []
const labels = env.GH_LABELS
const checkInterval = env.CHECK_INTERVAL || 3600000 // 1 hour default

const bot = new Slackbot({
token: process.env.SLACK_TOKEN,
name: process.env.SLACK_BOT_NAME || 'PR-Police'
token: env.SLACK_TOKEN,
name: env.SLACK_BOT_NAME || 'PR-Police'
})

bot.on('start', () => {
Expand Down Expand Up @@ -49,5 +51,9 @@ module.exports = function server () {
channels.map((channel) => {
bot.postMessageToChannel(channel, message)
})

groups.map((group) => {
bot.postMessageToGroup(group, message)
})
}
}

0 comments on commit 3d55c24

Please sign in to comment.