This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds the basic features: - Connect to slack - Check periodically for PRs - Post a message to all specified slack channels listing the PRs
- Loading branch information
0 parents
commit ce7b1a9
Showing
6 changed files
with
1,791 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- stable | ||
- 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('./lib/server')() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const Slackbot = require('slackbots') | ||
const pullhub = require('pullhub') | ||
const debounce = require('lodash.debounce') | ||
|
||
module.exports = function server () { | ||
const requiredEnvs = ['SLACK_TOKEN', 'GH_TOKEN', 'SLACK_CHANNELS', 'GH_REPOS'] | ||
|
||
if (!requiredEnvs.every((k) => !!process.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 bot = new Slackbot({ | ||
token: process.env.SLACK_TOKEN, | ||
name: process.env.SLACK_BOT_NAME || 'PR-Police' | ||
}) | ||
|
||
bot.on('start', () => { | ||
checkForPRs() | ||
debounce(checkForPRs, checkInterval) | ||
}) | ||
|
||
function checkForPRs () { | ||
pullhub(repos, labels) | ||
.then((prs) => { | ||
const message = buildMessage(prs) | ||
return notify(message) | ||
}) | ||
.catch((err) => { | ||
console.error(err) | ||
}) | ||
} | ||
|
||
function buildMessage (data) { | ||
const message = data.map((item) => { | ||
return `#${item.number} - ${item.title} | ${item.html_url}` | ||
}) | ||
|
||
return message.join('\n') | ||
} | ||
|
||
function notify (message) { | ||
channels.map((channel) => { | ||
bot.postMessageToChannel(channel, message) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "pr-police", | ||
"version": "1.0.0", | ||
"description": "Slackbot that warns about open pull requests with given labels", | ||
"main": "index.js", | ||
"scripts": { | ||
"pretest": "standard", | ||
"test": "tape test/*.js | faucet", | ||
"start": "node index.js" | ||
}, | ||
"keywords": [ | ||
"slackbot", | ||
"pull", | ||
"request", | ||
"github", | ||
"labels" | ||
], | ||
"author": "rogeriopvl", | ||
"license": "MIT", | ||
"dependencies": { | ||
"lodash.debounce": "^4.0.8", | ||
"pullhub": "^1.0.1", | ||
"slackbots": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"faucet": "^0.0.1", | ||
"proxyquire": "^1.7.11", | ||
"sinon": "^2.1.0", | ||
"standard": "^10.0.2", | ||
"tape": "^4.6.3" | ||
} | ||
} |
Oops, something went wrong.