Class: Danger::DangerXcodebuild
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerXcodebuild
- Defined in:
- lib/xcodebuild/plugin.rb
Overview
Exposes warnings, errors and test results. It requires a JSON generated using [xcpretty-json-formatter](github.com/marcelofabri/xcpretty-json-formatter), to be passed as an argument for it to work.
Instance Attribute Summary collapse
-
#json_file ⇒ Object
Allows you to specify an xcodebuild JSON file location to parse.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(arg) ⇒ DangerXcodebuild
constructor
A new instance of DangerXcodebuild.
-
#parse_errors ⇒ error_count
Parses and expose eventual errors.
-
#parse_tests ⇒ test_failures
Parses and exposes eventual test failures.
-
#parse_warnings ⇒ warning_count
Parses and exposes eventual warnings.
-
#perfect_build ⇒ is_perfect_build
Prints “Perfect build 👍🏻” if everything is ok after parsing.
Constructor Details
#initialize(arg) ⇒ DangerXcodebuild
Returns a new instance of DangerXcodebuild.
18 19 20 21 22 23 24 |
# File 'lib/xcodebuild/plugin.rb', line 18 def initialize(arg) super @warning_count = 0 @error_count = 0 @test_failures_count = 0 @xcodebuild_json = nil end |
Instance Attribute Details
#json_file ⇒ Object
Allows you to specify an xcodebuild JSON file location to parse.
27 28 29 |
# File 'lib/xcodebuild/plugin.rb', line 27 def json_file @json_file end |
Class Method Details
.instance_name ⇒ Object
100 101 102 |
# File 'lib/xcodebuild/plugin.rb', line 100 def self.instance_name to_s.gsub("Danger", "").danger_underscore.split("/").last end |
Instance Method Details
#parse_errors ⇒ error_count
Parses and expose eventual errors.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/xcodebuild/plugin.rb', line 54 def parse_errors errors = @xcodebuild_json["errors"].map {|x| "`#{x}`"} errors += @xcodebuild_json["compile_errors"].map {|x| "`[#{x["file_path"].split("/").last}] #{x["reason"]}`"} errors += @xcodebuild_json["file_missing_errors"].map {|x| "`[#{x["file_path"].split("/").last}] #{x["reason"]}`"} errors += @xcodebuild_json["undefined_symbols_errors"].map {|x| "`#{x["message"]}`"} errors += @xcodebuild_json["duplicate_symbols_errors"].map {|x| "`#{x["message"]}`"} if errors.count > 0 error_string = errors.count == 1 ? "error" : "errors" fail("Build failed with **#{errors.count}** #{error_string} 🚨") errors.each do |error| fail(error) end end @error_count = errors.count return @error_count end |
#parse_tests ⇒ test_failures
Parses and exposes eventual test failures.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/xcodebuild/plugin.rb', line 74 def parse_tests test_failures = Array.new @xcodebuild_json["tests_failures"].each do |key, value| test_failures += value.map {|x| "`[#{x["file_path"].split("/").last}] [#{x["test_case"]}] #{x["reason"]}`"} end if test_failures.count > 0 test_string = test_failures.count == 1 ? "error" : "errors" fail("Test execution failed with **#{test_failures.count}** #{test_string} 🚨") test_failures.each do |test_failure| fail(test_failure) end end @test_failures_count = test_failures.count return @test_failures_count end |
#parse_warnings ⇒ warning_count
Parses and exposes eventual warnings.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/xcodebuild/plugin.rb', line 40 def parse_warnings @warning_count = @xcodebuild_json["warnings"].count @warning_count = @warning_count + @xcodebuild_json["ld_warnings"].count @warning_count = @warning_count + @xcodebuild_json["compile_warnings"].count if @warning_count > 0 warning_string = @warning_count == 1 ? "warning" : "warnings" warn("Please fix **#{@warning_count}** #{warning_string} 😒") end return @warning_count end |
#perfect_build ⇒ is_perfect_build
Prints “Perfect build 👍🏻” if everything is ok after parsing.
94 95 96 97 98 |
# File 'lib/xcodebuild/plugin.rb', line 94 def perfect_build is_perfect_build = @warning_count == 0 && @error_count == 0 && @test_failures_count == 0 ("Perfect build 👍🏻") if is_perfect_build return is_perfect_build end |