summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-11-15 11:36:39 +0100
committerJames Lopez <james@jameslopez.es>2016-11-17 08:22:58 +0100
commit8743e59f78cd8f8701460796dcc06854281f3f73 (patch)
treed539fff96a88a8ea33f1a9ab62faffc678dd22d8
parentf5600997512f1068cdc36ad7d086e7447dbc6d9d (diff)
downloadgitlab-ce-8743e59f78cd8f8701460796dcc06854281f3f73.tar.gz
get all stages to use serlalizers - apart from plan - WIP
-rw-r--r--app/serializers/analytics_build_entity.rb11
-rw-r--r--app/serializers/analytics_generic_entity.rb8
-rw-r--r--app/serializers/entity_date_helper.rb7
-rw-r--r--lib/gitlab/cycle_analytics/events.rb4
-rw-r--r--lib/gitlab/cycle_analytics/query_config.rb2
-rw-r--r--spec/lib/gitlab/cycle_analytics/events_spec.rb42
6 files changed, 46 insertions, 28 deletions
diff --git a/app/serializers/analytics_build_entity.rb b/app/serializers/analytics_build_entity.rb
index a07f0beccd4..eb1eef3424a 100644
--- a/app/serializers/analytics_build_entity.rb
+++ b/app/serializers/analytics_build_entity.rb
@@ -1,14 +1,21 @@
class AnalyticsBuildEntity < Grape::Entity
include RequestAwareEntity
+ include EntityDateHelper
expose :name
expose :id
expose :ref, as: :branch
expose :short_sha
- expose :started_at, as: :date
- expose :duration, as: :total_time
expose :author, using: UserEntity
+ expose :started_at, as: :date do |build|
+ interval_in_words(build[:started_at])
+ end
+
+ expose :duration, as: :total_time do |build|
+ distance_of_time_in_words(build[:duration].to_f)
+ end
+
expose :branch do
expose :ref, as: :name
diff --git a/app/serializers/analytics_generic_entity.rb b/app/serializers/analytics_generic_entity.rb
index 8c8a40cd90b..d7abe3f5f50 100644
--- a/app/serializers/analytics_generic_entity.rb
+++ b/app/serializers/analytics_generic_entity.rb
@@ -1,10 +1,10 @@
class AnalyticsGenericEntity < Grape::Entity
include RequestAwareEntity
- include ActionView::Helpers::DateHelper
-
+ include EntityDateHelper
expose :title
expose :iid
+ expose :state, if: ->(_instance, options) { options[:request].entity == :merge_request }
expose :author, using: UserEntity
expose :total_time do |object|
@@ -24,8 +24,4 @@ class AnalyticsGenericEntity < Grape::Entity
def url_to(route, id)
public_send("#{route}_url", request.project.namespace, request.project, id)
end
-
- def interval_in_words(diff)
- "#{distance_of_time_in_words(diff.to_f)} ago"
- end
end
diff --git a/app/serializers/entity_date_helper.rb b/app/serializers/entity_date_helper.rb
new file mode 100644
index 00000000000..0772f652f0c
--- /dev/null
+++ b/app/serializers/entity_date_helper.rb
@@ -0,0 +1,7 @@
+module EntityDateHelper
+ include ActionView::Helpers::DateHelper
+
+ def interval_in_words(diff)
+ "#{distance_of_time_in_words(diff.to_f)} ago"
+ end
+end \ No newline at end of file
diff --git a/lib/gitlab/cycle_analytics/events.rb b/lib/gitlab/cycle_analytics/events.rb
index 3b397bab178..69688a2a0ca 100644
--- a/lib/gitlab/cycle_analytics/events.rb
+++ b/lib/gitlab/cycle_analytics/events.rb
@@ -34,7 +34,7 @@ module Gitlab
end
def review_events
- @fetcher.fetch(stage: :review).map { |event| parse_event(event) }
+ @fetcher.fetch(stage: :review).map { |event| parse_event(event, entity: :merge_request) }
end
def staging_events
@@ -44,7 +44,7 @@ module Gitlab
end
def production_events
- @fetcher.fetch(stage: :production).each { |event| parse_event(event) }
+ @fetcher.fetch(stage: :production).map { |event| parse_event(event) }
end
private
diff --git a/lib/gitlab/cycle_analytics/query_config.rb b/lib/gitlab/cycle_analytics/query_config.rb
index d077a3e1a14..a18c263ba53 100644
--- a/lib/gitlab/cycle_analytics/query_config.rb
+++ b/lib/gitlab/cycle_analytics/query_config.rb
@@ -67,7 +67,7 @@ module Gitlab
projections: [mr_table[:title],
mr_table[:iid],
mr_table[:id],
- mr_table[:created_at].as('opened_at'),
+ mr_table[:created_at],
mr_table[:state],
mr_table[:author_id]]
}
diff --git a/spec/lib/gitlab/cycle_analytics/events_spec.rb b/spec/lib/gitlab/cycle_analytics/events_spec.rb
index 073469a2b80..55ab28e2af8 100644
--- a/spec/lib/gitlab/cycle_analytics/events_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/events_spec.rb
@@ -60,15 +60,15 @@ describe Gitlab::CycleAnalytics::Events do
end
it "has the author's URL" do
- expect(subject.plan_events.first[:author_profile_url]).not_to be_nil
+ expect(subject.plan_events.first[:author][:web_url]).not_to be_nil
end
it "has the author's avatar URL" do
- expect(subject.plan_events.first[:author_avatar_url]).not_to be_nil
+ expect(subject.plan_events.first[:author][:avatar_url]).not_to be_nil
end
it "has the author's name" do
- expect(subject.plan_events.first[:author_name]).not_to be_nil
+ expect(subject.plan_events.first[:author][:name]).to eq(context.author.name)
end
end
@@ -94,15 +94,15 @@ describe Gitlab::CycleAnalytics::Events do
end
it "has the author's URL" do
- expect(subject.code_events.first[:author_profile_url]).not_to be_nil
+ expect(subject.code_events.first[:author][:web_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
+ 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[:author_name]).to eq(context.author.name)
+ expect(subject.code_events.first[:author][:name]).to eq(MergeRequest.first.author.name)
end
end
@@ -184,19 +184,19 @@ describe Gitlab::CycleAnalytics::Events do
end
it 'has a created_at timestamp' do
- expect(subject.review_events.first[:opened_at]).not_to be_nil
+ expect(subject.review_events.first[:created_at]).not_to be_nil
end
it "has the author's URL" do
- expect(subject.review_events.first[:author_profile_url]).not_to be_nil
+ expect(subject.review_events.first[:author][:web_url]).not_to be_nil
end
it "has the author's avatar URL" do
- expect(subject.review_events.first[:author_avatar_url]).not_to be_nil
+ expect(subject.review_events.first[:author][:avatar_url]).not_to be_nil
end
it "has the author's name" do
- expect(subject.review_events.first[:author_name]).to eq(MergeRequest.first.author.name)
+ expect(subject.review_events.first[:author][:name]).to eq(MergeRequest.first.author.name)
end
end
@@ -237,11 +237,11 @@ describe Gitlab::CycleAnalytics::Events do
end
it 'has the branch URL' do
- expect(subject.staging_events.first[:branch_url]).not_to be_nil
+ expect(subject.staging_events.first[:branch][:url]).not_to be_nil
end
it 'has the short SHA' do
- expect(subject.staging_events.first[:sha]).not_to be_nil
+ expect(subject.staging_events.first[:short_sha]).not_to be_nil
end
it 'has the commit URL' do
@@ -256,8 +256,16 @@ describe Gitlab::CycleAnalytics::Events do
expect(subject.staging_events.first[:total_time]).not_to be_nil
end
- it 'has the author name' do
- expect(subject.staging_events.first[:author_name]).not_to be_nil
+ it "has the author's URL" do
+ expect(subject.staging_events.first[:author][:web_url]).not_to be_nil
+ end
+
+ it "has the author's avatar URL" do
+ expect(subject.staging_events.first[:author][:avatar_url]).not_to be_nil
+ end
+
+ it "has the author's name" do
+ expect(subject.staging_events.first[:author][:name]).to eq(MergeRequest.first.author.name)
end
end
@@ -290,15 +298,15 @@ describe Gitlab::CycleAnalytics::Events do
end
it "has the author's URL" do
- expect(subject.production_events.first[:author_profile_url]).not_to be_nil
+ expect(subject.production_events.first[:author][:web_url]).not_to be_nil
end
it "has the author's avatar URL" do
- expect(subject.production_events.first[:author_avatar_url]).not_to be_nil
+ expect(subject.production_events.first[:author][:avatar_url]).not_to be_nil
end
it "has the author's name" do
- expect(subject.production_events.first[:author_name]).to eq(context.author.name)
+ expect(subject.production_events.first[:author][:name]).to eq(context.author.name)
end
end