diff options
author | James Lopez <james@jameslopez.es> | 2016-10-21 11:33:37 +0200 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-11-17 08:22:55 +0100 |
commit | 1f701cb5e2fc9ea3af98ab0e6e07a7568a0e54dc (patch) | |
tree | eccc2c127d5c43807991746f64962a4d7be334a6 | |
parent | f8acc7ea77bb52531b11abea5eabd68a38236cff (diff) | |
download | gitlab-ce-1f701cb5e2fc9ea3af98ab0e6e07a7568a0e54dc.tar.gz |
added staging events and spec
-rw-r--r-- | lib/gitlab/cycle_analytics/events.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/events_fetcher.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/events_spec.rb | 26 |
3 files changed, 47 insertions, 2 deletions
diff --git a/lib/gitlab/cycle_analytics/events.rb b/lib/gitlab/cycle_analytics/events.rb index a16c15ed3a8..3c0b9a7ddfa 100644 --- a/lib/gitlab/cycle_analytics/events.rb +++ b/lib/gitlab/cycle_analytics/events.rb @@ -39,6 +39,13 @@ module Gitlab @fetcher.fetch_review_events.each { |event| parse_event(event) } end + def staging_events + @fetcher.fetch_staging_events.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 + end + end + private def parse_event(event) diff --git a/lib/gitlab/cycle_analytics/events_fetcher.rb b/lib/gitlab/cycle_analytics/events_fetcher.rb index 1be68c771cd..bddaede53b7 100644 --- a/lib/gitlab/cycle_analytics/events_fetcher.rb +++ b/lib/gitlab/cycle_analytics/events_fetcher.rb @@ -46,7 +46,7 @@ module Gitlab end def fetch_test_events - base_query = base_query_for(:code) + base_query = base_query_for(:test) diff_fn = subtract_datetimes_diff(base_query, mr_metrics_table[:latest_build_started_at], mr_metrics_table[:latest_build_finished_at]) @@ -58,7 +58,7 @@ module Gitlab end def fetch_review_events - base_query = base_query_for(:code) + base_query = base_query_for(:review) diff_fn = subtract_datetimes_diff(base_query, mr_table[:created_at], mr_metrics_table[:merged_at]) @@ -70,6 +70,18 @@ module Gitlab execute(query) end + def fetch_staging_events + base_query = base_query_for(:staging) + diff_fn = subtract_datetimes_diff(base_query, + mr_metrics_table[:merged_at], + mr_metrics_table[:first_deployed_to_production_at]) + + query = base_query.project(extract_epoch(diff_fn).as('total_time'), mr_metrics_table[:ci_commit_id]). + order(mr_table[:created_at].desc) + + execute(query) + end + private def issue_attributes diff --git a/spec/lib/gitlab/cycle_analytics/events_spec.rb b/spec/lib/gitlab/cycle_analytics/events_spec.rb index 17db46f0d4a..0212ce60b92 100644 --- a/spec/lib/gitlab/cycle_analytics/events_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/events_spec.rb @@ -123,6 +123,32 @@ describe Gitlab::CycleAnalytics::Events do end end + describe '#staging_events' do + let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } + let(:merge_request) { MergeRequest.first } + let!(:pipeline) do + create(:ci_pipeline, + ref: merge_request.source_branch, + sha: merge_request.diff_head_sha, + project: context.project) + end + + before do + pipeline.run! + pipeline.succeed! + merge_merge_requests_closing_issue(context) + deploy_master + end + + it 'has the build info as a pipeline' do + expect(subject.staging_events.first['pipeline']).to eq(pipeline) + end + + it 'has the total time' do + expect(subject.staging_events.first['total_time']).to eq('less than a minute') + end + end + def setup(context) milestone = create(:milestone, project: project) context.update(milestone: milestone) |