File: flow_advisor.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (93 lines) | stat: -rwxr-xr-x 2,562 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# frozen_string_literal: true

require_relative '../helpers'
require_relative '../text/flow_advisor'

# Entrypoint for help flow, which directs the user to the
# correct flow or documentation based on their goal
module InternalEventsCli
  module Flows
    class FlowAdvisor
      include Helpers
      include Text::FlowAdvisor

      attr_reader :cli

      def initialize(cli)
        @cli = cli
      end

      def run
        return use_case_error unless goal_is_tracking_usage?
        return use_case_error unless usage_trackable_with_internal_events?

        event_already_tracked? ? proceed_to_metric_definition : proceed_to_event_definition
      end

      private

      def goal_is_tracking_usage?
        new_page!

        cli.say format_info("First, let's check your objective.\n")

        cli.yes?('Are you trying to track customer usage of a GitLab feature?', **yes_no_opts)
      end

      def usage_trackable_with_internal_events?
        new_page!

        cli.say format_info("Excellent! Let's check that this tool will fit your needs.\n")
        cli.say EVENT_TRACKING_EXAMPLES

        cli.yes?(
          'Can usage for the feature be measured with a count of specific user actions or events? ' \
            'Or counting a set of events?',
          **yes_no_opts
        )
      end

      def event_already_tracked?
        new_page!

        cli.say format_info("Super! Let's figure out if the event is already tracked & usable.\n")
        cli.say EVENT_EXISTENCE_CHECK_INSTRUCTIONS

        cli.yes?('Is the event already tracked?', **yes_no_opts)
      end

      def use_case_error
        new_page!

        cli.error("Oh no! This probably isn't the tool you need!\n")
        cli.say ALTERNATE_RESOURCES_NOTICE
        cli.say feedback_notice
      end

      def proceed_to_metric_definition
        new_page!

        cli.say format_info("Amazing! The next step is adding a new metric! (~8-15 min)\n")

        return not_ready_error('New Metric') unless cli.yes?(format_prompt('Ready to start?'))

        MetricDefiner.new(cli).run
      end

      def proceed_to_event_definition
        new_page!

        cli.say format_info("Okay! The next step is adding a new event! (~5-10 min)\n")

        return not_ready_error('New Event') unless cli.yes?(format_prompt('Ready to start?'))

        EventDefiner.new(cli).run
      end

      def not_ready_error(description)
        cli.say "\nNo problem! When you're ready, run the CLI & select '#{description}'\n"
        cli.say feedback_notice
      end
    end
  end
end