Commit 8f7266cd authored by James Lopez's avatar James Lopez

added missing fields to issue. Also, added a light url builder to add URLs...

added missing fields to issue. Also, added a light url builder to add URLs easily from arel. Updated specs.
parent 8bb4750e
......@@ -50,8 +50,13 @@ module Gitlab
private
def parse_event(event)
event['url'] = Gitlab::LightUrlBuilder.build(entity: :issue, project: @project, id: event['id'])
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
event['created_at'] = interval_in_words(event['created_at'])
event['author_profile_url'] = Gitlab::LightUrlBuilder.build(entity: :user, id: event['author_username'])
event['author_avatar_url'] = Gitlab::LightUrlBuilder.build(entity: :user_avatar_url, id: event['author_id'])
event.except('author_id', 'author_username')
end
def first_time_reference_commit(commits, event)
......
......@@ -21,9 +21,12 @@ module Gitlab
issue_metrics_table[:first_added_to_board_at]],
projections: [issue_table[:title],
issue_table[:iid],
issue_table[:id],
issue_table[:created_at],
user_table[:name],
user_table[:email]]
issue_table[:state],
user_table[:name].as('author_name'),
user_table[:username].as('author_username'),
user_table[:id].as('author_id')]
}
end
......
module Gitlab
class LightUrlBuilder
include Gitlab::Routing.url_helpers
include GitlabRoutingHelper
include ActionView::RecordIdentifier
def self.build(*args)
new(*args).url
end
def initialize(entity:, project: nil, id:, opts: {})
@entity = entity
@project = project
@id = id
@opts = opts
end
def url
case @entity
when :issue
issue_url
when :user
user_url(@id)
when :user_avatar_url
user_avatar_url
else
raise NotImplementedError.new("No URL builder defined for #{object.class}")
end
end
private
def issue_url
namespace_project_issue_url({
namespace_id: @project.namespace,
project_id: @project,
id: @id
}.merge!(@opts))
end
def user_avatar_url
User.find(@id).avatar_url
end
end
end
......@@ -30,12 +30,16 @@ describe Gitlab::CycleAnalytics::Events do
expect(subject.issue_events.first['created_at']).to end_with('ago')
end
it "has the author's email" do
expect(subject.issue_events.first['email']).to eq(context.author.email)
it "has the author's URL" do
expect(subject.issue_events.first['author_profile_url']).not_to be_nil
end
it "has the author's avatar URL" do
expect(subject.issue_events.first['author_avatar_url']).not_to be_nil
end
it "has the author's name" do
expect(subject.issue_events.first['name']).to eq(context.author.name)
expect(subject.issue_events.first['author_name']).to eq(context.author.name)
end
end
......
......@@ -51,7 +51,6 @@ describe 'cycle analytics events' do
expect(json_response['events']).not_to be_empty
expect(json_response['events'].first['pipeline']).not_to be_empty
end
it 'lists the review events in the right order' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment