diff options
author | James Lopez <james@jameslopez.es> | 2016-10-21 17:30:38 +0200 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-11-17 08:22:55 +0100 |
commit | 3cdc9af78ebb71e2b91046e9dea8695aa04f6713 (patch) | |
tree | 22122f8bd8928afd399f5640aefdcfa464470c82 | |
parent | 275292de4768ab9893d9d786b9fbb72bf173ba3c (diff) | |
download | gitlab-ce-3cdc9af78ebb71e2b91046e9dea8695aa04f6713.tar.gz |
added production events and related spec
-rw-r--r-- | lib/gitlab/cycle_analytics/events.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/events_fetcher.rb | 20 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/events_spec.rb | 29 |
3 files changed, 44 insertions, 11 deletions
diff --git a/lib/gitlab/cycle_analytics/events.rb b/lib/gitlab/cycle_analytics/events.rb index 3ab544faf5d..912694fa1ad 100644 --- a/lib/gitlab/cycle_analytics/events.rb +++ b/lib/gitlab/cycle_analytics/events.rb @@ -10,9 +10,9 @@ module Gitlab end # TODO: backend pagination - specially for commits, etc... + # TODO figure out what the frontend needs for displaying the avatar def issue_events - # TODO figure out what the frontend needs for displaying the avatar @fetcher.fetch(stage: :issue).each { |event| parse_event(event) } end @@ -46,6 +46,10 @@ module Gitlab end end + def production_events + @fetcher.fetch(stage: :production).each { |event| parse_event(event) } + 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 75a6779e0e8..03b1878dc1c 100644 --- a/lib/gitlab/cycle_analytics/events_fetcher.rb +++ b/lib/gitlab/cycle_analytics/events_fetcher.rb @@ -8,9 +8,7 @@ module Gitlab start_time_attrs: issue_table[:created_at], end_time_attrs: [issue_metrics_table[:first_associated_with_milestone_at], issue_metrics_table[:first_added_to_board_at]], - projections: [issue_table[:title], issue_table[:iid], issue_table[:created_at], user_table[:name]], - project: @project, - from: @from + projections: [issue_table[:title], issue_table[:iid], issue_table[:created_at], user_table[:name]] }, plan: { start_time_attrs: issue_metrics_table[:first_associated_with_milestone_at], @@ -39,12 +37,15 @@ module Gitlab 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] - } + }, + production: { + start_time_attrs: issue_table[:created_at], + end_time_attrs: mr_metrics_table[:first_deployed_to_production_at], + projections: [issue_table[:title], issue_table[:iid], issue_table[:created_at], user_table[:name]] + }, }.freeze def initialize(project:, from:) - @project = project - @from = from @query = EventsQuery.new(project: project, from: from) end @@ -60,14 +61,13 @@ 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 - def code_custom_query(base_query) - base_query.join(user_table).on(issue_table[:author_id].eq(user_table[:id])) - end - def review_custom_query(base_query) base_query.join(user_table).on(mr_table[:author_id].eq(user_table[:id])) end diff --git a/spec/lib/gitlab/cycle_analytics/events_spec.rb b/spec/lib/gitlab/cycle_analytics/events_spec.rb index 0212ce60b92..410310d3029 100644 --- a/spec/lib/gitlab/cycle_analytics/events_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/events_spec.rb @@ -149,6 +149,35 @@ describe Gitlab::CycleAnalytics::Events do end end + describe '#production_events' do + let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } + + before do + merge_merge_requests_closing_issue(context) + deploy_master + end + + it 'has the total time' do + expect(subject.production_events.first['total_time']).to eq('2 days') + end + + it 'has a title' do + expect(subject.production_events.first['title']).to eq(context.title) + end + + it 'has an iid' do + expect(subject.production_events.first['iid']).to eq(context.iid.to_s) + end + + it 'has a created_at timestamp' do + expect(subject.production_events.first['created_at']).to end_with('ago') + end + + it "has the author's name" do + expect(subject.production_events.first['name']).to eq(context.author.name) + end + end + def setup(context) milestone = create(:milestone, project: project) context.update(milestone: milestone) |