Class: Dri::Commands::Fetch::FeatureFlags

Inherits:
Dri::Command show all
Includes:
Utils::Constants::FeatureFlag, Utils::Table
Defined in:
lib/dri/commands/fetch/featureflags.rb

Constant Summary

Constants included from Utils::Constants::FeatureFlag

Utils::Constants::FeatureFlag::TITLE_SUBSTRINGS

Instance Method Summary collapse

Methods included from Utils::Table

#print_table

Methods inherited from Dri::Command

#add_color, #api_client, #bold, #command, #config, #cursor, #editor, #emoji, #handover_report_path, #logger, #ops_token, #pastel, #profile, #prompt, #spinner, #timezone, #token, #username, #verify_config_exists

Constructor Details

#initialize(options) ⇒ FeatureFlags

Returns a new instance of FeatureFlags.



15
16
17
18
# File 'lib/dri/commands/fetch/featureflags.rb', line 15

def initialize(options)
  @options = options
  @today_iso_format = Time.now.strftime('%Y-%m-%dT00:00:00Z')
end

Instance Method Details

#execute(_input: $stdin, output: $stdout) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



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
# File 'lib/dri/commands/fetch/featureflags.rb', line 20

def execute(_input: $stdin, output: $stdout) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  verify_config_exists

  summary = add_color('Summary', :bright_yellow)
  changed_on = add_color('Changed(UTC)', :bright_yellow)
  url = add_color('URL', :bright_yellow)

  report = Dri::FeatureFlagReport.new

  headers = [summary, changed_on, url]

  logger.info "Fetching today's feature flag changes..."

  spinner.run do
    response = api_client.fetch_feature_flag_logs(@today_iso_format)

    if response.empty?
      logger.info 'It\'s been quiet...no feature flag changes for today 👀'
      break
    end

    response.each do |feature_flag|
      next unless TITLE_SUBSTRINGS.any? { |substr| feature_flag.title.include?(substr) }

      report.add_change(feature_flag)
    end
  end

  print_results('Production', headers, report.prod, output) unless report.prod.empty?
  print_results('Staging', headers, report.staging, output) unless report.staging.empty?
  print_results('Staging Ref', headers, report.staging_ref, output) unless report.staging_ref.empty?
  print_results('Preprod', headers, report.preprod, output) unless report.preprod.empty?
end