From b950b60c64320bf9bc013577156bec130e3dc159 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 10 Dec 2015 09:29:30 +0100 Subject: [PATCH] Fix committer and author in build header --- app/components/build-header.coffee | 20 ++++++++++++++------ app/components/builds-item.coffee | 11 +++++++---- app/models/commit.coffee | 2 ++ app/serializers/commit.js | 16 ++++++++++++++++ app/templates/components/build-header.hbs | 10 +++++----- app/templates/components/builds-item.hbs | 2 +- 6 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 app/serializers/commit.js diff --git a/app/components/build-header.coffee b/app/components/build-header.coffee index 3d0e584b..e3f515f1 100644 --- a/app/components/build-header.coffee +++ b/app/components/build-header.coffee @@ -10,13 +10,21 @@ BuildHeaderComponent = Ember.Component.extend classNames: ['build-header'] classNameBindings: ['item.state'] - urlCommitterGravatarImage: (-> - gravatarImage(@get('commit.committerEmail'), 40) - ).property('commit.committerEmail') + committerAvatarUrl: (-> + if url = @get('commit.committerAvatarUrl') + url + else + email = @get('commit.committerEmail') + gravatarImage(email, 40) + ).property('commit.committerEmail', 'commit.committerAvatarUrl') - urlAuthorGravatarImage: (-> - gravatarImage(@get('commit.authorEmail'), 40) - ).property('commit.authorEmail') + 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 diff --git a/app/components/builds-item.coffee b/app/components/builds-item.coffee index d836ec1c..49c5e520 100644 --- a/app/components/builds-item.coffee +++ b/app/components/builds-item.coffee @@ -3,14 +3,17 @@ `import { githubCommit as githubCommitUrl } from 'travis/utils/urls'` BuildsItemComponent = Ember.Component.extend - tagName: 'li' classNameBindings: ['build.state'] classNames: ['row-li', 'pr-row'] - urlAuthorGravatarImage: (-> - gravatarImage(@get('build.commit.authorEmail'), 40) - ).property('build.commit.authorEmail') + 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')) diff --git a/app/models/commit.coffee b/app/models/commit.coffee index 387c7b0d..3585b1e3 100644 --- a/app/models/commit.coffee +++ b/app/models/commit.coffee @@ -12,6 +12,8 @@ Commit = Model.extend committerName: DS.attr() committerEmail: DS.attr() committedAt: DS.attr() + committerAvatarUrl: DS.attr() + authorAvatarUrl: DS.attr() build: DS.belongsTo('build') diff --git a/app/serializers/commit.js b/app/serializers/commit.js new file mode 100644 index 00000000..3a51f116 --- /dev/null +++ b/app/serializers/commit.js @@ -0,0 +1,16 @@ +import Ember from 'ember'; +import V2FallbackSerializer from 'travis/serializers/v2_fallback'; + +export default V2FallbackSerializer.extend({ + normalize(modelClass, resourceHash) { + if(resourceHash.author && resourceHash.author.name) { + resourceHash.author_name = resourceHash.author.name; + resourceHash.author_avatar_url = resourceHash.author.avatar_url; + } + if(resourceHash.committer && resourceHash.committer.name) { + resourceHash.committer_name = resourceHash.author.name; + resourceHash.committer_avatar_url = resourceHash.author.avatar_url; + } + return this._super(...arguments); + } +}); diff --git a/app/templates/components/build-header.hbs b/app/templates/components/build-header.hbs index 07a9e7ae..d7897cdf 100644 --- a/app/templates/components/build-header.hbs +++ b/app/templates/components/build-header.hbs @@ -6,15 +6,15 @@ {{item.pullRequestTitle}} {{else}} {{item.branch.name}} - {{format-message item.commit.subject repo=item.repo}} + {{format-message commit.subject repo=item.repo}} {{/if}}

{{#if item.pullRequest}} - {{format-message item.commit.subject repo=item.repo}}
+ {{format-message commit.subject repo=item.repo}}
{{/if}} - {{format-message item.commit.body repo=item.repo pre=true}} + {{format-message commit.body repo=item.repo pre=true}}

{{#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 82d7c769..081e190f 100644 --- a/app/templates/components/builds-item.hbs +++ b/app/templates/components/builds-item.hbs @@ -20,7 +20,7 @@ {{/unless}}
- {{build.commit.committerName}} avatar + {{build.commit.committerName}} avatar {{build.commit.committerName}}