diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project_contributions.rb | 9 | ||||
-rw-r--r-- | app/models/repository.rb | 14 |
2 files changed, 23 insertions, 0 deletions
diff --git a/app/models/project_contributions.rb b/app/models/project_contributions.rb index 8ab2d814a94..bfe9928b158 100644 --- a/app/models/project_contributions.rb +++ b/app/models/project_contributions.rb @@ -17,6 +17,15 @@ class ProjectContributions end end + def user_commits_on_date(date) + repository = @project.repository + + if !repository.exists? || repository.empty? + return [] + end + commits = repository.commits_by_user_on_date_log(@user, date) + end + def cache_key "#{Date.today.to_s}-commits-log-#{project.id}-#{user.email}" end diff --git a/app/models/repository.rb b/app/models/repository.rb index 47758b8ad68..7addbca8fb1 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -157,6 +157,20 @@ class Repository end end + def commits_by_user_on_date_log(user, date) + # format the date string for git + start_date = date.strftime("%Y-%m-%d 00:00:00") + end_date = date.strftime("%Y-%m-%d 23:59:59") + + author_emails = '(' + user.all_emails.map{ |e| Regexp.escape(e) }.join('|') + ')' + args = %W(git log -E --author=#{author_emails} --after=#{start_date.to_s} --until=#{end_date.to_s} --branches --pretty=format:%h) + commits = Gitlab::Popen.popen(args, path_to_repo).first.split("\n") + + commits.map! do |commit_id| + commit(commit_id) + end + end + def commits_per_day_for_user(user) timestamps_by_user_log(user). group_by { |commit_date| commit_date }. |