Permalink
Browse files

Added avatars for people.

  • Loading branch information...
Ian Langworth ☠
Ian Langworth ☠ committed Feb 13, 2013
1 parent 1640ff4 commit 1eb3f76be0d20ec76ba5c868768770513317b2b8
Showing with 61 additions and 3 deletions.
  1. +47 −0 prviewer.coffee
  2. +1 −0 public/stylesheets/style.css
  3. +1 −0 public/stylesheets/style.styl
  4. +12 −3 views/index.hjs
View
@@ -29,6 +29,10 @@ argv = optimist
settings = JSON.parse fs.readFileSync argv._[0]
+# Map of GitHub username -> Gravatar URL.
+# The URL might be null for names like 'WIP' and 'ALL'
+usernameToAvatar = {}
+
# -------------------------------------------------------------------------
# GITHUB OAUTH INITIALIZATION
# -------------------------------------------------------------------------
@@ -224,6 +228,49 @@ app.get '/', ensureAuthenticated, (req, res) ->
async.forEach pulls, iterator, (err) ->
cb err, pulls
+ # Replace submitter and reviewers with { username: ..., avatar: ... } objects.
+ (pulls, cb) ->
+
+ # Collect all names of reviewers.
+ usernames = {}
+ for pull in pulls
+ usernames[pull.user.login] = true
+ for name in pull.reviewers
+ usernames[name] = true
+
+ # Make sure we have avatars for everybody.
+ iterator = (username, cb2) ->
+ if username in ['wip', 'all'] or username of usernameToAvatar
+ return cb2()
+
+ github.user.getFrom {
+ user: username
+ }, (err, res) ->
+ return cb2 err if err
+ usernameToAvatar[username] = res.avatar_url
+ cb2()
+
+ # When done, replace properties with objects.
+ async.forEach Object.keys(usernames), iterator, (err) ->
+ for pull in pulls
+ pull.submitter =
+ username: pull.user.login
+ avatar: usernameToAvatar[pull.user.login]
+
+ if pull.last_commenter
+ pull.last_commenter =
+ username: pull.last_commenter
+ avatar: usernameToAvatar[pull.last_commenter]
+
+ obj = []
+ for name in pull.reviewers
+ obj.push
+ username: name
+ avatar: usernameToAvatar[name]
+ pull.reviewers = obj
+
+ cb err, pulls
+
# Sort the pulls based on update time.
(pulls, cb) ->
pulls.sort (a, b) ->
@@ -18,6 +18,7 @@ tr.pullrequest img {
height: 24px;
vertical-align: middle;
border-radius: 3px;
+ margin: 2px 0;
}
tr.pullrequest.ignore {
opacity: 0.5;
@@ -19,6 +19,7 @@ tr.pullrequest img
height: 24px
vertical-align: middle
border-radius: 3px
+ margin: 2px 0
tr.pullrequest.ignore
opacity: 0.5
View
@@ -49,16 +49,25 @@
<td><a href="{{html_url}}">#{{number}}</a></td>
<td>{{title}}</td>
<td>
- <img src="{{user.avatar_url}}"/>&nbsp;{{user.login}}
+ <img src="{{submitter.avatar}}" title="{{username}}" alt="{{username}}"/>
</td>
<td>
- {{reviewers}}
+ {{#reviewers}}
+ {{#avatar}}
+ <img src="{{avatar}}" title="{{username}}" alt="{{username}}"/>
+ {{/avatar}}
+ {{^avatar}}
+ <span style="text-transform: uppercase">{{username}}</span>
+ {{/avatar}}
+ {{/reviewers}}
</td>
<td><span class="label label-{{reviewStatusClass}}">{{reviewStatus}}</span></td>
<td>{{num_comments}}</td>
<td class="nowrap">
+ {{#last_commenter}}
+ <img src="{{avatar}}" title="{{username}}" alt="{{username}}"/>
+ {{/last_commenter}}
{{last_update}}
- {{#last_commenter}} <br/> by {{last_commenter}} {{/last_commenter}}
</td>
<td><code>{{head.ref}}</code></td>
<td><span class="label label-{{buildStatusClass}}">{{buildStatus}}</span></td>

0 comments on commit 1eb3f76

Please sign in to comment.