BigW Consortium Gitlab

Commit 1f701cb5 by James Lopez

added staging events and spec

parent f8acc7ea
......@@ -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)
......
......@@ -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
......
......@@ -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)
......
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