Commit 3b179bc3 authored by James Lopez's avatar James Lopez

WIP - refactored events to use build serializer, related spec passing

parent 81d0146c
...@@ -2,17 +2,23 @@ class AnalyticsBuildEntity < Grape::Entity ...@@ -2,17 +2,23 @@ class AnalyticsBuildEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
expose :name expose :name
expose :id
expose :ref, as: :branch expose :ref, as: :branch
expose :short_sha expose :short_sha
expose :started_at, as: :date expose :started_at, as: :date
expose :duration, as: :total_time expose :duration, as: :total_time
expose :author, using: UserEntity
expose :branch do
expose :ref, as: :name
expose :url do |build| expose :url do |build|
url_to(:namespace_project_build, build) url_to(:namespace_project_tree, build, build.ref)
end
end end
expose :branch_url do |build| expose :url do |build|
url_to(:namespace_project_tree, build, build.ref) url_to(:namespace_project_build, build)
end end
expose :commit_url do |build| expose :commit_url do |build|
......
...@@ -30,7 +30,7 @@ module Gitlab ...@@ -30,7 +30,7 @@ module Gitlab
end end
def test_events def test_events
@fetcher.fetch(stage: :test).each do |event| @fetcher.fetch(stage: :test).map do |event|
parse_build_event(event) parse_build_event(event)
end end
end end
...@@ -40,7 +40,7 @@ module Gitlab ...@@ -40,7 +40,7 @@ module Gitlab
end end
def staging_events def staging_events
@fetcher.fetch(stage: :staging).each do |event| @fetcher.fetch(stage: :staging).map do |event|
parse_build_event(event) parse_build_event(event)
end end
end end
...@@ -64,7 +64,7 @@ module Gitlab ...@@ -64,7 +64,7 @@ module Gitlab
def parse_build_event(event) def parse_build_event(event)
build = ::Ci::Build.find(event['id']) build = ::Ci::Build.find(event['id'])
#event['author_name'] = build.author.try(:name) AnalyticsBuildSerializer.new(project: @project).represent(build).as_json
end end
def first_time_reference_commit(commits, event) def first_time_reference_commit(commits, event)
......
...@@ -14,61 +14,61 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -14,61 +14,61 @@ describe Gitlab::CycleAnalytics::Events do
describe '#issue_events' do describe '#issue_events' do
it 'has the total time' do it 'has the total time' do
expect(subject.issue_events.first['total_time']).to eq('2 days') expect(subject.issue_events.first[:total_time]).to eq('2 days')
end end
it 'has a title' do it 'has a title' do
expect(subject.issue_events.first['title']).to eq(context.title) expect(subject.issue_events.first[:title]).to eq(context.title)
end end
it 'has the URL' do it 'has the URL' do
expect(subject.issue_events.first['url']).not_to be_nil expect(subject.issue_events.first[:url]).not_to be_nil
end end
it 'has an iid' do it 'has an iid' do
expect(subject.issue_events.first['iid']).to eq(context.iid.to_s) expect(subject.issue_events.first[:iid]).to eq(context.iid.to_s)
end end
it 'has a created_at timestamp' do it 'has a created_at timestamp' 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 URL" do it "has the author's URL" do
expect(subject.issue_events.first['author_profile_url']).not_to be_nil expect(subject.issue_events.first[:author_profile_url]).not_to be_nil
end end
it "has the author's avatar URL" do it "has the author's avatar URL" do
expect(subject.issue_events.first['author_avatar_url']).not_to be_nil 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['author_name']).to eq(context.author.name) expect(subject.issue_events.first[:author_name]).to eq(context.author.name)
end end
end end
describe '#plan_events' do describe '#plan_events' do
it 'has a title' do it 'has a title' do
expect(subject.plan_events.first['title']).not_to be_nil expect(subject.plan_events.first[:title]).not_to be_nil
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[:sha]).not_to be_nil
end end
it 'has the total time' do it 'has the total time' do
expect(subject.plan_events.first['total_time']).to eq('less than a minute') expect(subject.plan_events.first[:total_time]).to eq('less than a minute')
end end
it "has the author's URL" do 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_profile_url]).not_to be_nil
end end
it "has the author's avatar URL" do 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 end
it "has the author's name" do 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]).not_to be_nil
end end
end end
...@@ -78,31 +78,31 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -78,31 +78,31 @@ describe Gitlab::CycleAnalytics::Events do
end end
it 'has the total time' do it 'has the total time' do
expect(subject.code_events.first['total_time']).to eq('less than a minute') expect(subject.code_events.first[:total_time]).to eq('less than a minute')
end end
it 'has a title' do it 'has a title' do
expect(subject.code_events.first['title']).to eq('Awesome merge_request') expect(subject.code_events.first[:title]).to eq('Awesome merge_request')
end end
it 'has an iid' do it 'has an iid' do
expect(subject.code_events.first['iid']).to eq(context.iid.to_s) expect(subject.code_events.first[:iid]).to eq(context.iid.to_s)
end end
it 'has a created_at timestamp' do it 'has a created_at timestamp' do
expect(subject.code_events.first['created_at']).to end_with('ago') expect(subject.code_events.first[:created_at]).to end_with('ago')
end end
it "has the author's URL" do 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_profile_url]).not_to be_nil
end end
it "has the author's avatar URL" do 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 end
it "has the author's name" do 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(context.author.name)
end end
end end
...@@ -116,47 +116,47 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -116,47 +116,47 @@ describe Gitlab::CycleAnalytics::Events do
end end
before do before do
create(:ci_build, pipeline: pipeline, status: :success) create(:ci_build, pipeline: pipeline, status: :success, author: user)
create(:ci_build, pipeline: pipeline, status: :success) create(:ci_build, pipeline: pipeline, status: :success, author: user)
pipeline.run! pipeline.run!
pipeline.succeed! pipeline.succeed!
end end
it 'has the name' do it 'has the name' do
expect(subject.test_events.first['name']).not_to be_nil expect(subject.test_events.first[:name]).not_to be_nil
end end
it 'has the ID' do it 'has the ID' do
expect(subject.test_events.first['id']).not_to be_nil expect(subject.test_events.first[:id]).not_to be_nil
end end
it 'has the URL' do it 'has the URL' do
expect(subject.test_events.first['url']).not_to be_nil expect(subject.test_events.first[:url]).not_to be_nil
end end
it 'has the branch name' do it 'has the branch name' do
expect(subject.test_events.first['branch']).not_to be_nil expect(subject.test_events.first[:branch]).not_to be_nil
end end
it 'has the branch URL' do it 'has the branch URL' do
expect(subject.test_events.first['branch_url']).not_to be_nil expect(subject.test_events.first[:branch][:url]).not_to be_nil
end end
it 'has the short SHA' do it 'has the short SHA' do
expect(subject.test_events.first['sha']).not_to be_nil expect(subject.test_events.first[:short_sha]).not_to be_nil
end end
it 'has the commit URL' do it 'has the commit URL' do
expect(subject.test_events.first['commit_url']).not_to be_nil expect(subject.test_events.first[:commit_url]).not_to be_nil
end end
it 'has the date' do it 'has the date' do
expect(subject.test_events.first['date']).not_to be_nil expect(subject.test_events.first[:date]).not_to be_nil
end end
it 'has the total time' do it 'has the total time' do
expect(subject.test_events.first['total_time']).not_to be_nil expect(subject.test_events.first[:total_time]).not_to be_nil
end end
end end
...@@ -164,39 +164,39 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -164,39 +164,39 @@ describe Gitlab::CycleAnalytics::Events do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
it 'has the total time' do it 'has the total time' do
expect(subject.review_events.first['total_time']).to eq('less than a minute') expect(subject.review_events.first[:total_time]).to eq('less than a minute')
end end
it 'has a title' do it 'has a title' do
expect(subject.review_events.first['title']).to eq('Awesome merge_request') expect(subject.review_events.first[:title]).to eq('Awesome merge_request')
end end
it 'has an iid' do it 'has an iid' do
expect(subject.review_events.first['iid']).to eq(context.iid.to_s) expect(subject.review_events.first[:iid]).to eq(context.iid.to_s)
end end
it 'has the URL' do it 'has the URL' do
expect(subject.review_events.first['url']).not_to be_nil expect(subject.review_events.first[:url]).not_to be_nil
end end
it 'has a state' do it 'has a state' do
expect(subject.review_events.first['state']).not_to be_nil expect(subject.review_events.first[:state]).not_to be_nil
end end
it 'has a created_at timestamp' do it 'has a created_at timestamp' do
expect(subject.review_events.first['opened_at']).not_to be_nil expect(subject.review_events.first[:opened_at]).not_to be_nil
end end
it "has the author's URL" do 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_profile_url]).not_to be_nil
end end
it "has the author's avatar URL" do 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 end
it "has the author's name" do 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
end end
...@@ -221,43 +221,43 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -221,43 +221,43 @@ describe Gitlab::CycleAnalytics::Events do
end end
it 'has the name' do it 'has the name' do
expect(subject.staging_events.first['name']).not_to be_nil expect(subject.staging_events.first[:name]).not_to be_nil
end end
it 'has the ID' do it 'has the ID' do
expect(subject.staging_events.first['id']).not_to be_nil expect(subject.staging_events.first[:id]).not_to be_nil
end end
it 'has the URL' do it 'has the URL' do
expect(subject.staging_events.first['url']).not_to be_nil expect(subject.staging_events.first[:url]).not_to be_nil
end end
it 'has the branch name' do it 'has the branch name' do
expect(subject.staging_events.first['branch']).not_to be_nil expect(subject.staging_events.first[:branch]).not_to be_nil
end end
it 'has the branch URL' do 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 end
it 'has the short SHA' do it 'has the short SHA' do
expect(subject.staging_events.first['sha']).not_to be_nil expect(subject.staging_events.first[:sha]).not_to be_nil
end end
it 'has the commit URL' do it 'has the commit URL' do
expect(subject.staging_events.first['commit_url']).not_to be_nil expect(subject.staging_events.first[:commit_url]).not_to be_nil
end end
it 'has the date' do it 'has the date' do
expect(subject.staging_events.first['date']).not_to be_nil expect(subject.staging_events.first[:date]).not_to be_nil
end end
it 'has the total time' do it 'has the total time' do
expect(subject.staging_events.first['total_time']).not_to be_nil expect(subject.staging_events.first[:total_time]).not_to be_nil
end end
it 'has the author name' do it 'has the author name' do
expect(subject.staging_events.first['author_name']).not_to be_nil expect(subject.staging_events.first[:author_name]).not_to be_nil
end end
end end
...@@ -270,35 +270,35 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -270,35 +270,35 @@ describe Gitlab::CycleAnalytics::Events do
end end
it 'has the total time' do it 'has the total time' do
expect(subject.production_events.first['total_time']).to eq('2 days') expect(subject.production_events.first[:total_time]).to eq('2 days')
end end
it 'has a title' do it 'has a title' do
expect(subject.production_events.first['title']).to eq(context.title) expect(subject.production_events.first[:title]).to eq(context.title)
end end
it 'has the URL' do it 'has the URL' do
expect(subject.production_events.first['url']).not_to be_nil expect(subject.production_events.first[:url]).not_to be_nil
end end
it 'has an iid' do it 'has an iid' do
expect(subject.production_events.first['iid']).to eq(context.iid.to_s) expect(subject.production_events.first[:iid]).to eq(context.iid.to_s)
end end
it 'has a created_at timestamp' do it 'has a created_at timestamp' do
expect(subject.production_events.first['created_at']).to end_with('ago') expect(subject.production_events.first[:created_at]).to end_with('ago')
end end
it "has the author's URL" do 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_profile_url]).not_to be_nil
end end
it "has the author's avatar URL" do 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 end
it "has the author's name" do 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
end end
......
...@@ -6,14 +6,19 @@ describe AnalyticsBuildEntity do ...@@ -6,14 +6,19 @@ describe AnalyticsBuildEntity do
end end
context 'when build is a regular job' do context 'when build is a regular job' do
let(:build) { create(:ci_build) } let(:user) { create(:user) }
let(:build) { create(:ci_build, author: user) }
subject { entity.as_json } subject { entity.as_json }
it 'contains url to build page and retry action' do it 'contains URLs' do
expect(subject).to include(:url, :branch_url, :commit_url) expect(subject).to include(:url, :branch_url, :commit_url)
end end
it 'contains the author' do
expect(subject).to include(:author)
end
it 'does not contain sensitive information' do it 'does not contain sensitive information' do
expect(subject).not_to include(/token/) expect(subject).not_to include(/token/)
expect(subject).not_to include(/variables/) expect(subject).not_to include(/variables/)
......
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