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

This commit is contained in:
James Lopez 2016-11-14 14:53:06 +01:00
parent 81d0146c4c
commit 3b179bc37b
4 changed files with 79 additions and 68 deletions

View File

@ -2,19 +2,25 @@ class AnalyticsBuildEntity < Grape::Entity
include RequestAwareEntity
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 :branch do
expose :ref, as: :name
expose :url do |build|
url_to(:namespace_project_tree, build, build.ref)
end
end
expose :url do |build|
url_to(:namespace_project_build, build)
end
expose :branch_url do |build|
url_to(:namespace_project_tree, build, build.ref)
end
expose :commit_url do |build|
url_to(:namespace_project_commit, build, build.sha)
end

View File

@ -30,7 +30,7 @@ module Gitlab
end
def test_events
@fetcher.fetch(stage: :test).each do |event|
@fetcher.fetch(stage: :test).map do |event|
parse_build_event(event)
end
end
@ -40,7 +40,7 @@ module Gitlab
end
def staging_events
@fetcher.fetch(stage: :staging).each do |event|
@fetcher.fetch(stage: :staging).map do |event|
parse_build_event(event)
end
end
@ -64,7 +64,7 @@ module Gitlab
def parse_build_event(event)
build = ::Ci::Build.find(event['id'])
#event['author_name'] = build.author.try(:name)
AnalyticsBuildSerializer.new(project: @project).represent(build).as_json
end
def first_time_reference_commit(commits, event)

View File

@ -14,61 +14,61 @@ describe Gitlab::CycleAnalytics::Events do
describe '#issue_events' 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
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
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
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
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
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
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
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
describe '#plan_events' 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
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
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
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
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]).not_to be_nil
end
end
@ -78,31 +78,31 @@ describe Gitlab::CycleAnalytics::Events do
end
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
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
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
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
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
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(context.author.name)
end
end
@ -116,47 +116,47 @@ describe Gitlab::CycleAnalytics::Events do
end
before do
create(:ci_build, pipeline: pipeline, status: :success)
create(:ci_build, pipeline: pipeline, status: :success)
create(:ci_build, pipeline: pipeline, status: :success, author: user)
create(:ci_build, pipeline: pipeline, status: :success, author: user)
pipeline.run!
pipeline.succeed!
end
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
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
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
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
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
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
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
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
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
@ -164,39 +164,39 @@ describe Gitlab::CycleAnalytics::Events do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
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
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
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
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
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
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
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
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
@ -221,43 +221,43 @@ describe Gitlab::CycleAnalytics::Events do
end
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
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
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
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
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[:sha]).not_to be_nil
end
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
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
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
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
@ -270,35 +270,35 @@ describe Gitlab::CycleAnalytics::Events do
end
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
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
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
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
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
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
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

View File

@ -6,14 +6,19 @@ describe AnalyticsBuildEntity do
end
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 }
it 'contains url to build page and retry action' do
it 'contains URLs' do
expect(subject).to include(:url, :branch_url, :commit_url)
end
it 'contains the author' do
expect(subject).to include(:author)
end
it 'does not contain sensitive information' do
expect(subject).not_to include(/token/)
expect(subject).not_to include(/variables/)