Class: Precheck::Runner

Inherits:
Object
  • Object
show all
Defined in:
precheck/lib/precheck/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#spaceshipObject

Returns the value of attribute spaceship.



11
12
13
# File 'precheck/lib/precheck/runner.rb', line 11

def spaceship
  @spaceship
end

Instance Method Details

#appObject



162
163
164
# File 'precheck/lib/precheck/runner.rb', line 162

def app
  Spaceship::Tunes::Application.find(Precheck.config[:app_identifier])
end

#build_items_not_checked_table(items_not_checked: nil) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
# File 'precheck/lib/precheck/runner.rb', line 149

def build_items_not_checked_table(items_not_checked: nil)
  rows = []
  items_not_checked.each do |item|
    rows << [item.item_name, item.friendly_name]
  end

  return Terminal::Table.new(
    title: "Not analyzed".yellow,
    headings: ["Name", "Friendly name"],
    rows: FastlaneCore::PrintTable.transform_output(rows)
  ).to_s
end

#build_potential_problems_table(processor_result: nil) ⇒ Object



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
94
95
96
97
98
# File 'precheck/lib/precheck/runner.rb', line 65

def build_potential_problems_table(processor_result: nil)
  error_results = processor_result.error_results
  warning_results = processor_result.warning_results

  rows = []

  warning_results.each do |rule, results|
    results.each do |result|
      rows << [result.item.friendly_name, result.rule_return.failure_data.yellow]
    end
  end

  error_results.each do |rule, results|
    results.each do |result|
      rows << [result.item.friendly_name, result.rule_return.failure_data.red]
    end
  end

  if rows.length == 0
    return nil
  else
    title_text = "Potential problems"
    if error_results.length > 0
      title_text = title_text.red
    else
      title_text = title_text.yellow
    end
    return Terminal::Table.new(
      title: title_text,
      headings: ["Field", "Failure reason"],
      rows: FastlaneCore::PrintTable.transform_output(rows)
    ).to_s
  end
end

#check_for_rule_violations(app: nil, app_version: nil) ⇒ Object



100
101
102
103
104
105
106
# File 'precheck/lib/precheck/runner.rb', line 100

def check_for_rule_violations(app: nil, app_version: nil)
  Precheck::RuleProcessor.process_app_and_version(
    app: app,
    app_version: app_version,
    rules: Precheck::Options.rules
  )
end

#ensure_app_exists!Object

Makes sure the current App ID exists. If not, it will show an appropriate error message



171
172
173
174
# File 'precheck/lib/precheck/runner.rb', line 171

def ensure_app_exists!
  return if app
  UI.user_error!("Could not find app with App Identifier '#{Precheck.config[:app_identifier]}'")
end

#latest_app_versionObject



166
167
168
# File 'precheck/lib/precheck/runner.rb', line 166

def latest_app_version
  @latest_version ||= app.latest_version
end


60
61
62
63
# File 'precheck/lib/precheck/runner.rb', line 60

def print_items_not_checked(processor_result: nil)
  names = processor_result.items_not_checked.map(&:friendly_name)
  UI.message("😶  Metadata fields not checked by any rule: #{names.join(', ')}".yellow) if names.length > 0
end

#rendered_failed_results_table(failed_results: nil) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
# File 'precheck/lib/precheck/runner.rb', line 108

def rendered_failed_results_table(failed_results: nil)
  rows = []
  failed_results.each do |failed_result|
    rows << [failed_result.rule.key, failed_result.item.friendly_name]
  end

  return Terminal::Table.new(
    title: "Failed rules".red,
    headings: ["Name", "App metadata field: (language code)"],
    rows: FastlaneCore::PrintTable.transform_output(rows)
  ).to_s
end

#rendered_rules_checked_table(rules_checked: nil) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
# File 'precheck/lib/precheck/runner.rb', line 121

def rendered_rules_checked_table(rules_checked: nil)
  rows = []
  rules_checked.each do |rule|
    rows << [rule.key, rule.description]
  end

  return Terminal::Table.new(
    title: "Enabled rules".green,
    headings: ["Name", "Description"],
    rows: FastlaneCore::PrintTable.transform_output(rows)
  ).to_s
end

#rendered_skipped_rules_table(skipped_rules: nil) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'precheck/lib/precheck/runner.rb', line 134

def rendered_skipped_rules_table(skipped_rules: nil)
  return nil if skipped_rules.empty?

  rows = []
  skipped_rules.each do |rule|
    rows << [rule.key, rule.description]
  end

  return Terminal::Table.new(
    title: "Skipped rules".yellow,
    headings: ["Name", "Description"],
    rows: FastlaneCore::PrintTable.transform_output(rows)
  ).to_s
end

#runObject

Uses the spaceship to download app metadata and then run all rule checkers



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
# File 'precheck/lib/precheck/runner.rb', line 14

def run
  Precheck.config.load_configuration_file(Precheck.precheckfile_name)

  FastlaneCore::PrintTable.print_values(config: Precheck.config,
                                     hide_keys: [:output_path],
                                         title: "Summary for precheck #{Fastlane::VERSION}")

  unless Spaceship::Tunes.client
    UI.message("Starting login with user '#{Precheck.config[:username]}'")
    Spaceship::Tunes.(Precheck.config[:username])
    Spaceship::Tunes.select_team

    UI.message("Successfully logged in")
  end

  UI.message("Checking app for precheck rule violations")

  ensure_app_exists!

  processor_result = check_for_rule_violations(app: app, app_version: latest_app_version)

  if processor_result.items_not_checked?
    print_items_not_checked(processor_result: processor_result)
  end

  if processor_result.has_errors_or_warnings?
    summary_table = build_potential_problems_table(processor_result: processor_result)
    puts(summary_table)
  end

  if processor_result.should_trigger_user_error?
    UI.user_error!("precheck 👮‍♀️ 👮  found one or more potential problems that must be addressed before submitting to review")
    return false
  end

  if processor_result.has_errors_or_warnings?
    UI.important("precheck 👮‍♀️ 👮  found one or more potential metadata problems, but this won't prevent fastlane from completing 👍".yellow)
  end

  if !processor_result.has_errors_or_warnings? && !processor_result.items_not_checked?
    UI.message("precheck 👮‍♀️ 👮  finished without detecting any potential problems 🛫".green)
  end

  return true
end