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

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])


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

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:

  • Block (Block value)

    value

Returns:

  • (Block)


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

def ignored_results
  @ignored_results
end

#ignores_warningsBoolean

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

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


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

def ignores_warnings
  @ignores_warnings
end

#inline_modeBoolean

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

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


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

def inline_mode
  @inline_mode
end

#project_rootObject

rubocop:disable Lint/DuplicateMethods



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

def project_root
  @project_root
end

#strictBoolean

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

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


62
63
64
# File 'lib/xcode_summary/plugin.rb', line 62

def strict
  @strict
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



95
96
97
98
# File 'lib/xcode_summary/plugin.rb', line 95

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.



105
106
107
108
109
110
111
112
# File 'lib/xcode_summary/plugin.rb', line 105

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



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/xcode_summary/plugin.rb', line 118

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