added production events and related spec

This commit is contained in:
James Lopez 2016-10-21 17:30:38 +02:00
parent 275292de47
commit 3cdc9af78e
3 changed files with 44 additions and 11 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)