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
-
#build_title ⇒ String
Allows you to specify a build title to prefix all the reported messages.
-
#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
#build_title ⇒ String
Allows you to specify a build title to prefix all the reported messages.
29 30 31 |
# File 'lib/xcodebuild/plugin.rb', line 29 def build_title @build_title end |
#json_file ⇒ Object
Allows you to specify an xcodebuild JSON file location to parse.
32 33 34 |
# File 'lib/xcodebuild/plugin.rb', line 32 def json_file @json_file end |
Class Method Details
.instance_name ⇒ Object
117 118 119 |
# File 'lib/xcodebuild/plugin.rb', line 117 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.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/xcodebuild/plugin.rb', line 62 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" = Array.new .push (@build_title) unless @build_title.nil? .push("Build failed with **#{errors.count}** #{error_string} 🚨") fail(.reject(&:empty?).join(" ")) 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.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/xcodebuild/plugin.rb', line 85 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" = Array.new .push (@build_title) unless @build_title.nil? .push("Test execution failed with **#{test_failures.count}** #{test_string} 🚨") fail(.reject(&:empty?).join(" ")) 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.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/xcodebuild/plugin.rb', line 45 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" = Array.new .push (@build_title) unless @build_title.nil? .push("Please fix **#{@warning_count}** #{warning_string} 😒") warn(.reject(&:empty?).join(" ")) end return @warning_count end |
#perfect_build ⇒ is_perfect_build
Prints “Perfect build 👍🏻” if everything is ok after parsing.
108 109 110 111 112 113 114 115 |
# File 'lib/xcodebuild/plugin.rb', line 108 def perfect_build is_perfect_build = @warning_count == 0 && @error_count == 0 && @test_failures_count == 0 = Array.new .push (@build_title) unless @build_title.nil? .push ("Perfect build 👍🏻") (.reject(&:empty?).join(" ")) if is_perfect_build return is_perfect_build end |