summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-11-03 13:06:14 +0100
committerJames Lopez <james@jameslopez.es>2016-11-17 08:22:56 +0100
commit8f7266cd4b6a3e65224b55c2b91509f5ac88d837 (patch)
treeda1da700b5383342c4e26b9dadc02a47a2c8ad01
parent8bb4750eb3987999b0ee617c29224e468e9147b3 (diff)
downloadgitlab-ce-8f7266cd4b6a3e65224b55c2b91509f5ac88d837.tar.gz
added missing fields to issue. Also, added a light url builder to add URLs easily from arel. Updated specs.
-rw-r--r--lib/gitlab/cycle_analytics/events.rb5
-rw-r--r--lib/gitlab/cycle_analytics/query_config.rb7
-rw-r--r--lib/gitlab/light_url_builder.rb45
-rw-r--r--spec/lib/gitlab/cycle_analytics/events_spec.rb10
-rw-r--r--spec/requests/projects/cycle_analytics_events_spec.rb1
5 files changed, 62 insertions, 6 deletions
diff --git a/lib/gitlab/cycle_analytics/events.rb b/lib/gitlab/cycle_analytics/events.rb
index 0ec5aeb03c7..66b30250c0f 100644
--- a/lib/gitlab/cycle_analytics/events.rb
+++ b/lib/gitlab/cycle_analytics/events.rb
@@ -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)
diff --git a/lib/gitlab/cycle_analytics/query_config.rb b/lib/gitlab/cycle_analytics/query_config.rb
index 3852ed7a2ab..ae3dd43a81b 100644
--- a/lib/gitlab/cycle_analytics/query_config.rb
+++ b/lib/gitlab/cycle_analytics/query_config.rb
@@ -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
diff --git a/lib/gitlab/light_url_builder.rb b/lib/gitlab/light_url_builder.rb
new file mode 100644
index 00000000000..9b5d28e731f
--- /dev/null
+++ b/lib/gitlab/light_url_builder.rb
@@ -0,0 +1,45 @@
+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
diff --git a/spec/lib/gitlab/cycle_analytics/events_spec.rb b/spec/lib/gitlab/cycle_analytics/events_spec.rb
index 7d544dbdb19..e4535f467ec 100644
--- a/spec/lib/gitlab/cycle_analytics/events_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/events_spec.rb
@@ -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
diff --git a/spec/requests/projects/cycle_analytics_events_spec.rb b/spec/requests/projects/cycle_analytics_events_spec.rb
index 3ee8795ac4c..9884df3f110 100644
--- a/spec/requests/projects/cycle_analytics_events_spec.rb
+++ b/spec/requests/projects/cycle_analytics_events_spec.rb
@@ -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