Class: SystemNotes::TimeTrackingService

Inherits:
BaseService show all
Defined in:
app/services/system_notes/time_tracking_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#author, #container, #group, #noteable, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

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: author, project: project)
  end

  work_item_activity_counter.track_work_item_date_changed_action(author: author) if noteable.is_a?(WorkItem)

  create_note(
    NoteSummary.new(noteable, project, author, changed_date_body(changed_dates), action: 'start_date_or_due_date')
  )
end

#change_time_estimateObject

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
# File 'app/services/system_notes/time_tracking_service.rb', line 45

def change_time_estimate
  if noteable.is_a?(Issue)
    issue_activity_counter.track_issue_time_estimate_changed_action(author: author, project: project)
  end

  create_note(NoteSummary.new(noteable, project, author, time_estimate_system_note, action: 'time_tracking'))
end

#change_time_spentObject

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



64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/services/system_notes/time_tracking_service.rb', line 64

def change_time_spent
  update_activity_counter
  time_spent = noteable.time_spent

  if time_spent == :reset
    body = "removed time spent"
    create_note(NoteSummary.new(noteable, project, author, body, action: 'time_tracking'))
  else
    spent_at = noteable.spent_at
    time_spent_note(time_spent, spent_at)
  end
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



88
89
90
91
92
93
94
# File 'app/services/system_notes/time_tracking_service.rb', line 88

def created_timelog(timelog)
  time_spent = timelog.time_spent
  spent_at = timelog.spent_at

  update_activity_counter
  time_spent_note(time_spent, spent_at)
end

#remove_timelog(timelog) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'app/services/system_notes/time_tracking_service.rb', line 96

def remove_timelog(timelog)
  time_spent = timelog.time_spent
  spent_at = timelog.spent_at

  parsed_time = Gitlab::TimeTrackingFormatter.output(time_spent)

  body = "deleted #{parsed_time} of spent time from #{formatted_spent_at(spent_at)}"
  create_note(NoteSummary.new(noteable, project, author, body, action: 'time_tracking'))
end