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.
-
#post_messages ⇒ Bool
Allows you to specify whether default messages should be posted when parsing.
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 25 |
# File 'lib/xcodebuild/plugin.rb', line 18 def initialize(arg) super @warning_count = 0 @error_count = 0 @test_failures_count = 0 @xcodebuild_json = nil @post_messages = true end |
Instance Attribute Details
#build_title ⇒ String
Allows you to specify a build title to prefix all the reported messages.
30 31 32 |
# File 'lib/xcodebuild/plugin.rb', line 30 def build_title @build_title end |
#json_file ⇒ Object
Allows you to specify an xcodebuild JSON file location to parse.
33 34 35 |
# File 'lib/xcodebuild/plugin.rb', line 33 def json_file @json_file end |
#post_messages ⇒ Bool
Allows you to specify whether default messages should be posted when parsing
46 47 48 |
# File 'lib/xcodebuild/plugin.rb', line 46 def @post_messages end |
Class Method Details
.instance_name ⇒ Object
125 126 127 |
# File 'lib/xcodebuild/plugin.rb', line 125 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.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/xcodebuild/plugin.rb', line 68 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.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/xcodebuild/plugin.rb', line 91 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/xcodebuild/plugin.rb', line 51 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.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/xcodebuild/plugin.rb', line 114 def perfect_build is_perfect_build = @warning_count == 0 && @error_count == 0 && @test_failures_count == 0 if = Array.new .push (@build_title) unless @build_title.nil? .push ("Perfect build 👍🏻") (.reject(&:empty?).join(" ")) if is_perfect_build end return is_perfect_build end |