summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-03-22 14:35:27 -0700
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-03-22 14:35:27 -0700
commit54aca18cf856a18bdd121a3db25d2a64b9e0844d (patch)
treedfac4e8a97b290f318fea1553e023eb5b1d3a47b
parent43afe46bbd19b1edf60abf3f104fb2b0d29af564 (diff)
downloadgitlab-ce-54aca18cf856a18bdd121a3db25d2a64b9e0844d.tar.gz
Contribution calendar will use events instead of commits to count contributions
-rw-r--r--app/views/users/calendar.html.haml5
-rw-r--r--features/steps/user.rb2
-rw-r--r--lib/gitlab/contributions_calendar.rb19
3 files changed, 12 insertions, 14 deletions
diff --git a/app/views/users/calendar.html.haml b/app/views/users/calendar.html.haml
index 12446a209f8..488f49267c7 100644
--- a/app/views/users/calendar.html.haml
+++ b/app/views/users/calendar.html.haml
@@ -1,4 +1,7 @@
-%h4 Contributions calendar
+%h4
+ Contributions calendar
+ .pull-right
+ %small Issues, merge requests and push events
#cal-heatmap.calendar
:javascript
new calendar(
diff --git a/features/steps/user.rb b/features/steps/user.rb
index e6086bfc1c9..5939c28a000 100644
--- a/features/steps/user.rb
+++ b/features/steps/user.rb
@@ -35,7 +35,7 @@ class Spinach::Features::User < Spinach::FeatureSteps
step 'I should see contributions calendar' do
within '.calendar' do
- page.should have_css('.graph-rect.r2.q2')
+ page.should have_css('.graph-rect.r3.q3')
end
end
diff --git a/lib/gitlab/contributions_calendar.rb b/lib/gitlab/contributions_calendar.rb
index ea41644811f..79e0a514f9e 100644
--- a/lib/gitlab/contributions_calendar.rb
+++ b/lib/gitlab/contributions_calendar.rb
@@ -15,25 +15,20 @@ module Gitlab
date_to = Date.today
events = Event.contributions.where(author_id: user.id).
- where("created_at > ?", date_from).where(project_id: projects)
+ where("created_at > ?", date_from).where(project_id: projects).
+ group('date(created_at)').
+ select('date(created_at), count(id) as total_amount').
+ reorder(nil).map(&:attributes)
- grouped_events = events.to_a.group_by { |event| event.created_at.to_date.to_s }
dates = (1.year.ago.to_date..(Date.today + 1.day)).to_a
dates.each do |date|
date_id = date.to_time.to_i.to_s
@timestamps[date_id] = 0
+ day_events = events.find { |day_events| day_events["date"] == date }
- if grouped_events.has_key?(date.to_s)
- grouped_events[date.to_s].each do |event|
- if event.created_at.to_date == date
- if event.issue? || event.merge_request?
- @timestamps[date_id] += 1
- elsif event.push?
- @timestamps[date_id] += event.commits_count
- end
- end
- end
+ if day_events
+ @timestamps[date_id] = day_events["total_amount"]
end
end