Class: Fastlane::CrashlyticsBetaInfoCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/setup/crashlytics_beta_info_collector.rb

Instance Method Summary collapse

Constructor Details

#initialize(project_parser, user_email_fetcher, ui) ⇒ CrashlyticsBetaInfoCollector

Returns a new instance of CrashlyticsBetaInfoCollector.



3
4
5
6
7
8
9
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 3

def initialize(project_parser, user_email_fetcher, ui)
  @project_parser = project_parser
  @user_email_fetcher = user_email_fetcher
  @ui = ui

  @shown_fabric_org_help = false
end

Instance Method Details

#collect_info_into(info) ⇒ Object

Parameters:

  • info

    CrashlyticsBetaInfo to supplement with needed info that is collected



12
13
14
15
16
17
18
19
20
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 12

def collect_info_into(info)
  if user_provided_invalid_values?(info) || !info.has_all_detectable_values?
    @ui.message "\nTrying to discover Beta by Crashlytics info from your project...".cyan
    parse_project_info_into(info)
    fetch_email_into(info)
  end

  prompt_for_missing_values(info)
end

#fetch_email_into(info) ⇒ Object



68
69
70
71
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 68

def fetch_email_into(info)
  email = @user_email_fetcher.fetch
  info.emails = [email] if !info.emails_valid? && email
end

#parse_project_info_into(info) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 53

def parse_project_info_into(info)
  begin
    info_hash = @project_parser.parse
  rescue => ex
    @ui.important ex.message
  end

  if info_hash
    info.api_key = info_hash[:api_key] unless info.api_key_valid?
    info.build_secret = info_hash[:build_secret] unless info.build_secret_valid?
    info.crashlytics_path = info_hash[:crashlytics_path] unless info.crashlytics_path_valid?
    info.schemes = info_hash[:schemes] unless info.schemes_valid?
  end
end

#prompt_for_api_key(info) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 114

def prompt_for_api_key(info)
  loop do
    info.api_key = @ui.input("\nPlease provide your Fabric organization's API Key:").strip
    break if info.api_key_valid?
    @ui.message "The API Key you provided was invalid (must be 40 characters)."
  end
end

#prompt_for_build_secret(info) ⇒ Object



122
123
124
125
126
127
128
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 122

def prompt_for_build_secret(info)
  loop do
    info.build_secret = @ui.input("\nPlease provide your Fabric organization's Build Secret:").strip
    break if info.build_secret_valid?
    @ui.message "The Build Secret you provided was invalid (must be 64 characters)."
  end
end

#prompt_for_crashlytics_path(info) ⇒ Object



130
131
132
133
134
135
136
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 130

def prompt_for_crashlytics_path(info)
  loop do
    info.crashlytics_path = @ui.input("\nPlease provide the path to Crashlytics.framework:").strip
    break if info.crashlytics_path_valid?
    @ui.message "A submit binary could not be found at the framework path you provided."
  end
end

#prompt_for_email(info) ⇒ Object



138
139
140
141
142
143
144
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 138

def prompt_for_email(info)
  loop do
    info.emails = [@ui.input("\nPlease enter an email address to distribute the beta to:").strip]
    break if info.emails_valid?
    @ui.message "You must provide an email address."
  end
end

#prompt_for_export_method(info) ⇒ Object



159
160
161
162
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 159

def prompt_for_export_method(info)
  @ui.important "The export method you entered was not valid."
  info.export_method = @ui.choose("\nWhich export method would you like to use?", CrashlyticsBetaInfo::EXPORT_METHODS)
end

#prompt_for_missing_values(info) ⇒ Object



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
99
100
101
102
103
104
105
106
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 73

def prompt_for_missing_values(info)
  if !info.crashlytics_path || !info.crashlytics_path_valid?
    @ui.important "A Crashlytics submit binary path couldn't be discovered from your project 🔍"
    prompt_for_crashlytics_path(info)
  end

  if !info.api_key || !info.api_key_valid?
    @ui.important "Your Fabric organization's API Key couldn't be discovered from your project 🔍"
    show_fabric_org_help unless @shown_fabric_org_help
    prompt_for_api_key(info)
  end

  if !info.build_secret || !info.build_secret_valid?
    @ui.important "Your Fabric organization's Build Secret couldn't be discovered from your project 🔍"
    show_fabric_org_help unless @shown_fabric_org_help
    prompt_for_build_secret(info)
  end

  if (!info.emails || !info.emails_valid?) && !info.groups
    @ui.important "Your email address couldn't be discovered from your project 🔍"
    prompt_for_email(info)
  end

  if !info.schemes || info.schemes.empty?
    @ui.important "Your scheme couldn't be discovered from your project 🔍"
    prompt_for_schemes(info)
  elsif info.schemes.size > 1
    @ui.important "Multiple schemes were discovered from your project 🔍"
    prompt_for_schemes(info)
  end

  info.export_method = 'development' unless info.export_method
  prompt_for_export_method(info) unless info.export_method_valid?
end

#prompt_for_schemes(info) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 146

def prompt_for_schemes(info)
  current_schemes = info.schemes
  if current_schemes.nil? || current_schemes.empty?
    loop do
      info.schemes = [@ui.input("\nPlease enter the name of the scheme you would like to use:").strip]
      break if info.schemes_valid?
      @ui.message "You must provide a scheme name."
    end
  else
    info.schemes = [@ui.choose("\nWhich scheme would you like to use?", current_schemes)]
  end
end

#show_fabric_org_helpObject



108
109
110
111
112
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 108

def show_fabric_org_help
  @ui.important("\nNavigate to https://www.fabric.io/settings/organizations, select the appropriate organization,")
  @ui.important('and copy the API Key and Build Secret.')
  @shown_fabric_org_help = true
end

#user_provided_invalid_values?(info) ⇒ Boolean

Returns:

  • (Boolean)


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
# File 'lib/fastlane/setup/crashlytics_beta_info_collector.rb', line 22

def user_provided_invalid_values?(info)
  invalid = false

  if info.crashlytics_path && !info.crashlytics_path_valid?
    @ui.message "The crashlytics_path you provided (#{info.crashlytics_path}) is not valid."
    invalid = true
  end

  if info.api_key && !info.api_key_valid?
    @ui.message "The api_key you provided (#{info.api_key}) is not valid."
    invalid = true
  end

  if info.build_secret && !info.build_secret_valid?
    @ui.message "The build_secret you provided (#{info.build_secret}) is not valid."
    invalid = true
  end

  if info.emails && !info.emails_valid?
    @ui.message "The email you provided (#{info.emails.first}) is not valid."
    invalid = true
  end

  if info.schemes && !info.schemes_valid?
    @ui.message "The scheme you provided (#{info.schemes.first}) is not valid."
    invalid = true
  end

  invalid
end