-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgithub.coffee
More file actions
76 lines (67 loc) · 2.71 KB
/
github.coffee
File metadata and controls
76 lines (67 loc) · 2.71 KB
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
Promise = require 'bluebird'
{ Octokit } = require 'octokit'
daysToLookBack = 30
githubRateDelay = 200
delays = Promise.resolve()
octokit = null
exports.auth = (token) ->
octokit = new Octokit {auth: token}
octokit.rest.users.getAuthenticated()
.then (a) -> console.log 'GitHub Hello', (JSON.stringify a, null, 2)
process.once 'beforeExit', (code) ->
octokit.rest.users.getAuthenticated()
.then (a) -> console.log 'GitHub Goodbye', (JSON.stringify a, null, 2)
exports.getIssueAndCommentsAsync = (githubUser, githubRepo, issueNumber) ->
delays = delays.delay(githubRateDelay)
delays.then -> Promise.resolve octokit.request 'GET /repos/{owner}/{repo}/issues/{issue_number}',
owner: githubUser
repo: githubRepo
issue_number: issueNumber
.then (issue) ->
if issue.status isnt 200
console.log "ERROR: issue #{issueNumber} issue.status isnt 200"
throw issue
expect = "/#{githubUser}/#{githubRepo}/issues/#{issueNumber}"
# There's also html_url, but PRs are "pulls" there so we can't expect "issues"
if not issue.data.url.endsWith expect
console.log "ERROR: issue moved? '#{issue.data.url}' does not end with '#{expect}'"
issue.issueMoved = true
throw issue
issue.data
.then (issue) ->
console.log "Downloading comments for issue #{issueNumber}..."
delays = delays.delay(githubRateDelay)
delays.then -> Promise.resolve octokit.paginate 'GET /repos/{owner}/{repo}/issues/{issue_number}/comments',
owner: githubUser
repo: githubRepo
issue_number: issue.number
per_page: 100
.then (comments) ->
console.log "Downloaded #{comments.length} comments for issue #{issue.number}."
issue: issue
comments: comments
exports.openIssuesAndCommentsAsync = (githubUser, githubRepo, issue_filter = (->true)) ->
console.log "Downloading open issues..."
delays = delays.delay(githubRateDelay)
delays.then -> Promise.resolve octokit.paginate 'GET /repos/{owner}/{repo}/issues',
owner: githubUser
repo: githubRepo
state: 'open'
per_page: 100
since: (new Date (new Date).getTime() - (daysToLookBack*24*60*60*1000)).toISOString()
.filter issue_filter
.then (issues) ->
console.log "Downloaded #{issues.length} issues."
console.log "Downloading comments for all open issues..."
issues
.map (issue) ->
delays = delays.delay(githubRateDelay)
delays.then -> Promise.resolve octokit.paginate 'GET /repos/{owner}/{repo}/issues/{issue_number}/comments',
owner: githubUser
repo: githubRepo
issue_number: issue.number
per_page: 100
.then (comments) ->
console.log "Downloaded #{comments.length} comments for issue #{issue.number}."
issue: issue
comments: comments