This commit is contained in:
jysperm
2014-07-27 12:12:37 +08:00
parent 45f76942ef
commit bbeca9114a
2 changed files with 27 additions and 15 deletions

View File

@@ -28,7 +28,12 @@ app.get '/:username', (req, res) ->
username = req.param 'username'
sendRequest "/users/#{username}/events?per_page=300", (err, _res, body) ->
events = _.filter JSON.parse(body), (event) ->
body = JSON.parse body
unless _.isArray body
return res.status(404).end()
events = _.filter body, (event) ->
return event.type == 'PushEvent'
async.map events, (event, callback) ->
@@ -46,11 +51,14 @@ app.get '/:username', (req, res) ->
sendRequest "/repos/#{event.repo.name}/git/commits/#{commit.sha}", (err, _res, body) ->
body = JSON.parse body
result =
start: new Date body.committer.date
end: new Date body.committer.date
summary: "#{commit.message} (#{event.repo.name})"
url: body.html_url
if body.committer
result =
start: new Date body.committer.date
end: new Date body.committer.date
summary: "#{commit.message} (#{event.repo.name})"
url: body.html_url
else
result = {}
redis_client.set "github-commit-ical:#{commit.sha}", JSON.stringify(result), ->
callback err, result
@@ -64,7 +72,8 @@ app.get '/:username', (req, res) ->
for commits in result
for commit in commits
cal.addEvent commit
if commit.summary
cal.addEvent commit
console.log "[Request by] #{username}"
console.log "[X-RateLimit-Remaining] #{_res.headers['x-ratelimit-remaining']}"

View File

@@ -34,15 +34,18 @@ html
if (!username) {
return false;
}
url = "commit-calendar.newsbee.io/" + username;
if (window.navigator.platform.toUpperCase().indexOf('MAC') >= 0){
window.open("webcal://" + url);
}else{
link = document.getElementById('subscription_url')
link.innerHTML = "http://" + url;
subscription = document.getElementById('subscription')
subscription.style.display = "block";
url = "commit-calendar.newsbee.io/" + username;
if (window.navigator.platform.toUpperCase().indexOf('MAC') >= 0) {
window.open("webcal://" + url);
}
link = document.getElementById('subscription_url')
link.innerHTML = "http://" + url;
subscription = document.getElementById('subscription')
subscription.style.display = "block";
return false;
}