diff --git a/app.coffee b/app.coffee index b417adc..ebbd691 100644 --- a/app.coffee +++ b/app.coffee @@ -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']}" diff --git a/static/index.jade b/static/index.jade index cb37068..e6fd878 100644 --- a/static/index.jade +++ b/static/index.jade @@ -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; } \ No newline at end of file