Class: SystemNotes::TimeTrackingService
- Inherits:
-
BaseService
- Object
- BaseService
- SystemNotes::TimeTrackingService
- Defined in:
- app/services/system_notes/time_tracking_service.rb
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
-
#change_start_date_or_due_date(changed_dates = {}) ⇒ Object
“changed start date to September 20, 2018 and changed due date to September 25, 2018”.
-
#change_time_estimate ⇒ Object
Called when the estimated time of a Noteable is changed.
-
#change_time_spent ⇒ Object
Called when the spent time of a Noteable is changed.
-
#created_timelog(timelog) ⇒ Object
Called when a timelog is added to an issuable.
- #remove_timelog(timelog) ⇒ Object
Methods inherited from BaseService
Constructor Details
This class inherits a constructor from SystemNotes::BaseService
Instance Method Details
#change_start_date_or_due_date(changed_dates = {}) ⇒ Object
“changed start date to September 20, 2018 and changed due date to September 25, 2018”
Returns the created Note object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/system_notes/time_tracking_service.rb', line 19 def change_start_date_or_due_date(changed_dates = {}) return if changed_dates.empty? # Using instance_of because WorkItem < Issue. We don't want to track work item updates as issue updates if noteable.instance_of?(Issue) && changed_dates.key?('due_date') issue_activity_counter.track_issue_due_date_changed_action(author: , project: project) end work_item_activity_counter.track_work_item_date_changed_action(author: ) if noteable.is_a?(WorkItem) create_note( NoteSummary.new(noteable, project, , changed_date_body(changed_dates), action: 'start_date_or_due_date') ) end |
#change_time_estimate ⇒ Object
Called when the estimated time of a Noteable is changed
time_estimate - Estimated time
Example Note text:
"removed time estimate"
"changed time estimate to 3d 5h"
Returns the created Note object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/system_notes/time_tracking_service.rb', line 45 def change_time_estimate parsed_time = Gitlab::TimeTrackingFormatter.output(noteable.time_estimate) body = if noteable.time_estimate == 0 "removed time estimate" else "changed time estimate to #{parsed_time}" end if noteable.is_a?(Issue) issue_activity_counter.track_issue_time_estimate_changed_action(author: , project: project) end create_note(NoteSummary.new(noteable, project, , body, action: 'time_tracking')) end |
#change_time_spent ⇒ Object
Called when the spent time of a Noteable is changed
time_spent - Spent time
Example Note text:
"removed time spent"
"added 2h 30m of time spent"
Returns the created Note object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/services/system_notes/time_tracking_service.rb', line 71 def change_time_spent time_spent = noteable.time_spent if time_spent == :reset body = "removed time spent" else spent_at = noteable.spent_at&.to_date parsed_time = Gitlab::TimeTrackingFormatter.output(time_spent.abs) action = time_spent > 0 ? 'added' : 'subtracted' text_parts = ["#{action} #{parsed_time} of time spent"] text_parts << "at #{spent_at}" if spent_at && spent_at != DateTime.current.to_date body = text_parts.join(' ') end if noteable.is_a?(Issue) issue_activity_counter.track_issue_time_spent_changed_action(author: , project: project) end create_note(NoteSummary.new(noteable, project, , body, action: 'time_tracking')) end |
#created_timelog(timelog) ⇒ Object
Called when a timelog is added to an issuable
timelog - Added timelog
Example Note text:
"subtracted 1h 15m of time spent"
"added 2h 30m of time spent"
Returns the created Note object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/services/system_notes/time_tracking_service.rb', line 104 def created_timelog(timelog) time_spent = timelog.time_spent spent_at = timelog.spent_at&.to_date parsed_time = Gitlab::TimeTrackingFormatter.output(time_spent.abs) action = time_spent > 0 ? 'added' : 'subtracted' text_parts = ["#{action} #{parsed_time} of time spent"] text_parts << "at #{spent_at}" if spent_at && spent_at != DateTime.current.to_date body = text_parts.join(' ') if noteable.is_a?(Issue) issue_activity_counter.track_issue_time_spent_changed_action(author: , project: project) end create_note(NoteSummary.new(noteable, project, , body, action: 'time_tracking')) end |
#remove_timelog(timelog) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/services/system_notes/time_tracking_service.rb', line 121 def remove_timelog(timelog) time_spent = timelog.time_spent spent_at = timelog.spent_at&.to_date parsed_time = Gitlab::TimeTrackingFormatter.output(time_spent) body = "deleted #{parsed_time} of spent time" body += " from #{spent_at}" if spent_at create_note(NoteSummary.new(noteable, project, , body, action: 'time_tracking')) end |