From 8abc24f04bf12308b4ae17297d3cfa6403bb4c84 Mon Sep 17 00:00:00 2001
From: Jonas Weber <github@jonasw.de>
Date: Fri, 1 Jan 2016 17:09:54 +0100
Subject: [PATCH] Calculate actual avatar URL in model

repeated logic for Gravatar fallback
---
 app/components/build-header.coffee        | 17 -----------------
 app/components/builds-item.coffee         |  9 ---------
 app/models/commit.coffee                  | 17 +++++++++++++++++
 app/templates/components/build-header.hbs |  4 ++--
 app/templates/components/builds-item.hbs  |  2 +-
 5 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/app/components/build-header.coffee b/app/components/build-header.coffee
index e3f515f1..92eda750 100644
--- a/app/components/build-header.coffee
+++ b/app/components/build-header.coffee
@@ -1,5 +1,4 @@
 `import Ember from 'ember'`
-`import { gravatarImage } from 'travis/utils/urls'`
 `import GithubUrlPropertievs from 'travis/mixins/github-url-properties'`
 `import { durationFrom, safe } from 'travis/utils/helpers'`
 `import { githubCommit } from 'travis/utils/urls'`
@@ -10,22 +9,6 @@ BuildHeaderComponent = Ember.Component.extend
   classNames: ['build-header']
   classNameBindings: ['item.state']
 
-  committerAvatarUrl: (->
-    if url = @get('commit.committerAvatarUrl')
-      url
-    else
-      email = @get('commit.committerEmail')
-      gravatarImage(email, 40)
-  ).property('commit.committerEmail', 'commit.committerAvatarUrl')
-
-  authorAvatarUrl: (->
-    if url = @get('commit.authorAvatarUrl')
-      url
-    else
-      email = @get('commit.authorEmail')
-      gravatarImage(email, 40)
-  ).property('commit.authorEmail', 'commit.authorAvatarUrl')
-
   isJob: (->
     if @get('item.build') then true else false
   ).property('item')
diff --git a/app/components/builds-item.coffee b/app/components/builds-item.coffee
index 49c5e520..c2cf4740 100644
--- a/app/components/builds-item.coffee
+++ b/app/components/builds-item.coffee
@@ -1,5 +1,4 @@
 `import Ember from 'ember'`
-`import { gravatarImage } from 'travis/utils/urls'`
 `import { githubCommit as githubCommitUrl } from 'travis/utils/urls'`
 
 BuildsItemComponent = Ember.Component.extend
@@ -7,14 +6,6 @@ BuildsItemComponent = Ember.Component.extend
   classNameBindings: ['build.state']
   classNames: ['row-li', 'pr-row']
 
-  authorAvatarUrl: (->
-    if url = @get('build.commit.authorAvatarUrl')
-      url
-    else
-      email = @get('build.commit.authorEmail')
-      gravatarImage(email, 40)
-  ).property('build.commit.authorEmail', 'build.commit.authorAvatarUrl')
-
   urlGithubCommit: (->
     githubCommitUrl(@get('build.repo.slug'), @get('build.commit.sha'))
   ).property('build.commit.sha')
diff --git a/app/models/commit.coffee b/app/models/commit.coffee
index 3585b1e3..ac59140b 100644
--- a/app/models/commit.coffee
+++ b/app/models/commit.coffee
@@ -1,6 +1,7 @@
 `import Ember from 'ember'`
 `import Model from 'travis/models/model'`
 `import Build from 'travis/models/build'`
+`import { gravatarImage } from 'travis/utils/urls'`
 
 Commit = Model.extend
   sha:               DS.attr()
@@ -34,4 +35,20 @@ Commit = Model.extend
       @get('authorEmail') == @get('committerEmail')
   ).property('authorName', 'authorEmail', 'committerName', 'committerEmail')
 
+  authorAvatarUrl: (->
+    if url = @get('authorAvatarUrl')
+      url
+    else
+      email = @get('authorEmail')
+      gravatarImage(email, 40)
+  ).property('authorEmail', 'authorAvatarUrl')
+
+  committerAvatarUrl: (->
+    if url = @get('committerAvatarUrl')
+      url
+    else
+      email = @get('committerEmail')
+      gravatarImage(email, 40)
+  ).property('committerEmail', 'committerAvatarUrl')
+
 `export default Commit`
diff --git a/app/templates/components/build-header.hbs b/app/templates/components/build-header.hbs
index 442eeaed..1909834c 100644
--- a/app/templates/components/build-header.hbs
+++ b/app/templates/components/build-header.hbs
@@ -38,11 +38,11 @@
     </ul>
     <p class="commit-author">
       {{#if commit.authorName}}
-        <img src={{authorAvatarUrl}} alt="comitter avatar" aria-hidden="true"><span class="label-align">{{commit.authorName}} authored{{#if commit.authorIsCommitter}} and committed{{/if}}</span>
+        <img src={{commit.authorAvatarUrl}} alt="author avatar" aria-hidden="true"><span class="label-align">{{commit.authorName}} authored{{#if commit.authorIsCommitter}} and committed{{/if}}</span>
       {{/if}}
       {{#unless commit.authorIsCommitter}}
         {{#if commit.committerName}}
-          <img src={{committerAvatarUrl}} alt="comitter avatar" aria-hidden="true"><span class="label-align">{{commit.committerName}} committed</span>
+          <img src={{commit.committerAvatarUrl}} alt="comitter avatar" aria-hidden="true"><span class="label-align">{{commit.committerName}} committed</span>
         {{/if}}
       {{/unless}}
     </p>
diff --git a/app/templates/components/builds-item.hbs b/app/templates/components/builds-item.hbs
index 081e190f..7af0d5ea 100644
--- a/app/templates/components/builds-item.hbs
+++ b/app/templates/components/builds-item.hbs
@@ -20,7 +20,7 @@
     {{/unless}}
   </div>
   <div class="row-item row-committer">
-    <img class="avatar" src={{authorAvatarUrl}} alt="{{build.commit.committerName}} avatar">
+    <img class="avatar" src={{build.commit.authorAvatarUrl}} alt="{{build.commit.authorName}} avatar">
     <span class="label-align">{{build.commit.committerName}}</span>
   </div>
 </div>