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
4d681488
Commit
4d681488
authored
Nov 16, 2016
by
Ruben Davila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address suggestions from last code review.
* Added new serializers for Issue and MergeRequest.
parent
933400e4
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
97 additions
and
28 deletions
+97
-28
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+1
-1
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+1
-1
app/models/concerns/time_trackable.rb
app/models/concerns/time_trackable.rb
+2
-7
app/models/note.rb
app/models/note.rb
+1
-1
app/models/timelog.rb
app/models/timelog.rb
+1
-1
app/serializers/issuable_entity.rb
app/serializers/issuable_entity.rb
+21
-0
app/serializers/issue_entity.rb
app/serializers/issue_entity.rb
+11
-0
app/serializers/issue_serializer.rb
app/serializers/issue_serializer.rb
+3
-0
app/serializers/label_entity.rb
app/serializers/label_entity.rb
+11
-0
app/serializers/merge_request_entity.rb
app/serializers/merge_request_entity.rb
+17
-0
app/serializers/merge_request_serializer.rb
app/serializers/merge_request_serializer.rb
+3
-0
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+3
-3
app/services/slash_commands/interpret_service.rb
app/services/slash_commands/interpret_service.rb
+2
-1
app/services/system_note_service.rb
app/services/system_note_service.rb
+4
-4
spec/factories/timelogs.rb
spec/factories/timelogs.rb
+1
-0
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+9
-4
spec/models/timelog_spec.rb
spec/models/timelog_spec.rb
+1
-0
spec/services/slash_commands/interpret_service_spec.rb
spec/services/slash_commands/interpret_service_spec.rb
+5
-5
No files found.
app/controllers/projects/issues_controller.rb
View file @
4d681488
...
...
@@ -75,7 +75,7 @@ class Projects::IssuesController < Projects::ApplicationController
respond_to
do
|
format
|
format
.
html
format
.
json
do
render
json:
@issue
.
to_json
(
include:
[
:milestone
,
:labels
],
methods:
[
:total_time_spent
,
:human_total_time_spent
,
:human_time_estimate
]
)
render
json:
IssueSerializer
.
new
.
represent
(
@issue
)
end
end
end
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
4d681488
...
...
@@ -62,7 +62,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
format
.
html
{
define_discussion_vars
}
format
.
json
do
render
json:
@merge_request
,
methods: :rebase_in_progress?
render
json:
MergeRequestSerializer
.
new
.
represent
(
@merge_request
)
end
format
.
patch
do
...
...
app/models/concerns/time_trackable.rb
View file @
4d681488
...
...
@@ -27,15 +27,10 @@ module TimeTrackable
if
seconds
==
:reset
reset_spent_time
else
add_or_su
s
btract_spent_time
add_or_subtract_spent_time
end
end
def
spend_time!
(
seconds
,
user
)
spend_time
(
seconds
,
user
)
save!
end
def
total_time_spent
timelogs
.
sum
(
:time_spent
)
end
...
...
@@ -54,7 +49,7 @@ module TimeTrackable
timelogs
.
new
(
time_spent:
total_time_spent
*
-
1
,
user:
@time_spent_user
)
end
def
add_or_su
s
btract_spent_time
def
add_or_subtract_spent_time
# Exit if time to subtract exceeds the total time spent.
return
if
time_spent
<
0
&&
(
time_spent
.
abs
>
total_time_spent
)
...
...
app/models/note.rb
View file @
4d681488
...
...
@@ -19,7 +19,7 @@ class Note < ActiveRecord::Base
# Banzai::ObjectRenderer
attr_accessor
:user_visible_reference_count
# Attribute
s
used to store the attributes that have ben changed by slash commands.
# Attribute used to store the attributes that have ben changed by slash commands.
attr_accessor
:commands_changes
default_value_for
:system
,
false
...
...
app/models/timelog.rb
View file @
4d681488
class
Timelog
<
ActiveRecord
::
Base
validates
:time_spent
,
presence:
true
validates
:time_spent
,
:user
,
presence:
true
belongs_to
:trackable
,
polymorphic:
true
belongs_to
:user
...
...
app/serializers/issuable_entity.rb
0 → 100644
View file @
4d681488
class
IssuableEntity
<
Grape
::
Entity
expose
:id
expose
:iid
expose
:assignee_id
expose
:author_id
expose
:description
expose
:lock_version
expose
:milestone_id
expose
:position
expose
:state
expose
:title
expose
:updated_by_id
expose
:created_at
expose
:updated_at
expose
:deleted_at
expose
:time_estimate
expose
:total_time_spent
expose
:human_time_estimate
expose
:human_total_time_spent
end
app/serializers/issue_entity.rb
0 → 100644
View file @
4d681488
class
IssueEntity
<
IssuableEntity
expose
:branch_name
expose
:confidential
expose
:due_date
expose
:moved_to_id
expose
:project_id
expose
:updated_by_id
expose
:weight
expose
:milestone
,
using:
API
::
Entities
::
Milestone
expose
:labels
,
using:
LabelEntity
end
app/serializers/issue_serializer.rb
0 → 100644
View file @
4d681488
class
IssueSerializer
<
BaseSerializer
entity
IssueEntity
end
app/serializers/label_entity.rb
0 → 100644
View file @
4d681488
class
LabelEntity
<
Grape
::
Entity
expose
:id
expose
:title
expose
:color
expose
:description
expose
:group_id
expose
:project_id
expose
:template
expose
:created_at
expose
:updated_at
end
app/serializers/merge_request_entity.rb
0 → 100644
View file @
4d681488
class
MergeRequestEntity
<
IssuableEntity
expose
:approvals_before_merge
expose
:in_progress_merge_commit_sha
expose
:locked_at
expose
:merge_commit_sha
expose
:merge_error
expose
:merge_params
expose
:merge_status
expose
:merge_user_id
expose
:merge_when_build_succeeds
expose
:rebase_commit_sha
expose
:rebase_in_progress?
expose
:source_branch
expose
:source_project_id
expose
:target_branch
expose
:target_project_id
end
app/serializers/merge_request_serializer.rb
0 → 100644
View file @
4d681488
class
MergeRequestSerializer
<
BaseSerializer
entity
MergeRequestEntity
end
app/services/issuable_base_service.rb
View file @
4d681488
...
...
@@ -239,9 +239,9 @@ class IssuableBaseService < BaseService
end
def
change_time_spent
(
issuable
)
if
params
[
:spend_time
]
issuable
.
spend_time
(
params
.
delete
(
:spend_time
),
current_user
)
end
time_spent
=
params
.
delete
(
:spend_time
)
issuable
.
spend_time
(
time_spent
,
current_user
)
if
time_spent
end
def
has_changes?
(
issuable
,
old_labels:
[])
...
...
app/services/slash_commands/interpret_service.rb
View file @
4d681488
...
...
@@ -269,9 +269,10 @@ module SlashCommands
command
:spend
do
|
raw_duration
|
reduce_time
=
raw_duration
.
sub!
(
/\A-/
,
''
)
time_spent
=
ChronicDuration
.
parse
(
raw_duration
,
default_unit:
'hours'
)
rescue
nil
time_spent
*=
-
1
if
time_spent
&&
reduce_time
if
time_spent
time_spent
*=
-
1
if
reduce_time
@updates
[
:spend_time
]
=
time_spent
end
end
...
...
app/services/system_note_service.rb
View file @
4d681488
...
...
@@ -126,10 +126,10 @@ module SystemNoteService
def
change_time_estimate
(
noteable
,
project
,
author
)
parsed_time
=
ChronicDuration
.
output
(
noteable
.
time_estimate
,
format: :short
)
body
=
if
parsed_time
"Changed time estimate of this
#{
noteable
.
human_class_name
}
to
#{
parsed_time
}
"
else
body
=
if
noteable
.
time_estimate
==
0
"Removed time estimate on this
#{
noteable
.
human_class_name
}
"
else
"Changed time estimate of this
#{
noteable
.
human_class_name
}
to
#{
parsed_time
}
"
end
create_note
(
noteable:
noteable
,
project:
project
,
author:
author
,
note:
body
)
...
...
@@ -155,7 +155,7 @@ module SystemNoteService
body
=
"Removed time spent on this
#{
noteable
.
human_class_name
}
"
else
parsed_time
=
ChronicDuration
.
output
(
time_spent
.
abs
,
format: :short
)
action
=
time_spent
>
0
?
'Added'
:
'Sub
s
tracted'
action
=
time_spent
>
0
?
'Added'
:
'Subtracted'
body
=
"
#{
action
}
#{
parsed_time
}
of time spent on this
#{
noteable
.
human_class_name
}
"
end
...
...
spec/factories/timelogs.rb
View file @
4d681488
...
...
@@ -3,6 +3,7 @@
FactoryGirl
.
define
do
factory
:timelog
do
time_spent
3600
user
association
:trackable
,
factory: :issue
end
end
spec/models/concerns/issuable_spec.rb
View file @
4d681488
...
...
@@ -389,9 +389,14 @@ describe Issue, "Issuable" do
let
(
:user
)
{
create
(
:user
)
}
let
(
:issue
)
{
create
(
:issue
)
}
def
spend_time
(
seconds
)
issue
.
spend_time
(
seconds
,
user
)
issue
.
save!
end
context
'adding time'
do
it
'should update the total time spent'
do
issue
.
spend_time!
(
1800
,
user
)
spend_time
(
1800
)
expect
(
issue
.
total_time_spent
).
to
eq
(
1800
)
end
...
...
@@ -399,18 +404,18 @@ describe Issue, "Issuable" do
context
'substracting time'
do
before
do
issue
.
spend_time!
(
1800
,
user
)
spend_time
(
1800
)
end
it
'should update the total time spent'
do
issue
.
spend_time!
(
-
900
,
user
)
spend_time
(
-
900
)
expect
(
issue
.
total_time_spent
).
to
eq
(
900
)
end
context
'when time to substract exceeds the total time spent'
do
it
'should not alter the total time spent'
do
issue
.
spend_time!
(
-
3600
,
user
)
spend_time
(
-
3600
)
expect
(
issue
.
total_time_spent
).
to
eq
(
1800
)
end
...
...
spec/models/timelog_spec.rb
View file @
4d681488
...
...
@@ -6,4 +6,5 @@ RSpec.describe Timelog, type: :model do
it
{
is_expected
.
to
be_valid
}
it
{
is_expected
.
to
validate_presence_of
(
:time_spent
)
}
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
end
spec/services/slash_commands/interpret_service_spec.rb
View file @
4d681488
...
...
@@ -211,7 +211,7 @@ describe SlashCommands::InterpretService, services: true do
end
shared_examples
'estimate command'
do
it
'populates time_estimate:
"3600"
if content contains /estimate 1h'
do
it
'populates time_estimate:
3600
if content contains /estimate 1h'
do
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
time_estimate:
3600
)
...
...
@@ -219,7 +219,7 @@ describe SlashCommands::InterpretService, services: true do
end
shared_examples
'spend command'
do
it
'populates spend_time:
{ seconds: 3600, user: user }
if content contains /spend 1h'
do
it
'populates spend_time:
3600
if content contains /spend 1h'
do
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
spend_time:
3600
)
...
...
@@ -227,7 +227,7 @@ describe SlashCommands::InterpretService, services: true do
end
shared_examples
'spend command with negative time'
do
it
'populates spend_time:
{ seconds: -1800, user: user }
if content contains /spend -30m'
do
it
'populates spend_time:
-1800
if content contains /spend -30m'
do
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
spend_time:
-
1800
)
...
...
@@ -235,7 +235,7 @@ describe SlashCommands::InterpretService, services: true do
end
shared_examples
'remove_estimate command'
do
it
'populates time_estimate:
"0"
if content contains /remove_estimate'
do
it
'populates time_estimate:
0
if content contains /remove_estimate'
do
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
time_estimate:
0
)
...
...
@@ -243,7 +243,7 @@ describe SlashCommands::InterpretService, services: true do
end
shared_examples
'remove_time_spent command'
do
it
'populates spend_time:
":reset"
if content contains /remove_time_spent'
do
it
'populates spend_time:
:reset
if content contains /remove_time_spent'
do
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
spend_time: :reset
)
...
...
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