summaryrefslogtreecommitdiff
path: root/app/models/project_contributions.rb
blob: bfe9928b1580bf8e0c1d82226b97fcd50f5c4011 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class ProjectContributions
  attr_reader :project, :user

  def initialize(project, user)
    @project, @user = project, user
  end

  def commits_log
    repository = project.repository

    if !repository.exists? || repository.empty?
      return {}
    end

    Rails.cache.fetch(cache_key) do
      repository.commits_per_day_for_user(user)
    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
end