-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.coffee
49 lines (37 loc) · 1.26 KB
/
index.coffee
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
icalendar = require 'icalendar'
async = require 'async'
github = require 'githubot'
express = require 'express'
_ = require 'underscore'
app = express()
process.env.HUBOT_GITHUB_TOKEN = process.env.GITHUB_TOKEN
allRepos = process.env.GITHUB_REPOS.split(',')
url = if process.env.URL_SECRET
"/milestones/#{process.env.URL_SECRET}.ics"
else
'/milestones.ics'
renderCalendar = (milestones) ->
ical = new icalendar.iCalendar()
for milestone in milestones
repoName = _.find(allRepos, (x) -> milestone.url.match(x)).split('/')[1]
event = ical.addComponent 'VEVENT'
event.setSummary "[#{repoName}] #{milestone.title}"
eventDate = new Date milestone.due_on
eventDate.date_only = true
event.setDate eventDate
ical.toString()
app.get url, (req, res) ->
showMilestoneFunctions = []
for repo in allRepos
do (repo) =>
showMilestoneFunctions.push( (cb) ->
github.get "repos/#{repo}/milestones", { state: 'open' }, (data) ->
cb(null, data)
)
async.parallel showMilestoneFunctions, (err, results) ->
console.log("ERROR: #{err}") if err
allResults = [].concat.apply([], results)
allResults = _.filter allResults, (r) ->
r.due_on
res.send(renderCalendar(allResults));
app.listen(process.env.PORT || 3000)