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

This commit is contained in:
James Lopez 2016-10-19 15:40:14 +02:00
parent 3b5d947730
commit 72660d58af
4 changed files with 29 additions and 14 deletions

View file

@ -20,12 +20,23 @@ module Gitlab
end
def plan_events
# TODO sort out 1st referenced commit and parse stuff
@fetcher.fetch_plan_events
@fetcher.fetch_plan_events.each do |event|
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
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)
"#{distance_of_time_in_words(diff.to_f)} ago"
end

View file

@ -23,8 +23,8 @@ module Gitlab
base_query = base_query_for(:plan)
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])).
project(merge_request_diff_table[:st_commits].as(:commits), extract_epoch(diff_fn).as('total_time')).
query = base_query.join(mr_diff_table).on(mr_diff_table[:merge_request_id].eq(mr_table[:id])).
project(extract_epoch(diff_fn).as('total_time'), *plan_projections).
order(issue_table[:created_at].desc)
ActiveRecord::Base.connection.execute(query.to_sql).to_a
@ -45,6 +45,10 @@ module Gitlab
[issue_table[:title], issue_table[:iid], issue_table[:created_at], User.arel_table[:name]]
end
def plan_projections
[mr_diff_table[:st_commits].as('commits'), issue_metrics_table[:first_mentioned_in_commit_at]]
end
def user_table
User.arel_table
end

View file

@ -35,28 +35,28 @@ module Gitlab
where(issue_table[:created_at].gteq(@from))
# Load merge_requests
query = query.join(merge_request_table, Arel::Nodes::OuterJoin).
on(merge_request_table[:id].eq(mr_closing_issues_table[:merge_request_id])).
join(merge_request_metrics_table).
on(merge_request_table[:id].eq(merge_request_metrics_table[:merge_request_id]))
query = query.join(mr_table, Arel::Nodes::OuterJoin).
on(mr_table[:id].eq(mr_closing_issues_table[:merge_request_id])).
join(mr_metrics_table).
on(mr_table[:id].eq(mr_metrics_table[:merge_request_id]))
if DEPLOYMENT_METRIC_STAGES.include?(name)
# 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
query
end
def merge_request_metrics_table
def mr_metrics_table
MergeRequest::Metrics.arel_table
end
def merge_request_table
def mr_table
MergeRequest.arel_table
end
def merge_request_diff_table
def mr_diff_table
MergeRequestDiff.arel_table
end

View file

@ -38,8 +38,8 @@ describe Gitlab::CycleAnalytics::Events do
describe '#plan_events' do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
xit 'has the first referenced commit' do
expect(subject.plan_events.first['commit']).to eq(project.commit)
it 'has the first referenced commit' do
expect(subject.plan_events.first['commit'].message).to eq('commit message')
end
it 'has the total time' do