BigW Consortium Gitlab

Commit 8f7266cd by 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 ...@@ -50,8 +50,13 @@ module Gitlab
private private
def parse_event(event) 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['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
event['created_at'] = interval_in_words(event['created_at']) 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 end
def first_time_reference_commit(commits, event) def first_time_reference_commit(commits, event)
......
...@@ -21,9 +21,12 @@ module Gitlab ...@@ -21,9 +21,12 @@ module Gitlab
issue_metrics_table[:first_added_to_board_at]], issue_metrics_table[:first_added_to_board_at]],
projections: [issue_table[:title], projections: [issue_table[:title],
issue_table[:iid], issue_table[:iid],
issue_table[:id],
issue_table[:created_at], issue_table[:created_at],
user_table[:name], issue_table[:state],
user_table[:email]] user_table[:name].as('author_name'),
user_table[:username].as('author_username'),
user_table[:id].as('author_id')]
} }
end 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 ...@@ -30,12 +30,16 @@ describe Gitlab::CycleAnalytics::Events do
expect(subject.issue_events.first['created_at']).to end_with('ago') expect(subject.issue_events.first['created_at']).to end_with('ago')
end end
it "has the author's email" do it "has the author's URL" do
expect(subject.issue_events.first['email']).to eq(context.author.email) 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 end
it "has the author's name" do 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
end end
......
...@@ -51,7 +51,6 @@ describe 'cycle analytics events' do ...@@ -51,7 +51,6 @@ describe 'cycle analytics events' do
expect(json_response['events']).not_to be_empty expect(json_response['events']).not_to be_empty
expect(json_response['events'].first['pipeline']).not_to be_empty expect(json_response['events'].first['pipeline']).not_to be_empty
end end
it 'lists the review events in the right order' do 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