Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
85c3128a
Commit
85c3128a
authored
Aug 24, 2017
by
Jeff Stubler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix division by zero for blame age map
parent
19dfd9e9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
7 deletions
+30
-7
app/helpers/blame_helper.rb
app/helpers/blame_helper.rb
+10
-6
changelogs/unreleased/35441-fix-division-by-zero.yml
changelogs/unreleased/35441-fix-division-by-zero.yml
+5
-0
spec/helpers/blame_helper_spec.rb
spec/helpers/blame_helper_spec.rb
+15
-1
No files found.
app/helpers/blame_helper.rb
View file @
85c3128a
...
@@ -11,11 +11,15 @@ module BlameHelper
...
@@ -11,11 +11,15 @@ module BlameHelper
end
end
def
age_map_class
(
commit_date
,
duration
)
def
age_map_class
(
commit_date
,
duration
)
commit_date_days_ago
=
(
duration
[
:now
]
-
commit_date
).
to_i
/
1
.
day
if
duration
[
:started_days_ago
]
==
0
# Numbers 0 to 10 come from this calculation, but only commits on the oldest
"blame-commit-age-0"
# day get number 10 (all other numbers can be multiple days), so the range
else
# is normalized to 0-9
commit_date_days_ago
=
(
duration
[
:now
]
-
commit_date
).
to_i
/
1
.
day
age_group
=
[(
10
*
commit_date_days_ago
)
/
duration
[
:started_days_ago
],
9
].
min
# Numbers 0 to 10 come from this calculation, but only commits on the oldest
"blame-commit-age-
#{
age_group
}
"
# 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
end
end
changelogs/unreleased/35441-fix-division-by-zero.yml
0 → 100644
View file @
85c3128a
---
title
:
Fix division by zero error in blame age mapping
merge_request
:
13803
author
:
Jeff Stubler
type
:
fixed
spec/helpers/blame_helper_spec.rb
View file @
85c3128a
...
@@ -36,17 +36,26 @@ describe BlameHelper do
...
@@ -36,17 +36,26 @@ describe BlameHelper do
describe
'#age_map_class'
do
describe
'#age_map_class'
do
let
(
:dates
)
do
let
(
:dates
)
do
[
Time
.
zone
.
local
(
2014
,
3
,
17
,
0
,
0
,
0
)]
[
Time
.
zone
.
local
(
2014
,
3
,
17
,
0
,
0
,
0
)
,
Time
.
zone
.
now
]
end
end
let
(
:blame_groups
)
do
let
(
:blame_groups
)
do
[
[
{
commit:
double
(
committed_date:
dates
[
0
])
}
{
commit:
double
(
committed_date:
dates
[
0
])
}
]
]
end
end
let
(
:today_blame_groups
)
do
[
{
commit:
double
(
committed_date:
dates
[
1
])
}
]
end
let
(
:duration
)
do
let
(
:duration
)
do
project
=
double
(
created_at:
dates
[
0
])
project
=
double
(
created_at:
dates
[
0
])
helper
.
age_map_duration
(
blame_groups
,
project
)
helper
.
age_map_duration
(
blame_groups
,
project
)
end
end
let
(
:same_day_duration
)
do
project
=
double
(
created_at:
dates
[
1
])
helper
.
age_map_duration
(
today_blame_groups
,
project
)
end
it
'returns blame-commit-age-9 when oldest'
do
it
'returns blame-commit-age-9 when oldest'
do
expect
(
helper
.
age_map_class
(
dates
[
0
],
duration
)).
to
eq
'blame-commit-age-9'
expect
(
helper
.
age_map_class
(
dates
[
0
],
duration
)).
to
eq
'blame-commit-age-9'
...
@@ -55,5 +64,10 @@ describe BlameHelper do
...
@@ -55,5 +64,10 @@ describe BlameHelper do
it
'returns blame-commit-age-0 class when newest'
do
it
'returns blame-commit-age-0 class when newest'
do
expect
(
helper
.
age_map_class
(
duration
[
:now
],
duration
)).
to
eq
'blame-commit-age-0'
expect
(
helper
.
age_map_class
(
duration
[
:now
],
duration
)).
to
eq
'blame-commit-age-0'
end
end
it
'returns blame-commit-age-0 class when created on same day'
do
puts
(
same_day_duration
.
inspect
)
expect
(
helper
.
age_map_class
(
duration
[
:now
],
same_day_duration
)).
to
eq
'blame-commit-age-0'
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment