diff options
author | Robert Speicher <robert@gitlab.com> | 2017-09-06 16:42:10 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-09-06 16:42:10 +0000 |
commit | 10fd3542225e161de0c82442304a0881ccecc774 (patch) | |
tree | 1ee40598c2e9f555b809a056e5b2bbc0edc652ef /app/helpers | |
parent | 04f887420999a14c6188db93f7c10add02f514f4 (diff) | |
parent | 0429ad80921cb38229cdbe650d1ca113c24eb88d (diff) | |
download | gitlab-ce-10fd3542225e161de0c82442304a0881ccecc774.tar.gz |
Merge branch '35441-fix-division-by-zero' into 'master'
Fix division by zero for blame age map
Closes #35441
See merge request !13803
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/blame_helper.rb | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/app/helpers/blame_helper.rb b/app/helpers/blame_helper.rb index d1dc4d94560..089d9e3e387 100644 --- a/app/helpers/blame_helper.rb +++ b/app/helpers/blame_helper.rb @@ -11,11 +11,15 @@ module BlameHelper end def age_map_class(commit_date, duration) - 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}" + 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 end end |