Skip to content

Commit

Permalink
added ability to set a build title
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriomazzeo committed Sep 27, 2016
1 parent e29ea67 commit 7ffb445
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
danger-xcodebuild (0.0.3)
danger-xcodebuild (0.0.4)
danger (~> 3.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion lib/xcodebuild/gem_version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Xcodebuild
VERSION = "0.0.3".freeze
VERSION = "0.0.4".freeze
end
25 changes: 21 additions & 4 deletions lib/xcodebuild/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
25 changes: 25 additions & 0 deletions spec/xcodebuild_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7ffb445

Please sign in to comment.