From 7ffb4456ded9c1c6be280e00c99cd1ed962ee8c4 Mon Sep 17 00:00:00 2001 From: Valerio Mazzeo Date: Tue, 27 Sep 2016 19:45:47 +0200 Subject: [PATCH] added ability to set a build title --- Gemfile.lock | 2 +- lib/xcodebuild/gem_version.rb | 2 +- lib/xcodebuild/plugin.rb | 25 +++++++++++++++++++++---- spec/xcodebuild_spec.rb | 25 +++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 441f222..f242c7e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - danger-xcodebuild (0.0.3) + danger-xcodebuild (0.0.4) danger (~> 3.0) GEM diff --git a/lib/xcodebuild/gem_version.rb b/lib/xcodebuild/gem_version.rb index 35a0c64..0112afe 100644 --- a/lib/xcodebuild/gem_version.rb +++ b/lib/xcodebuild/gem_version.rb @@ -1,3 +1,3 @@ module Xcodebuild - VERSION = "0.0.3".freeze + VERSION = "0.0.4".freeze end diff --git a/lib/xcodebuild/plugin.rb b/lib/xcodebuild/plugin.rb index fc9892c..b5f765a 100644 --- a/lib/xcodebuild/plugin.rb +++ b/lib/xcodebuild/plugin.rb @@ -23,6 +23,11 @@ def initialize(arg) @xcodebuild_json = nil end + # Allows you to specify a build title to prefix all the reported messages. + # @return [String] + # + attr_accessor :build_title + # Allows you to specify an xcodebuild JSON file location to parse. attr_reader :json_file @@ -43,7 +48,10 @@ def parse_warnings @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} 😒") + message = Array.new + message.push (@build_title) unless @build_title.nil? + message.push("Please fix **#{@warning_count}** #{warning_string} 😒") + warn(message.reject(&:empty?).join(" ")) end return @warning_count end @@ -59,7 +67,10 @@ def parse_errors 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} 🚨") + message = Array.new + message.push (@build_title) unless @build_title.nil? + message.push("Build failed with **#{errors.count}** #{error_string} 🚨") + fail(message.reject(&:empty?).join(" ")) errors.each do |error| fail(error) end @@ -79,7 +90,10 @@ def parse_tests if test_failures.count > 0 test_string = test_failures.count == 1 ? "error" : "errors" - fail("Test execution failed with **#{test_failures.count}** #{test_string} 🚨") + message = Array.new + message.push (@build_title) unless @build_title.nil? + message.push("Test execution failed with **#{test_failures.count}** #{test_string} 🚨") + fail(message.reject(&:empty?).join(" ")) test_failures.each do |test_failure| fail(test_failure) end @@ -93,7 +107,10 @@ def parse_tests # def perfect_build is_perfect_build = @warning_count == 0 && @error_count == 0 && @test_failures_count == 0 - message("Perfect build 👍🏻") if is_perfect_build + message = Array.new + message.push (@build_title) unless @build_title.nil? + message.push ("Perfect build 👍🏻") + message(message.reject(&:empty?).join(" ")) if is_perfect_build return is_perfect_build end diff --git a/spec/xcodebuild_spec.rb b/spec/xcodebuild_spec.rb index 7030e84..87ecd50 100644 --- a/spec/xcodebuild_spec.rb +++ b/spec/xcodebuild_spec.rb @@ -23,6 +23,13 @@ module Danger expect(@dangerfile.status_report[:markdowns]).to be_empty end + it "has to add build_title as prefix" do + @xcodebuild.build_title = "Title" + @xcodebuild.perfect_build + + expect(@dangerfile.status_report[:messages].first).to eq("Title Perfect build 👍🏻") + end + describe 'with warnings' do before do @@ -47,6 +54,12 @@ module Danger expect(@dangerfile.status_report[:markdowns]).to be_empty end + it "has to add build_title as prefix" do + @xcodebuild.build_title = "Title" + @xcodebuild.parse_warnings + expect(@dangerfile.status_report[:warnings].first).to eq("Title Please fix **4** warnings 😒") + end + end describe 'with errors' do @@ -82,6 +95,12 @@ module Danger expect(@dangerfile.status_report[:markdowns]).to be_empty end + it "has to add build_title as prefix" do + @xcodebuild.build_title = "Title" + @xcodebuild.parse_errors + expect(@dangerfile.status_report[:errors].first).to eq("Title Build failed with **8** errors 🚨") + end + end describe 'with tests failures' do @@ -110,6 +129,12 @@ module Danger expect(@dangerfile.status_report[:markdowns]).to be_empty end + it "has to add build_title as prefix" do + @xcodebuild.build_title = "Title" + @xcodebuild.parse_tests + expect(@dangerfile.status_report[:errors].first).to eq("Title Test execution failed with **2** errors 🚨") + end + end end