diff --git a/app/components/branch-row.coffee b/app/components/branch-row.coffee index 5a90c21d..bb40ad55 100644 --- a/app/components/branch-row.coffee +++ b/app/components/branch-row.coffee @@ -1,5 +1,4 @@ `import Ember from 'ember'` -`import { gravatarImage } from 'travis/utils/urls'` `import { githubCommit as githubCommitUrl } from 'travis/utils/urls'` `import TravisRoute from 'travis/routes/basic'` `import config from 'travis/config/environment'` 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/controllers/branches.coffee b/app/controllers/branches.coffee index e2b73697..528573df 100644 --- a/app/controllers/branches.coffee +++ b/app/controllers/branches.coffee @@ -1,5 +1,4 @@ `import Ember from 'ember'` -`import { gravatarImage } from 'travis/utils/urls'` `import GithubUrlPropertievs from 'travis/mixins/github-url-properties'` BranchesController = Ember.Controller.extend diff --git a/app/controllers/build.coffee b/app/controllers/build.coffee index 433dd49d..fcf82f19 100644 --- a/app/controllers/build.coffee +++ b/app/controllers/build.coffee @@ -1,5 +1,4 @@ `import Ember from 'ember'` -`import { gravatarImage } from 'travis/utils/urls'` `import GithubUrlPropertievs from 'travis/mixins/github-url-properties'` Controller = Ember.Controller.extend GithubUrlPropertievs, diff --git a/app/models/commit.coffee b/app/models/commit.coffee index 3585b1e3..e942b42e 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') + authorAvatarUrlOrGravatar: (-> + if url = @get('authorAvatarUrl') + url + else + email = @get('authorEmail') + gravatarImage(email, 40) + ).property('authorEmail', 'authorAvatarUrl') + + committerAvatarUrlOrGravatar: (-> + 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..15a1fc88 100644 --- a/app/templates/components/build-header.hbs +++ b/app/templates/components/build-header.hbs @@ -38,11 +38,11 @@

{{#if commit.authorName}} - {{commit.authorName}} authored{{#if commit.authorIsCommitter}} and committed{{/if}} + {{commit.authorName}} authored{{#if commit.authorIsCommitter}} and committed{{/if}} {{/if}} {{#unless commit.authorIsCommitter}} {{#if commit.committerName}} - {{commit.committerName}} committed + {{commit.committerName}} committed {{/if}} {{/unless}}

diff --git a/app/templates/components/builds-item.hbs b/app/templates/components/builds-item.hbs index 081e190f..46b11b3e 100644 --- a/app/templates/components/builds-item.hbs +++ b/app/templates/components/builds-item.hbs @@ -20,8 +20,8 @@ {{/unless}}
- {{build.commit.committerName}} avatar - {{build.commit.committerName}} + {{build.commit.authorName}} avatar + {{build.commit.authorName}}
diff --git a/app/views/job.coffee b/app/views/job.coffee index f9d93bbd..41cc3c96 100644 --- a/app/views/job.coffee +++ b/app/views/job.coffee @@ -1,6 +1,6 @@ `import Ember from 'ember'` `import { colorForState } from 'travis/utils/helpers'` -`import { githubCommit, gravatarImage } from 'travis/utils/urls'` +`import { githubCommit } from 'travis/utils/urls'` `import Polling from 'travis/mixins/polling'` View = Ember.View.extend Polling, @@ -20,12 +20,4 @@ View = Ember.View.extend Polling, githubCommit(@get('repo.slug'), @get('commit.sha')) ).property('repo.slug', 'commit.sha') - urlCommitterGravatarImage: (-> - gravatarImage(@get('commit.committerEmail'), 40) - ).property('commit.committerEmail') - - urlAuthorGravatarImage: (-> - gravatarImage(@get('commit.authorEmail'), 40) - ).property('commit.authorEmail') - `export default View` diff --git a/tests/unit/components/builds-item-test.coffee b/tests/unit/components/builds-item-test.coffee index eb1bbbee..4c449367 100644 --- a/tests/unit/components/builds-item-test.coffee +++ b/tests/unit/components/builds-item-test.coffee @@ -32,5 +32,4 @@ test 'it renders', (assert) -> ok component.$().hasClass('passed'), 'component has right status class' equal component.$('.row-branch a').text().trim(), 'foobarbranch', 'component renders branch if event is push' - equal component.$('.avatar').attr('src'), 'https://www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=40&d=https%3A%2F%2Ftravis-ci.org%2Fimages%2Fui%2Fdefault-avatar.png', 'component renders right gravatar image' equal component.$('a[title="See the commit on GitHub"]').attr('href'), 'https://github.com/foo/bar/commit/a5e8093098f9c0fb46856b753fb8943c7fbf26f3', 'component generates right commit link' diff --git a/tests/unit/models/commit-test.coffee b/tests/unit/models/commit-test.coffee new file mode 100644 index 00000000..d22dddee --- /dev/null +++ b/tests/unit/models/commit-test.coffee @@ -0,0 +1,25 @@ +`import { moduleForModel, test } from 'ember-qunit'` + +moduleForModel 'commit', 'Unit | Model | commit', needs: ['model:build'] + +test 'calculation of avatar urls via Gravatar', -> + model = @subject() + Ember.run -> + model.setProperties + authorEmail: 'author@example.com' + committerEmail: 'author@example.com' + authorAvatarUrl: null + committerAvatarUrl: null + equal model.get('authorAvatarUrlOrGravatar'), 'https://www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=40&d=https%3A%2F%2Ftravis-ci.org%2Fimages%2Fui%2Fdefault-avatar.png', 'correctly sets gravatar image' + equal model.get('committerAvatarUrlOrGravatar'), 'https://www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=40&d=https%3A%2F%2Ftravis-ci.org%2Fimages%2Fui%2Fdefault-avatar.png', 'correctly sets gravatar image' + +test 'calculation of avatar urls via overriding parameter', -> + model = @subject() + Ember.run -> + model.setProperties + authorEmail: 'author@example.com' + committerEmail: 'author@example.com' + authorAvatarUrl: 'http://example.com/test.jpg' + committerAvatarUrl: 'http://example.com/test2.jpg' + equal model.get('authorAvatarUrlOrGravatar'), 'http://example.com/test.jpg', 'correctly sets avatar' + equal model.get('committerAvatarUrlOrGravatar'), 'http://example.com/test2.jpg', 'correctly sets avatar'