summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJeff Stubler <brunsa2@gmail.com>2017-08-24 09:50:47 -0500
committerJeff Stubler <brunsa2@gmail.com>2017-08-24 22:27:31 -0500
commit85c3128a505a999b2ac775aac1336a0d27e7df55 (patch)
tree2c1b5406a4a9a202ae23b502d32388f26bf28a1c /app
parent19dfd9e9d6cf8c260dea6a339b1842fc2399729e (diff)
downloadgitlab-ce-85c3128a505a999b2ac775aac1336a0d27e7df55.tar.gz
Fix division by zero for blame age map
Diffstat (limited to 'app')
-rw-r--r--app/helpers/blame_helper.rb16
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