Class: Gitlab::WorkItems::TimeTrackingExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/work_items/time_tracking_extractor.rb

Constant Summary collapse

TIME_TRACKING_REGEX =
/@(\d+(?:mo|[dhms])(?:\d+(?:mo|[dhms]))*)/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, current_user) ⇒ TimeTrackingExtractor

Returns a new instance of TimeTrackingExtractor.



13
14
15
16
17
# File 'lib/gitlab/work_items/time_tracking_extractor.rb', line 13

def initialize(project, current_user)
  @project = project
  @current_user = current_user
  @extractor = Gitlab::ReferenceExtractor.new(project, current_user)
end

Class Method Details

.reference_patternObject

Expose the time tracking regex pattern to be used in cross-reference detection



9
10
11
# File 'lib/gitlab/work_items/time_tracking_extractor.rb', line 9

def self.reference_pattern
  TIME_TRACKING_REGEX
end

Instance Method Details

#extract_time_spent(message) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gitlab/work_items/time_tracking_extractor.rb', line 19

def extract_time_spent(message)
  return {} if message.blank?

  time_spent = find_time_spent(message)
  return {} unless time_spent

  extractor.analyze(message)
  referenced_issues = (extractor.issues + extractor.work_items).uniq(&:id)

  referenced_issues.index_with do |_issue|
    time_spent
  end
end