Commit beeb6461 authored by James Lopez's avatar James Lopez

Refactored staging events, added missing fields and fixed specs

parent bd31f24c
......@@ -31,15 +31,7 @@ module Gitlab
def test_events
@fetcher.fetch(stage: :test).each do |event|
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
parse_build_event(event)
end
end
......@@ -49,8 +41,7 @@ module Gitlab
def staging_events
@fetcher.fetch(stage: :staging).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
parse_build_event(event)
end
end
......@@ -70,6 +61,19 @@ module Gitlab
event.except!('author_id', 'author_username')
end
def parse_build_event(event)
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
event['author_name'] = build.author.try(:name)
end
def first_time_reference_commit(commits, event)
st_commit = YAML.load(commits).detect do |commit|
commit['created_at'] == event['first_mentioned_in_commit_at']
......
......@@ -19,9 +19,6 @@ module Gitlab
base_query.join(user_table).on(issue_table[:author_id].eq(user_table[:id]))
end
alias_method :code_custom_query, :issue_custom_query
alias_method :production_custom_query, :issue_custom_query
def plan_custom_query(base_query)
base_query.join(mr_diff_table).on(mr_diff_table[:merge_request_id].eq(mr_table[:id]))
end
......@@ -33,6 +30,10 @@ module Gitlab
def test_custom_query(base_query)
base_query.join(build_table).on(mr_metrics_table[:ci_commit_id].eq(build_table[:commit_id]))
end
alias_method :code_custom_query, :issue_custom_query
alias_method :production_custom_query, :issue_custom_query
alias_method :staging_custom_query, :test_custom_query
end
end
end
......@@ -63,17 +63,22 @@ module Gitlab
def review
{ start_time_attrs: mr_table[:created_at],
end_time_attrs: mr_metrics_table[:merged_at],
projections: [mr_table[:title], mr_table[:iid],
mr_table[:created_at],
user_table[:name],
user_table[:email]]
projections: [mr_table[:title],
mr_table[:iid],
mr_table[:id],
mr_table[:created_at].as('opened_at'),
mr_table[:state],
user_table[:name].as('author_name'),
user_table[:username].as('author_username'),
user_table[:id].as('author_id')]
}
end
def staging
{ start_time_attrs: mr_metrics_table[:merged_at],
end_time_attrs: mr_metrics_table[:first_deployed_to_production_at],
projections: [mr_metrics_table[:ci_commit_id]]
projections: [build_table[:id]],
order: build_table[:created_at]
}
end
......
......@@ -171,16 +171,28 @@ describe Gitlab::CycleAnalytics::Events do
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
end
it 'has a state' do
expect(subject.review_events.first['state']).not_to be_nil
end
it 'has a created_at timestamp' do
expect(subject.review_events.first['created_at']).to end_with('ago')
expect(subject.review_events.first['opened_at']).not_to be_nil
end
it "has the author's email" do
expect(subject.review_events.first['email']).to eq(MergeRequest.first.author.email)
it "has the author's URL" do
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
end
it "has the author's name" do
expect(subject.review_events.first['name']).to eq(MergeRequest.first.author.name)
expect(subject.review_events.first['author_name']).to eq(context.author.name)
end
end
......@@ -194,6 +206,9 @@ describe Gitlab::CycleAnalytics::Events do
end
before do
create(:ci_build, pipeline: pipeline, status: :success, author: user)
create(:ci_build, pipeline: pipeline, status: :success, author: user)
pipeline.run!
pipeline.succeed!
......@@ -201,12 +216,45 @@ describe Gitlab::CycleAnalytics::Events do
deploy_master
end
it 'has the build info as a pipeline' do
expect(subject.staging_events.first['pipeline']).to eq(pipeline)
it 'has the name' do
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
end
it 'has the URL' do
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
end
it 'has the branch URL' do
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
end
it 'has the commit URL' do
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
end
it 'has the total time' do
expect(subject.staging_events.first['total_time']).to eq('less than a minute')
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
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