diff options
author | James Lopez <james@jameslopez.es> | 2016-11-04 15:59:27 +0100 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-11-17 08:22:57 +0100 |
commit | beeb64610e6a1907d6675b535659a519db129453 (patch) | |
tree | 18e2ba374e27cd66bc84b718d8ebc6a2349f351b | |
parent | bd31f24c548878597322b34965789c88ff8d2dde (diff) | |
download | gitlab-ce-beeb64610e6a1907d6675b535659a519db129453.tar.gz |
Refactored staging events, added missing fields and fixed specs
-rw-r--r-- | lib/gitlab/cycle_analytics/events.rb | 26 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/events_fetcher.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/query_config.rb | 15 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/events_spec.rb | 62 |
4 files changed, 84 insertions, 26 deletions
diff --git a/lib/gitlab/cycle_analytics/events.rb b/lib/gitlab/cycle_analytics/events.rb index c86b242857e..1a78bea3e18 100644 --- a/lib/gitlab/cycle_analytics/events.rb +++ b/lib/gitlab/cycle_analytics/events.rb @@ -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'] diff --git a/lib/gitlab/cycle_analytics/events_fetcher.rb b/lib/gitlab/cycle_analytics/events_fetcher.rb index 9b62a596aeb..5631867d451 100644 --- a/lib/gitlab/cycle_analytics/events_fetcher.rb +++ b/lib/gitlab/cycle_analytics/events_fetcher.rb @@ -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 diff --git a/lib/gitlab/cycle_analytics/query_config.rb b/lib/gitlab/cycle_analytics/query_config.rb index 55db37ec796..68692f3a4e6 100644 --- a/lib/gitlab/cycle_analytics/query_config.rb +++ b/lib/gitlab/cycle_analytics/query_config.rb @@ -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 diff --git a/spec/lib/gitlab/cycle_analytics/events_spec.rb b/spec/lib/gitlab/cycle_analytics/events_spec.rb index a531c4c31b7..815e70ab6a8 100644 --- a/spec/lib/gitlab/cycle_analytics/events_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/events_spec.rb @@ -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 |