Permalink
Browse files

Consolidating the display of Push Events

  • Loading branch information...
Zach Moazeni
Zach Moazeni committed May 11, 2012
1 parent 245ce2d commit f2fa1e4c27354a2f9de588c9b7af1de504eb0525
Showing with 98 additions and 18 deletions.
  1. +39 −7 coffee/site.coffee
  2. +59 −11 js/site.js
View
@@ -33,7 +33,7 @@ class Repo extends Spine.Model
fetchHelper(1)
class Event extends Spine.Model
- @configure "Event", "type", "public", "repo", "created_at", "actor", "id", "payload"
+ @configure "Event", "type", "public", "repo", "created_at", "actor", "id", "payload", "commits"
@include TimeStamps
@fetchPages: (user, page, callback) ->
@@ -45,14 +45,46 @@ class Event extends Spine.Model
$.each(response.data, (i, eventData) -> events.push(new Event(eventData)))
if currentPage < max && hasMorePages(response.meta)
fetchHelper(currentPage + 1, events, callback)
- else if hasMorePages(response.meta)
- callback([currentPage + 1, events])
else
- callback([-1, events])
+ consolidated = @consolidateEvents(events)
+ if hasMorePages(response.meta)
+ callback([currentPage + 1, consolidated])
+ else
+ callback([-1, consolidated])
fetchHelper(page, [], callback)
+ @consolidateEvents: (events) ->
+ [otherEvents, pushEvents] = [[], []]
+ for e in events
+ if e.type == "PushEvent" then pushEvents.push(e) else otherEvents.push(e)
+
+ groups = {}
+ for e in pushEvents
+ groups[e.groupKey()] ||= []
+ groups[e.groupKey()].push(e)
+
+ for _, events of groups
+ keptEvent = events.shift()
+ keptEvent.addCommits(keptEvent.payload?.commits)
+ for e in events
+ keptEvent.addCommits(e.payload?.commits)
+
+ otherEvents.push(keptEvent)
+
+ otherEvents
+
+ constructor: (args) ->
+ super(args)
+ @commits ||= []
+
+ groupKey: ->
+ "#{@repo.name}-#{@created_at_short_string()}"
+
+ addCommits: (newCommits) ->
+ newCommits.forEach((e) => @commits.push(e)) if newCommits
+
viewType: ->
switch @type
when "PullRequestReviewCommentEvent"
@@ -176,16 +208,16 @@ class Event extends Spine.Model
repo:@repo.name
]
when "push"
- commits = @payload.commits.map((c, i) => {commit:c.sha, commit_url:"https://github.com/#{@repo.name}/commit/#{c.sha}", hidden:i > 2})
+ commits = @commits.map((c, i) => {commit:c.sha, commit_url:"https://github.com/#{@repo.name}/commit/#{c.sha}", hidden:i > 2})
[view,
id:@id,
login:@actor.login,
- num:@payload.commits.length,
+ num:commits.length,
commits:commits,
repo_url:"https://github.com/#{@repo.name}",
repo:@repo.name
date:@created_at_short_string(),
- more:@payload.commits.length > 3
+ more:commits.length > 3
]
when "gollum"
pages = @payload.pages.map((p, i) => {title:p.title, url:p.html_url, action:p.action, hidden:i > 2})
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit f2fa1e4

Please sign in to comment.