Module: GitlabInternalEventsCli::Helpers::EventOptions

Included in:
GitlabInternalEventsCli::Helpers
Defined in:
lib/gitlab_internal_events_cli/helpers/event_options.rb

Instance Method Summary collapse

Instance Method Details

#events_by_filepath(event_paths = []) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/gitlab_internal_events_cli/helpers/event_options.rb', line 27

def events_by_filepath(event_paths = [])
  events = cli.global.events.to_h { |event| [event.file_path, event] }

  return events if event_paths.none?

  events.slice(*event_paths)
end

#generate_ai_event_suggestion(action) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gitlab_internal_events_cli/helpers/event_options.rb', line 35

def generate_ai_event_suggestion(action)
  ai_tracking_url = format_info('https://docs.gitlab.com/development/ai_features/usage_tracking/#adding-new-event-for-tracking')
  ai_tracking_module = format_info('Gitlab::Tracking::AiTracking')

  <<~TEXT
    #{divider}
    #{format_info('AI Tracking')}

      Events with #{format_warning('classification: duo')} are required to be registered in #{ai_tracking_module}, you can do this in the following steps:

      - #{format_info('Add the event name and the unique AI feature ID:')}

        #{format_info('# Tracking without metadata')}
          events(#{action}: AI_FEATURE_ID)

        or, if your event has additional metadata:

        #{format_info('# Tracking with metadata')}
          events(#{event.action}: AI_FEATURE_ID) do |context|
            { job_id: context['job'].id }
          end

      Learn more: #{ai_tracking_url}
  TEXT
end

#generate_python_adviceObject



61
62
63
64
65
66
67
68
69
# File 'lib/gitlab_internal_events_cli/helpers/event_options.rb', line 61

def generate_python_advice
  <<~TEXT
    \n
    #{divider}
    #{format_info('Python codebase')}

      It seems like you are using the CLI in a python codebase. Make sure to check the python examples in the usage section.
  TEXT
end

#get_event_options(events) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gitlab_internal_events_cli/helpers/event_options.rb', line 7

def get_event_options(events)
  options = events.filter_map do |(path, event)|
    next if duplicate_events?(event.action, events.values)

    description = format_help(" - #{trim_description(event.description)}")

    {
      name: "#{format_event_name(event)}#{description}",
      value: path
    }
  end

  options.sort_by do |option|
    category = events.dig(option[:value], 'category')
    internal_events = events.dig(option[:value], 'internal_events')

    event_sort_param(internal_events, category, option[:name])
  end
end