Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/user_contribution_calendar.rb')
-rw-r--r--lib/gitlab/user_contribution_calendar.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/gitlab/user_contribution_calendar.rb b/lib/gitlab/user_contribution_calendar.rb
new file mode 100644
index 00000000000..7eace88e4d7
--- /dev/null
+++ b/lib/gitlab/user_contribution_calendar.rb
@@ -0,0 +1,22 @@
+module Gitlab
+ class UserContributionCalendar
+ def initialize(user)
+ @user = user
+ end
+
+ def calculate
+ query.each_with_object({}) do |(date, contributions), hash|
+ hash[date] = contributions
+ end
+ end
+
+ private
+
+ def query
+ UserContribution
+ .where(user_id: @user.id)
+ .where('date >= ?', 1.year.ago.beginning_of_day)
+ .pluck(:date, :contributions)
+ end
+ end
+end