Class: BranchIOCLI::Command::ValidateCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/branch_io_cli/command/validate_command.rb

Instance Attribute Summary

Attributes inherited from Command

#config, #options

Instance Method Summary collapse

Methods inherited from Command

available_options, command_name, configuration_class, #env, examples, #helper, #initialize, #patch_helper, return_value, #tool_helper

Constructor Details

This class inherits a constructor from BranchIOCLI::Command::Command

Instance Method Details

#project_matches_keys?(configurations) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/branch_io_cli/command/validate_command.rb', line 70

def project_matches_keys?(configurations)
  expected_keys = [config.live_key, config.test_key].compact
  return true if expected_keys.empty?

  # Validate the keys in the project against those passed in by the user.
  branch_keys = helper.branch_keys_from_project(configurations).sort

  keys_valid = expected_keys == branch_keys

  say "\n"
  if keys_valid
    say "Branch keys from project match provided keys. ✅"
  else
    say "Branch keys from project do not match provided keys. ❌"
    say " Expected: #{expected_keys.inspect}"
    say " Actual: #{branch_keys.inspect}"
  end

  keys_valid
end

#run!Object



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
# File 'lib/branch_io_cli/command/validate_command.rb', line 4

def run!
  say "\n"

  configurations = config.configurations || config.xcodeproj.build_configurations.map(&:name)

  return false unless tool_helper.pod_install_if_required

  valid = project_matches_keys?(configurations)
  schemes_valid = uri_schemes_valid?(configurations)
  valid &&= schemes_valid

  configurations.each do |configuration|
    message = "Validating #{configuration} configuration"
    say "\n<%= color('#{message}', [BOLD, CYAN]) %>\n\n"

    config_valid = true

    unless config.domains.blank?
      domains_valid = helper.validate_project_domains(config.domains, configuration)

      if domains_valid
        say "Project domains match domains parameter. ✅"
      else
        say "Project domains do not match specified domains. ❌"
        helper.errors.each { |error| say "  #{error}" }
      end

      config_valid &&= domains_valid
    end

    if config.target.symbol_type == :application
      entitlements_valid = helper.validate_team_and_bundle_ids_from_aasa_files [], false, configuration
      unless entitlements_valid
        say "Universal Link configuration failed validation for #{configuration} configuration. ❌"
        helper.errors.each { |error| say " #{error}" }
      end

      config_valid &&= entitlements_valid

      say "Universal Link configuration passed validation for #{configuration} configuration. ✅" if config_valid
    end

    unless config.universal_links_only
      branch_config_valid = helper.project_valid? configuration
      unless branch_config_valid
        say "Branch configuration failed validation for #{configuration} configuration. ❌"
        helper.errors.each { |error| say " #{error}" }
      end

      config_valid &&= branch_config_valid

      say "Branch configuration passed validation for #{configuration} configuration. ✅" if config_valid
    end

    valid &&= config_valid
  end

  unless valid
    say "\nValidation failed. See errors above marked with ❌."
    say "Please verify your app configuration at https://dashboard.branch.io."
    say "If your Dashboard configuration is correct, br setup will fix most errors."
  end

  valid ? 0 : 1
end

#uri_schemes_valid?(configurations) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/branch_io_cli/command/validate_command.rb', line 91

def uri_schemes_valid?(configurations)
  uri_schemes = helper.branch_apps_from_project(configurations).map(&:ios_uri_scheme).compact.uniq
  expected = uri_schemes.map { |s| BranchIOCLI::Configuration::Configuration.uri_scheme_without_suffix(s) }.sort
  return true if expected.empty?

  actual = helper.uri_schemes_from_project(configurations).sort
  valid = (expected - actual).empty?
  if valid
    say "URI schemes from project match schemes from Dashboard. ✅"
  else
    say "URI schemes from project do not match schemes from Dashboard. ❌"
    say " Expected: #{expected.inspect}"
    say " Actual: #{actual.inspect}"
  end

  valid
end