Class: FastlaneCore::ToolCollector
- Inherits:
-
Object
- Object
- FastlaneCore::ToolCollector
- Defined in:
- lib/fastlane_core/tool_collector.rb
Constant Summary collapse
- HOST_URL =
ENV['FASTLANE_ENHANCER_URL'] || "https://fastlane-enhancer.herokuapp.com"
Instance Attribute Summary collapse
-
#crash ⇒ Object
readonly
This is the newer field for tracking only uncontrolled exceptions.
-
#error ⇒ Object
readonly
This is the original error reporting mechanism, which has always represented either controlled (UI.user_error!), or uncontrolled (UI.crash!, anything else) exceptions.
Class Method Summary collapse
Instance Method Summary collapse
- #determine_version(name) ⇒ Object
-
#did_crash(name) ⇒ Object
Call when the problem is an uncaught/uncontrolled exception (e.g. via UI.crash!).
- #did_finish ⇒ Object
- #did_launch_action(name) ⇒ Object
-
#did_raise_error(name) ⇒ Object
Call when the problem is a caught/controlled exception (e.g. via UI.user_error!).
- #did_show_message? ⇒ Boolean
-
#initialize ⇒ ToolCollector
constructor
A new instance of ToolCollector.
-
#is_official?(name) ⇒ Boolean
Override this in subclasses.
- #launches ⇒ Object
-
#name_to_track(name) ⇒ Object
Returns nil if we shouldn’t track this action Returns a (maybe modified) name that should be sent to the enhancer web service Modificiation is used to prefix the action name with the name of the plugin.
- #show_message ⇒ Object
-
#versions ⇒ Object
Maintains a hash of tool names to their detected versions.
Constructor Details
#initialize ⇒ ToolCollector
Returns a new instance of ToolCollector.
23 24 25 |
# File 'lib/fastlane_core/tool_collector.rb', line 23 def initialize @crash = false end |
Instance Attribute Details
#crash ⇒ Object (readonly)
This is the newer field for tracking only uncontrolled exceptions.
This is written to only when ‘did_crash` is called, and therefore excludes controlled exceptions.
This value is a boolean, which is true if the error was an uncontrolled exception
21 22 23 |
# File 'lib/fastlane_core/tool_collector.rb', line 21 def crash @crash end |
#error ⇒ Object (readonly)
This is the original error reporting mechanism, which has always represented either controlled (UI.user_error!), or uncontrolled (UI.crash!, anything else) exceptions.
Thus, if you call ‘did_crash`, it will record the failure both here, and in the newer, more specific `crash` field.
This value is a String, which is the name of the tool that caused the error
13 14 15 |
# File 'lib/fastlane_core/tool_collector.rb', line 13 def error @error end |
Class Method Details
.determine_version(name) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/fastlane_core/tool_collector.rb', line 139 def self.determine_version(name) begin name = name.to_s.downcase # We need to pre-load the version file because tools that are invoked through their actions # will not yet have run their action, and thus will not yet have loaded the file which defines # the module and constant we need. require File.join(name, "version") # Go from :foo_bar to 'FooBar' module_name = name.fastlane_module # Look up the VERSION constant defined for the given tool name, # or return 'unknown' if we can't find it where we'd expect if Kernel.const_defined?(module_name) tool_module = Kernel.const_get(module_name) if tool_module.const_defined?('VERSION') return tool_module.const_get('VERSION') end end rescue LoadError # If there is no version file to load, this is not a tool for which # we can report a particular version end return nil end |
Instance Method Details
#determine_version(name) ⇒ Object
135 136 137 |
# File 'lib/fastlane_core/tool_collector.rb', line 135 def determine_version(name) self.class.determine_version(name) end |
#did_crash(name) ⇒ Object
Call when the problem is an uncaught/uncontrolled exception (e.g. via UI.crash!)
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fastlane_core/tool_collector.rb', line 46 def did_crash(name) name = name_to_track(name.to_sym) return unless name # Write to the @error field to maintain the historical behavior of the field, so # that the server gets the same data in that field from old and new clients @error = name # Also specifically note that this exception was uncontrolled in the @crash field @crash = true end |
#did_finish ⇒ Object
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 |
# File 'lib/fastlane_core/tool_collector.rb', line 57 def did_finish return false if ENV["FASTLANE_OPT_OUT_USAGE"] if ! and !Helper.is_ci? end require 'excon' url = HOST_URL + '/did_launch?' url += URI.encode_www_form( versions: versions.to_json, steps: launches.to_json, error: @error, crash: @crash ? @error : nil ) if Helper.is_test? # don't send test data return url else fork do begin Excon.post(url) rescue # we don't want to show a stack trace if something goes wrong end end return true end rescue # We don't care about connection errors end |
#did_launch_action(name) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/fastlane_core/tool_collector.rb', line 27 def did_launch_action(name) name = name_to_track(name.to_sym) return unless name launches[name] += 1 versions[name] ||= determine_version(name) end |
#did_raise_error(name) ⇒ Object
Call when the problem is a caught/controlled exception (e.g. via UI.user_error!)
36 37 38 39 40 41 42 43 |
# File 'lib/fastlane_core/tool_collector.rb', line 36 def did_raise_error(name) name = name_to_track(name.to_sym) return unless name @error = name # Don't write to the @crash field so that we can distinguish this exception later # as being controlled end |
#did_show_message? ⇒ Boolean
128 129 130 131 132 133 |
# File 'lib/fastlane_core/tool_collector.rb', line 128 def path = File.join(File.('~'), '.did_show_opt_info') did_show = File.exist?(path) File.write(path, '1') unless did_show did_show end |
#is_official?(name) ⇒ Boolean
Override this in subclasses
116 117 118 |
# File 'lib/fastlane_core/tool_collector.rb', line 116 def is_official?(name) return true end |
#launches ⇒ Object
98 99 100 |
# File 'lib/fastlane_core/tool_collector.rb', line 98 def launches @launches ||= Hash.new(0) end |
#name_to_track(name) ⇒ Object
Returns nil if we shouldn’t track this action Returns a (maybe modified) name that should be sent to the enhancer web service Modificiation is used to prefix the action name with the name of the plugin
123 124 125 126 |
# File 'lib/fastlane_core/tool_collector.rb', line 123 def name_to_track(name) return nil unless is_official?(name) name end |
#show_message ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/fastlane_core/tool_collector.rb', line 89 def UI.("Sending Crash/Success information. More information on: https://github.com/fastlane/enhancer") UI.("No personal/sensitive data is sent. Only sharing the following:") UI.(launches) UI.(@error) if @error UI.("This information is used to fix failing tools and improve those that are most often used.") UI.("You can disable this by setting the environment variable: FASTLANE_OPT_OUT_USAGE=1") end |
#versions ⇒ Object
Maintains a hash of tool names to their detected versions.
This data is sent in the same manner as launches, as an inline form-encoded JSON value in the POST. For example:
match: '0.5.0',
fastlane: '1.86.1'
111 112 113 |
# File 'lib/fastlane_core/tool_collector.rb', line 111 def versions @versions ||= {} end |