Commit 3b5d9477 authored by James Lopez's avatar James Lopez

commit events and spec

parent 1d6068a1
...@@ -9,15 +9,25 @@ module Gitlab ...@@ -9,15 +9,25 @@ module Gitlab
@fetcher = EventsFetcher.new(project: project, from: from) @fetcher = EventsFetcher.new(project: project, from: from)
end end
#TODO: backend pagination - specially for commits, etc...
def issue_events def issue_events
@fetcher.fetch_issues.each do |event| #TODO figure out what the frontend needs for displaying the avatar
event['issue_diff'] = interval_in_words(event['issue_diff']) @fetcher.fetch_issue_events.each do |event|
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
event['created_at'] = interval_in_words(event['created_at']) event['created_at'] = interval_in_words(event['created_at'])
end end
end end
def plan_events
# TODO sort out 1st referenced commit and parse stuff
@fetcher.fetch_plan_events
end
private
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
end end
end end
......
...@@ -8,22 +8,39 @@ module Gitlab ...@@ -8,22 +8,39 @@ module Gitlab
@from = from @from = from
end end
def fetch_issues def fetch_issue_events
base_query = base_query_for(:issue) base_query = base_query_for(:issue)
diff_fn = subtract_datetimes_diff(base_query, issue_table[:created_at], metric_attributes) diff_fn = subtract_datetimes_diff(base_query, issue_table[:created_at], issue_attributes)
query = base_query.join(user_table).on(issue_table[:author_id].eq(user_table[:id])). query = base_query.join(user_table).on(issue_table[:author_id].eq(user_table[:id])).
project(extract_epoch(diff_fn).as('issue_diff'), *issue_projections). project(extract_epoch(diff_fn).as('total_time'), *issue_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
end end
def metric_attributes def fetch_plan_events
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')).
order(issue_table[:created_at].desc)
ActiveRecord::Base.connection.execute(query.to_sql).to_a
end
private
def issue_attributes
[issue_metrics_table[:first_associated_with_milestone_at], [issue_metrics_table[:first_associated_with_milestone_at],
issue_metrics_table[:first_added_to_board_at]] issue_metrics_table[:first_added_to_board_at]]
end end
def plan_attributes
issue_attributes + [issue_metrics_table[:first_mentioned_in_commit_at]]
end
def issue_projections def issue_projections
[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
......
...@@ -56,6 +56,10 @@ module Gitlab ...@@ -56,6 +56,10 @@ module Gitlab
MergeRequest.arel_table MergeRequest.arel_table
end end
def merge_request_diff_table
MergeRequestDiff.arel_table
end
def mr_closing_issues_table def mr_closing_issues_table
MergeRequestsClosingIssues.arel_table MergeRequestsClosingIssues.arel_table
end end
......
...@@ -11,11 +11,11 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -11,11 +11,11 @@ describe Gitlab::CycleAnalytics::Events do
setup(context) setup(context)
end end
describe '#issue' do describe '#issue_events' do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
it 'has an issue diff' do it 'has the total time' do
expect(subject.issue_events.first['issue_diff']).to eq('2 days ago') expect(subject.issue_events.first['total_time']).to eq('2 days')
end end
it 'has a title' do it 'has a title' do
...@@ -35,6 +35,18 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -35,6 +35,18 @@ describe Gitlab::CycleAnalytics::Events do
end end
end end
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)
end
it 'has the total time' do
expect(subject.plan_events.first['total_time']).to eq('2 days')
end
end
def setup(context) def setup(context)
milestone = create(:milestone, project: project) milestone = create(:milestone, project: project)
context.update(milestone: milestone) 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