Commit 72660d58 authored by James Lopez's avatar James Lopez

plan events and spec working. Also added some TODOs to the code.

parent 3b5d9477
...@@ -20,12 +20,23 @@ module Gitlab ...@@ -20,12 +20,23 @@ module Gitlab
end end
def plan_events def plan_events
# TODO sort out 1st referenced commit and parse stuff @fetcher.fetch_plan_events.each do |event|
@fetcher.fetch_plan_events event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
commits = event.delete('commits')
event['commit'] = first_time_reference_commit(commits, event)
end
end end
private private
def first_time_reference_commit(commits, event)
st_commit = YAML.load(commits).detect do |commit|
commit['created_at'] == event['first_mentioned_in_commit_at']
end
Commit.new(Gitlab::Git::Commit.new(st_commit), @project)
end
def interval_in_words(diff) def interval_in_words(diff)
"#{distance_of_time_in_words(diff.to_f)} ago" "#{distance_of_time_in_words(diff.to_f)} ago"
end end
......
...@@ -23,8 +23,8 @@ module Gitlab ...@@ -23,8 +23,8 @@ module Gitlab
base_query = base_query_for(:plan) base_query = base_query_for(:plan)
diff_fn = subtract_datetimes_diff(base_query, issue_table[:created_at], plan_attributes) diff_fn = subtract_datetimes_diff(base_query, issue_table[:created_at], plan_attributes)
query = base_query.join(merge_request_diff_table).on(merge_request_diff_table[:merge_request_id].eq(merge_request_table[:id])). query = base_query.join(mr_diff_table).on(mr_diff_table[:merge_request_id].eq(mr_table[:id])).
project(merge_request_diff_table[:st_commits].as(:commits), extract_epoch(diff_fn).as('total_time')). project(extract_epoch(diff_fn).as('total_time'), *plan_projections).
order(issue_table[:created_at].desc) order(issue_table[:created_at].desc)
ActiveRecord::Base.connection.execute(query.to_sql).to_a ActiveRecord::Base.connection.execute(query.to_sql).to_a
...@@ -45,6 +45,10 @@ module Gitlab ...@@ -45,6 +45,10 @@ module Gitlab
[issue_table[:title], issue_table[:iid], issue_table[:created_at], User.arel_table[:name]] [issue_table[:title], issue_table[:iid], issue_table[:created_at], User.arel_table[:name]]
end end
def plan_projections
[mr_diff_table[:st_commits].as('commits'), issue_metrics_table[:first_mentioned_in_commit_at]]
end
def user_table def user_table
User.arel_table User.arel_table
end end
......
...@@ -35,28 +35,28 @@ module Gitlab ...@@ -35,28 +35,28 @@ module Gitlab
where(issue_table[:created_at].gteq(@from)) where(issue_table[:created_at].gteq(@from))
# Load merge_requests # Load merge_requests
query = query.join(merge_request_table, Arel::Nodes::OuterJoin). query = query.join(mr_table, Arel::Nodes::OuterJoin).
on(merge_request_table[:id].eq(mr_closing_issues_table[:merge_request_id])). on(mr_table[:id].eq(mr_closing_issues_table[:merge_request_id])).
join(merge_request_metrics_table). join(mr_metrics_table).
on(merge_request_table[:id].eq(merge_request_metrics_table[:merge_request_id])) on(mr_table[:id].eq(mr_metrics_table[:merge_request_id]))
if DEPLOYMENT_METRIC_STAGES.include?(name) if DEPLOYMENT_METRIC_STAGES.include?(name)
# Limit to merge requests that have been deployed to production after `@from` # Limit to merge requests that have been deployed to production after `@from`
query.where(merge_request_metrics_table[:first_deployed_to_production_at].gteq(@from)) query.where(mr_metrics_table[:first_deployed_to_production_at].gteq(@from))
end end
query query
end end
def merge_request_metrics_table def mr_metrics_table
MergeRequest::Metrics.arel_table MergeRequest::Metrics.arel_table
end end
def merge_request_table def mr_table
MergeRequest.arel_table MergeRequest.arel_table
end end
def merge_request_diff_table def mr_diff_table
MergeRequestDiff.arel_table MergeRequestDiff.arel_table
end end
......
...@@ -38,8 +38,8 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -38,8 +38,8 @@ describe Gitlab::CycleAnalytics::Events do
describe '#plan_events' do describe '#plan_events' do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
xit 'has the first referenced commit' do it 'has the first referenced commit' do
expect(subject.plan_events.first['commit']).to eq(project.commit) expect(subject.plan_events.first['commit'].message).to eq('commit message')
end end
it 'has the total time' do it 'has the total time' do
......
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