Class: Danger::DangerXcodeSummary

Inherits:
Plugin
  • Object
show all
Defined in:
lib/xcode_summary/plugin.rb

Overview

Shows all build errors, warnings and unit tests results generated from ‘xcodebuild`. You need to use the `xcresult` produced by Xcode 11. It’s located in the Derived Data folder.

Examples:

Showing summary


xcode_summary.report 'build.xcresult'

Filtering warnings in Pods


xcode_summary.ignored_files = '**/Pods/**'
xcode_summary.report 'build.xcresult'

See Also:

  • diogot/danger-xcode_summary

Defined Under Namespace

Classes: Location, Result, Warning

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ignored_files[String]

A globbed string or array of strings which should match the files that you want to ignore warnings on. Defaults to nil. An example would be ‘’/Pods/‘` to ignore warnings in Pods that your project uses.

Parameters:

  • value (String or [String])

Returns:

  • ([String])


38
39
40
# File 'lib/xcode_summary/plugin.rb', line 38

def ignored_files
  @ignored_files
end

#ignored_results(&block) ⇒ Block

A block that filters specific results. An example would be ‘lambda { |result| result.message.start_with?(’ld’) }‘ to ignore results for ld_warnings.

Parameters:

  • value (Block)

Returns:

  • (Block)


45
46
47
# File 'lib/xcode_summary/plugin.rb', line 45

def ignored_results
  @ignored_results
end

#ignores_warningsBoolean

Defines if warnings should be included or not Defaults to ‘false`.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


77
78
79
# File 'lib/xcode_summary/plugin.rb', line 77

def ignores_warnings
  @ignores_warnings
end

#inline_modeBoolean

Defines if using inline comment or not. Defaults to ‘false`.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


71
72
73
# File 'lib/xcode_summary/plugin.rb', line 71

def inline_mode
  @inline_mode
end

#project_rootObject

rubocop:disable Lint/DuplicateMethods



30
31
32
# File 'lib/xcode_summary/plugin.rb', line 30

def project_root
  @project_root
end

#sort_warnings_by(&block) ⇒ Block

A block that sorts the warning results. An example would be ‘lambda { |warning| warning.message.include?(“deprecated”) ? 1 : 0 }` to sort results for deprecated warnings.

Parameters:

  • value (Block)

Returns:

  • (Block)


65
66
67
# File 'lib/xcode_summary/plugin.rb', line 65

def sort_warnings_by
  @sort_warnings_by
end

#sticky_summaryBoolean

Defines if the test summary will be sticky or not. Defaults to ‘false`.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


51
52
53
# File 'lib/xcode_summary/plugin.rb', line 51

def sticky_summary
  @sticky_summary
end

#strictBoolean

Defines errors strict. If value is ‘false`, then errors will be reporting as warnings. Defaults to `true`

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


83
84
85
# File 'lib/xcode_summary/plugin.rb', line 83

def strict
  @strict
end

#test_summaryBoolean

Defines if the build summary is shown or not. Defaults to ‘true`.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


57
58
59
# File 'lib/xcode_summary/plugin.rb', line 57

def test_summary
  @test_summary
end

Instance Method Details

#pluginvoid

This method returns an undefined value.

Pick a Dangerfile plugin for a chosen request_source and cache it based on github.com/danger/danger/blob/master/lib/danger/plugin_support/plugin.rb#L31



128
129
130
131
# File 'lib/xcode_summary/plugin.rb', line 128

def plugin
  plugins = Plugin.all_plugins.select { |plugin| Dangerfile.essential_plugin_classes.include? plugin }
  @plugin ||= plugins.select { |p| p.method_defined? :html_link }.map { |p| p.new(@dangerfile) }.compact.first
end

#report(file_path) ⇒ void

This method returns an undefined value.

Reads a ‘.xcresult` and reports it.

Parameters:

  • file_path (String)

    Path for xcresult bundle.



138
139
140
141
142
143
144
145
# File 'lib/xcode_summary/plugin.rb', line 138

def report(file_path)
  if File.exist?(file_path)
    xcode_summary = XCResult::Parser.new(path: file_path)
    format_summary(xcode_summary)
  else
    fail 'summary file not found'
  end
end

#warning_error_count(file_path) ⇒ String

Reads a ‘.xcresult` and reports its warning and error count.

Parameters:

  • file_path (String)

    Path for xcresult bundle.

Returns:

  • (String)

    JSON string with warningCount and errorCount



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/xcode_summary/plugin.rb', line 151

def warning_error_count(file_path)
  if File.exist?(file_path)
    xcode_summary = XCResult::Parser.new(path: file_path)
    warning_count = 0
    error_count = 0
    xcode_summary.actions_invocation_record.actions.each do |action|
      warning_count += warnings(action).count
      error_count += errors(action).count
    end
    result = { warnings: warning_count, errors: error_count }
    result.to_json
  else
    fail 'summary file not found'
  end
end