Commit 11bad33a authored by James Lopez's avatar James Lopez

added missing fields to code events and updated spec

parent 1b5b2eac
......@@ -27,7 +27,7 @@ module Gitlab
end
def code_events
@fetcher.fetch(stage: :code).each { |event| parse_event(event) }
@fetcher.fetch(stage: :code).each { |event| parse_event(event, entity: :merge_request) }
end
def test_events
......@@ -54,8 +54,8 @@ module Gitlab
private
def parse_event(event)
event['url'] = Gitlab::LightUrlBuilder.build(entity: :issue, project: @project, id: event['id'])
def parse_event(event, entity: :issue)
event['url'] = Gitlab::LightUrlBuilder.build(entity: entity, 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'])
......
......@@ -23,7 +23,6 @@ module Gitlab
issue_table[:iid],
issue_table[:id],
issue_table[:created_at],
issue_table[:state],
user_table[:name].as('author_name'),
user_table[:username].as('author_username'),
user_table[:id].as('author_id')]
......@@ -41,10 +40,14 @@ module Gitlab
def code
{ start_time_attrs: issue_metrics_table[:first_mentioned_in_commit_at],
end_time_attrs: mr_table[:created_at],
projections: [mr_table[:title], mr_table[:iid],
projections: [mr_table[:title],
mr_table[:iid],
mr_table[:id],
mr_table[:created_at],
user_table[:name],
user_table[:email]],
mr_table[:state],
user_table[:name].as('author_name'),
user_table[:username].as('author_username'),
user_table[:id].as('author_id')],
order: mr_table[:created_at]
}
end
......
......@@ -25,6 +25,8 @@ module Gitlab
user_avatar_url
when :commit_url
commit_url
when :merge_request
mr_url
else
raise NotImplementedError.new("No URL builder defined for #{object.class}")
end
......@@ -51,5 +53,13 @@ module Gitlab
id: @id
}.merge!(@opts))
end
def mr_url
namespace_project_merge_request_url({
namespace_id: @project.namespace,
project_id: @project,
id: @id
}.merge!(@opts))
end
end
end
......@@ -89,12 +89,16 @@ describe Gitlab::CycleAnalytics::Events do
expect(subject.code_events.first['created_at']).to end_with('ago')
end
it "has the author's email" do
expect(subject.code_events.first['email']).to eq(context.author.email)
it "has the author's URL" do
expect(subject.code_events.first['author_profile_url']).not_to be_nil
end
it "has the author's avatar URL" do
expect(subject.code_events.first['author_avatar_url']).not_to be_nil
end
it "has the author's name" do
expect(subject.code_events.first['name']).to eq(context.author.name)
expect(subject.code_events.first['author_name']).to eq(context.author.name)
end
end
......
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