Commit 73e9ec63 authored by James Lopez's avatar James Lopez

serialize all the things!

parent 8743e59f
class AnalyticsCommitEntity < CommitEntity
include RequestAwareEntity
include EntityDateHelper
expose :short_id, as: :short_sha
expose :total_time do |commit|
distance_of_time_in_words(request.total_time.to_f)
end
unexpose :author_name
unexpose :author_email
unexpose :message
end
class AnalyticsCommitSerializer < BaseSerializer
entity AnalyticsCommitEntity
end
...@@ -7,55 +7,46 @@ module Gitlab ...@@ -7,55 +7,46 @@ module Gitlab
end end
def issue_events def issue_events
@fetcher.fetch(stage: :issue).map { |event| parse_event(event) } @fetcher.fetch(stage: :issue).map { |event| serialize_event(event) }
end end
def plan_events def plan_events
@fetcher.fetch(stage: :plan).each do |event| @fetcher.fetch(stage: :plan).map do |event|
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
commit = first_time_reference_commit(event.delete('commits'), event) commit = first_time_reference_commit(event.delete('commits'), event)
event['title'] = commit.title
event['url'] = Gitlab::LightUrlBuilder.build(entity: :commit, project: @project, id: commit.id) AnalyticsCommitSerializer.new(project: @project, total_time: event['total_time']).represent(commit).as_json
event['sha'] = commit.short_id
event['author_name'] = commit.author.name
event['author_profile_url'] = Gitlab::LightUrlBuilder.build(entity: :user, id: commit.author.username)
event['author_avatar_url'] = Gitlab::LightUrlBuilder.build(entity: :user_avatar, id: commit.author.id)
end end
end end
def code_events def code_events
@fetcher.fetch(stage: :code).map { |event| parse_event(event, entity: :merge_request) } @fetcher.fetch(stage: :code).map { |event| serialize_event(event, entity: :merge_request) }
end end
def test_events def test_events
@fetcher.fetch(stage: :test).map do |event| @fetcher.fetch(stage: :test).map { |event| serialize_build_event(event) }
parse_build_event(event)
end
end end
def review_events def review_events
@fetcher.fetch(stage: :review).map { |event| parse_event(event, entity: :merge_request) } @fetcher.fetch(stage: :review).map { |event| serialize_event(event, entity: :merge_request) }
end end
def staging_events def staging_events
@fetcher.fetch(stage: :staging).map do |event| @fetcher.fetch(stage: :staging).map { |event| serialize_build_event(event) }
parse_build_event(event)
end
end end
def production_events def production_events
@fetcher.fetch(stage: :production).map { |event| parse_event(event) } @fetcher.fetch(stage: :production).map { |event| serialize_event(event) }
end end
private private
def parse_event(event, entity: :issue) def serialize_event(event, entity: :issue)
event['author'] = User.find(event.delete('author_id')) event['author'] = User.find(event.delete('author_id'))
AnalyticsGenericSerializer.new(project: @project, entity: entity).represent(event).as_json AnalyticsGenericSerializer.new(project: @project, entity: entity).represent(event).as_json
end end
def parse_build_event(event) def serialize_build_event(event)
build = ::Ci::Build.find(event['id']) build = ::Ci::Build.find(event['id'])
AnalyticsBuildSerializer.new.represent(build).as_json AnalyticsBuildSerializer.new.represent(build).as_json
......
...@@ -52,7 +52,11 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -52,7 +52,11 @@ describe Gitlab::CycleAnalytics::Events do
end end
it 'has a sha short ID' do it 'has a sha short ID' do
expect(subject.plan_events.first[:sha]).not_to be_nil expect(subject.plan_events.first[:short_sha]).not_to be_nil
end
it 'has the URL' do
expect(subject.plan_events.first[:commit_url]).not_to be_nil
end end
it 'has the total time' do it 'has the total time' do
...@@ -68,7 +72,7 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -68,7 +72,7 @@ describe Gitlab::CycleAnalytics::Events do
end end
it "has the author's name" do it "has the author's name" do
expect(subject.plan_events.first[:author][:name]).to eq(context.author.name) expect(subject.plan_events.first[:author][:name]).not_to be_nil
end end
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