-
Notifications
You must be signed in to change notification settings - Fork 2
/
unanswered-github-issues.js
executable file
·76 lines (64 loc) · 1.98 KB
/
unanswered-github-issues.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var GitHubApi = require('github')
, parallel = require('run-parallel')
, github = new GitHubApi({
version: '3.0.0'
, protocol: 'https'
, timeout: 5000
, headers: { 'user-agent': 'Unanswered-github-issues' }
})
, getIssueComments = function (issue, done) {
github.issues.getComments({
number: issue.number
, owner: issue.repository.owner.login
, repo: issue.repository.name
}, done)
}
, getIssuesWithComments = function (done) {
github.issues.getAll({ filter: 'mentioned' }, function (err, response) {
if (err) return done(err)
parallel(response.data.map(function (issue) {
return function (cb) {
getIssueComments(issue, function (err, comments) {
if (err && err.code !== 404) return cb(err)
issue.comments = comments && comments.data || []
cb(null, issue)
})
}
}), done)
})
}
module.exports = function (opts, callback) {
if (opts.token)
github.authenticate({
type: 'oauth'
, token: opts.token
})
else if (opts.username && opts.password) {
github.authenticate({
type: 'basic'
, username: opts.username
, password: opts.password
})
} else {
return callback(new Error('token or username & password required'))
}
github.users.get({}, function (err, user) {
if (err) return callback(err)
var username = user.login
, userregexp = new RegExp(username)
getIssuesWithComments(function (err, issues) {
if (err) return callback(err)
var unansweredIssues = issues.filter(function (issue) {
var unanswered = true
issue.comments.forEach(function (comment) {
if (userregexp.test(comment.body))
unanswered = true
if (comment.user.login === username)
unanswered = false
})
return unanswered
})
callback(null, unansweredIssues)
})
})
}