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
80e314be
Commit
80e314be
authored
Nov 16, 2016
by
Ruben Davila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor formatting of time and add more specs.
parent
4d681488
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
6 deletions
+86
-6
app/models/concerns/time_trackable.rb
app/models/concerns/time_trackable.rb
+2
-2
app/services/slash_commands/interpret_service.rb
app/services/slash_commands/interpret_service.rb
+2
-2
app/services/system_note_service.rb
app/services/system_note_service.rb
+2
-2
lib/gitlab/time_tracking_formatter.rb
lib/gitlab/time_tracking_formatter.rb
+15
-0
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+65
-0
No files found.
app/models/concerns/time_trackable.rb
View file @
80e314be
...
...
@@ -36,11 +36,11 @@ module TimeTrackable
end
def
human_total_time_spent
ChronicDuration
.
output
(
total_time_spent
,
format: :shor
t
)
Gitlab
::
TimeTrackingFormatter
.
output
(
total_time_spen
t
)
end
def
human_time_estimate
ChronicDuration
.
output
(
time_estimate
,
format: :short
)
Gitlab
::
TimeTrackingFormatter
.
output
(
time_estimate
)
end
private
...
...
app/services/slash_commands/interpret_service.rb
View file @
80e314be
...
...
@@ -254,7 +254,7 @@ module SlashCommands
current_user
.
can?
(
:"admin_
#{
issuable
.
to_ability_name
}
"
,
project
)
end
command
:estimate
do
|
raw_duration
|
time_estimate
=
ChronicDuration
.
parse
(
raw_duration
,
default_unit:
'hours'
)
rescue
nil
time_estimate
=
Gitlab
::
TimeTrackingFormatter
.
parse
(
raw_duration
)
if
time_estimate
@updates
[
:time_estimate
]
=
time_estimate
...
...
@@ -268,7 +268,7 @@ module SlashCommands
end
command
:spend
do
|
raw_duration
|
reduce_time
=
raw_duration
.
sub!
(
/\A-/
,
''
)
time_spent
=
ChronicDuration
.
parse
(
raw_duration
,
default_unit:
'hours'
)
rescue
nil
time_spent
=
Gitlab
::
TimeTrackingFormatter
.
parse
(
raw_duration
)
if
time_spent
time_spent
*=
-
1
if
reduce_time
...
...
app/services/system_note_service.rb
View file @
80e314be
...
...
@@ -125,7 +125,7 @@ module SystemNoteService
# Returns the created Note object
def
change_time_estimate
(
noteable
,
project
,
author
)
parsed_time
=
ChronicDuration
.
output
(
noteable
.
time_estimate
,
format: :short
)
parsed_time
=
Gitlab
::
TimeTrackingFormatter
.
output
(
noteable
.
time_estimate
)
body
=
if
noteable
.
time_estimate
==
0
"Removed time estimate on this
#{
noteable
.
human_class_name
}
"
else
...
...
@@ -154,7 +154,7 @@ module SystemNoteService
if
time_spent
==
:reset
body
=
"Removed time spent on this
#{
noteable
.
human_class_name
}
"
else
parsed_time
=
ChronicDuration
.
output
(
time_spent
.
abs
,
format: :short
)
parsed_time
=
Gitlab
::
TimeTrackingFormatter
.
output
(
time_spent
.
abs
)
action
=
time_spent
>
0
?
'Added'
:
'Subtracted'
body
=
"
#{
action
}
#{
parsed_time
}
of time spent on this
#{
noteable
.
human_class_name
}
"
end
...
...
lib/gitlab/time_tracking_formatter.rb
0 → 100644
View file @
80e314be
module
Gitlab
module
TimeTrackingFormatter
extend
self
def
parse
(
string
)
ChronicDuration
.
parse
(
string
,
default_unit:
'hours'
)
rescue
ChronicDuration
::
DurationParseError
nil
end
def
output
(
seconds
)
ChronicDuration
.
output
(
seconds
,
format: :short
,
limit_to_hours:
false
,
weeks:
true
)
end
end
end
spec/services/system_note_service_spec.rb
View file @
80e314be
...
...
@@ -594,4 +594,69 @@ describe SystemNoteService, services: true do
end
end
end
describe
'.change_time_estimate'
do
subject
{
described_class
.
change_time_estimate
(
noteable
,
project
,
author
)
}
it_behaves_like
'a system note'
context
'with a time estimate'
do
it
'sets the note text'
do
noteable
.
update_attribute
(
:time_estimate
,
277200
)
expect
(
subject
.
note
).
to
eq
"Changed time estimate of this issue to 1w 4d 5h"
end
end
context
'without a time estimate'
do
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
"Removed time estimate on this issue"
end
end
end
describe
'.change_time_spent'
do
# We need a custom noteable in order to the shared examples to be green.
let
(
:noteable
)
do
mr
=
create
(
:merge_request
,
source_project:
project
)
mr
.
spend_time
(
1
,
author
)
mr
.
save!
mr
end
subject
do
described_class
.
change_time_spent
(
noteable
,
project
,
author
)
end
it_behaves_like
'a system note'
context
'when time was added'
do
it
'sets the note text'
do
spend_time!
(
277200
)
expect
(
subject
.
note
).
to
eq
"Added 1w 4d 5h of time spent on this merge request"
end
end
context
'when time was subtracted'
do
it
'sets the note text'
do
spend_time!
(
-
277200
)
expect
(
subject
.
note
).
to
eq
"Subtracted 1w 4d 5h of time spent on this merge request"
end
end
context
'when time was removed'
do
it
'sets the note text'
do
spend_time!
(
:reset
)
expect
(
subject
.
note
).
to
eq
"Removed time spent on this merge request"
end
end
def
spend_time!
(
seconds
)
noteable
.
spend_time
(
seconds
,
author
)
noteable
.
save!
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