debian-mirror-gitlab/app/helpers/blame_helper.rb

28 lines
864 B
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module BlameHelper
def age_map_duration(blame_groups, project)
now = Time.zone.now
start_date = blame_groups.map { |blame_group| blame_group[:commit].committed_date }
.append(project.created_at).min
{
now: now,
started_days_ago: (now - start_date).to_i / 1.day
}
end
def age_map_class(commit_date, duration)
2018-03-17 18:26:18 +05:30
if duration[:started_days_ago] == 0
"blame-commit-age-0"
else
commit_date_days_ago = (duration[:now] - commit_date).to_i / 1.day
# Numbers 0 to 10 come from this calculation, but only commits on the oldest
# day get number 10 (all other numbers can be multiple days), so the range
# is normalized to 0-9
age_group = [(10 * commit_date_days_ago) / duration[:started_days_ago], 9].min
"blame-commit-age-#{age_group}"
end
2017-09-10 17:25:29 +05:30
end
end