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:
authorHannes Rosenögger <123haynes@gmail.com>2015-01-29 00:18:22 +0300
committerHannes Rosenögger <123haynes@gmail.com>2015-01-29 03:25:26 +0300
commit792ced2f4190226c3335967a8e5a30d3b72bd4ae (patch)
tree0411a2c41710a7f0d2c06fa141b8875c77873968 /app/models/repository.rb
parent8eb365c0a04b912d2e10eb16adeeb4216563be2c (diff)
Add a commit calendar to the user profile
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r--app/models/repository.rb31
1 files changed, 28 insertions, 3 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index e93c76790c7..e44ecca865c 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -139,21 +139,46 @@ class Repository
def graph_log
Rails.cache.fetch(cache_key(:graph_log)) do
+
+ # handle empty repos that don't have a root_ref set yet
+ unless raw_repository.root_ref.present?
+ raw_repository.root_ref = 'refs/heads/master'
+ end
+
commits = raw_repository.log(limit: 6000, skip_merges: true,
- ref: root_ref)
+ ref: raw_repository.root_ref)
+
commits.map do |rugged_commit|
- commit = Gitlab::Git::Commit.new(rugged_commit)
+ commit = Gitlab::Git::Commit.new(rugged_commit)
{
author_name: commit.author_name.force_encoding('UTF-8'),
author_email: commit.author_email.force_encoding('UTF-8'),
additions: commit.stats.additions,
- deletions: commit.stats.deletions
+ deletions: commit.stats.deletions,
+ date: commit.committed_date
}
end
end
end
+ def graph_logs_by_user_email(user)
+ graph_log.select { |u_email| u_email[:author_email] == user.email }
+ end
+
+ def timestamps_by_user_from_graph_log(user)
+ graph_logs_by_user_email(user).map { |graph_log| graph_log[:date].to_time.to_i }
+ end
+
+ def commits_log_of_user_by_date(user)
+ timestamps_by_user_from_graph_log(user).
+ group_by { |commit_date| commit_date }.
+ inject({}) do |hash, (timestamp_date, commits)|
+ hash[timestamp_date] = commits.count
+ hash
+ end
+ end
+
def cache_key(type)
"#{type}:#{path_with_namespace}"
end