travis-api/lib/travis/api/v3/renderer/commit.rb
2015-04-30 17:08:52 +02:00

32 lines
797 B
Ruby

require 'travis/api/v3/renderer/model_renderer'
module Travis::API::V3
class Renderer::Commit < Renderer::ModelRenderer
representation(:minimal, :id, :sha, :ref, :message, :compare_url, :committed_at)
representation(:standard, *representations[:minimal], :repository, :branch, :committer, :author)
def sha
model.commit
end
def committer
user_data(model.committer_name, model.committer_email)
end
def author
user_data(model.author_name, model.author_email)
end
private
def user_data(name, email)
# query(:user).find_by_email(email) <= this triggers an N+1 query
{
#:@type => 'user'.freeze,
:name => name,
:avatar_url => Renderer::AvatarURL.avatar_url(email)
}
end
end
end