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

commits_calendar.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2f30d238e6bd9591be4ea57a9b86d9c4c119c5c2 (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
33
module Gitlab
  class CommitsCalendar
    attr_reader :timestamps

    def initialize(projects, user)
      @timestamps = {}
      date_timestamps = []

      projects.reject(&:forked?).each do |project|
        date_timestamps << ProjectContributions.new(project, user).commits_log
      end

      # Sumarrize commits from all projects per days
      date_timestamps = date_timestamps.inject do |collection, date|
        collection.merge(date) { |k, old_v, new_v| old_v + new_v }
      end

      date_timestamps ||= []
      date_timestamps.each do |date, commits|
        timestamp = Date.parse(date).to_time.to_i.to_s rescue nil
        @timestamps[timestamp] = commits if timestamp
      end
    end

    def starting_year
      (Time.now - 1.year).strftime("%Y")
    end

    def starting_month
      Date.today.strftime("%m").to_i
    end
  end
end