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.
This commit is contained in:
parent
11bad33a42
commit
eccb6a5e92
6 changed files with 70 additions and 6 deletions
|
@ -32,8 +32,15 @@ module Gitlab
|
|||
|
||||
def test_events
|
||||
@fetcher.fetch(stage: :test).each do |event|
|
||||
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
|
||||
event['pipeline'] = ::Ci::Pipeline.find_by_id(event['ci_commit_id']) # we may not have a pipeline
|
||||
build = ::Ci::Build.find(event['id'])
|
||||
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
|
||||
|
||||
|
|
|
@ -29,6 +29,10 @@ module Gitlab
|
|||
def review_custom_query(base_query)
|
||||
base_query.join(user_table).on(mr_table[:author_id].eq(user_table[:id]))
|
||||
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
|
||||
|
|
|
@ -79,6 +79,10 @@ module Gitlab
|
|||
def user_table
|
||||
User.arel_table
|
||||
end
|
||||
|
||||
def build_table
|
||||
::CommitStatus.arel_table
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -55,7 +55,7 @@ module Gitlab
|
|||
def test
|
||||
{ start_time_attrs: mr_metrics_table[:latest_build_started_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]
|
||||
}
|
||||
end
|
||||
|
|
|
@ -16,6 +16,7 @@ module Gitlab
|
|||
end
|
||||
|
||||
def url
|
||||
#TODO refactor this
|
||||
case @entity
|
||||
when :issue
|
||||
issue_url
|
||||
|
@ -27,6 +28,10 @@ module Gitlab
|
|||
commit_url
|
||||
when :merge_request
|
||||
mr_url
|
||||
when :build_url
|
||||
namespace_project_build_url(@project.namespace, @project, @id)
|
||||
when :branch_url
|
||||
branch_url
|
||||
else
|
||||
raise NotImplementedError.new("No URL builder defined for #{object.class}")
|
||||
end
|
||||
|
@ -61,5 +66,18 @@ module Gitlab
|
|||
id: @id
|
||||
}.merge!(@opts))
|
||||
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
|
||||
|
|
|
@ -112,16 +112,47 @@ describe Gitlab::CycleAnalytics::Events do
|
|||
end
|
||||
|
||||
before do
|
||||
create(:ci_build, pipeline: pipeline, status: :success)
|
||||
create(:ci_build, pipeline: pipeline, status: :success)
|
||||
|
||||
pipeline.run!
|
||||
pipeline.succeed!
|
||||
end
|
||||
|
||||
it 'has the build info as a pipeline' do
|
||||
expect(subject.test_events.first['pipeline']).to eq(pipeline)
|
||||
it 'has the name' do
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue