Commit eccb6a5e authored by James Lopez's avatar James Lopez

Refactored test events

Now test events return the builds instead a list of pipelines to avoid calling pipeline.builds per each and get the info. Also, added missing fields/data, URLs, and fixed specs in events spec.
parent 11bad33a
...@@ -32,8 +32,15 @@ module Gitlab ...@@ -32,8 +32,15 @@ module Gitlab
def test_events def test_events
@fetcher.fetch(stage: :test).each do |event| @fetcher.fetch(stage: :test).each do |event|
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f) build = ::Ci::Build.find(event['id'])
event['pipeline'] = ::Ci::Pipeline.find_by_id(event['ci_commit_id']) # we may not have a pipeline event['name'] = build.name
event['url'] = Gitlab::LightUrlBuilder.build(entity: :build_url, project: @project, id: build.id)
event['branch'] = build.ref
event['branch_url'] = Gitlab::LightUrlBuilder.build(entity: :branch_url, project: @project, id: build.ref)
event['sha'] = build.short_sha
event['commit_url'] = Gitlab::LightUrlBuilder.build(entity: :commit_url, project: @project, id: build.sha)
event['date'] = build.started_at
event['total_time'] = build.duration
end end
end end
......
...@@ -29,6 +29,10 @@ module Gitlab ...@@ -29,6 +29,10 @@ module Gitlab
def review_custom_query(base_query) def review_custom_query(base_query)
base_query.join(user_table).on(mr_table[:author_id].eq(user_table[:id])) base_query.join(user_table).on(mr_table[:author_id].eq(user_table[:id]))
end end
def test_custom_query(base_query)
base_query.join(build_table).on(mr_metrics_table[:ci_commit_id].eq(build_table[:commit_id]))
end
end end
end end
end end
...@@ -79,6 +79,10 @@ module Gitlab ...@@ -79,6 +79,10 @@ module Gitlab
def user_table def user_table
User.arel_table User.arel_table
end end
def build_table
::CommitStatus.arel_table
end
end end
end end
end end
...@@ -55,7 +55,7 @@ module Gitlab ...@@ -55,7 +55,7 @@ module Gitlab
def test def test
{ start_time_attrs: mr_metrics_table[:latest_build_started_at], { start_time_attrs: mr_metrics_table[:latest_build_started_at],
end_time_attrs: mr_metrics_table[:latest_build_finished_at], end_time_attrs: mr_metrics_table[:latest_build_finished_at],
projections: [mr_metrics_table[:ci_commit_id]], projections: [build_table[:id]],
order: mr_table[:created_at] order: mr_table[:created_at]
} }
end end
......
...@@ -16,6 +16,7 @@ module Gitlab ...@@ -16,6 +16,7 @@ module Gitlab
end end
def url def url
#TODO refactor this
case @entity case @entity
when :issue when :issue
issue_url issue_url
...@@ -27,6 +28,10 @@ module Gitlab ...@@ -27,6 +28,10 @@ module Gitlab
commit_url commit_url
when :merge_request when :merge_request
mr_url mr_url
when :build_url
namespace_project_build_url(@project.namespace, @project, @id)
when :branch_url
branch_url
else else
raise NotImplementedError.new("No URL builder defined for #{object.class}") raise NotImplementedError.new("No URL builder defined for #{object.class}")
end end
...@@ -61,5 +66,18 @@ module Gitlab ...@@ -61,5 +66,18 @@ module Gitlab
id: @id id: @id
}.merge!(@opts)) }.merge!(@opts))
end end
def pipeline_url
namespace_project_build_url({
namespace_id: @project.namespace,
project_id: @project,
id: @id
}.merge!(@opts))
end
def branch_url
"#{project_url(@project)}/commits/#{@id}"
end
end end
end end
...@@ -112,16 +112,47 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -112,16 +112,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)
pipeline.run! pipeline.run!
pipeline.succeed! pipeline.succeed!
end end
it 'has the build info as a pipeline' do it 'has the name' do
expect(subject.test_events.first['pipeline']).to eq(pipeline) 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
end
it 'has the URL' do
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
end
it 'has the branch URL' do
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
end
it 'has the commit URL' do
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
end end
it 'has the total time' do it 'has the total time' do
expect(subject.test_events.first['total_time']).to eq('less than a minute') expect(subject.test_events.first['total_time']).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