-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.babel.js
51 lines (41 loc) · 1.34 KB
/
index.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Description:
// Show open issues from a Github repository
//
// Configuration:
// HUBOT_GITHUB_REPO
// HUBOT_GITHUB_TOKEN
// HUBOT_GITHUB_ISSUE_LINK_IGNORE_USERS
//
// Commands:
// #nnn - link to Github issue nn from HUBOT_GITHUB_REPO project
//
// Dependencies:
// "githubot": "1.0.0"
//
// Notes:
// The HUBOT_GITHUB_TOKEN and HUBOT_GITHUB_REPO env vars are required.
//
// Author:
// Michael Coyne (@mikeycgto)
import {default as GitHubot} from 'githubot';
const TOKEN = process.env.HUBOT_GITHUB_TOKEN;
const REPO = process.env.HUBOT_GITHUB_REPO;
const IGNORED = (process.env.HUBOT_GITHUB_ISSUE_LINK_IGNORE_USERS || '').split(',');
export default (robot) => {
if (TOKEN == undefined || REPO == undefined){
console.warn("Missing HUBOT_GITHUB_TOKEN and/or HUBOT_GITHUB_REPO");
return;
}
const github = GitHubot(robot);
robot.hear(/((\S*|^)?#(\d+)).*/, (msg) => {
const issue = +msg.match[3];
if (issue == undefined || isNaN(issue))
return;
if (IGNORED.indexOf(msg.message.user.name) !== -1)
return;
github.get(`repos/${REPO}/issues/${issue}`, (issue_resp) => {
const state = issue_resp.state || 'UNKNOWN';
msg.send(`Issue ${issue}: ${issue_resp.title} (${state.toUpperCase()} - ${issue_resp.html_url})`);
});
});
};