Class: Danger::DangerXcov

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

Overview

Validates the code coverage of the files changed within a Pull Request and generates a brief coverage report.

Examples:

Validating code coverage for EasyPeasy (easy-peasy.io)


# Checks the coverage for the EasyPeasy scheme within the specified
# workspace, ignoring the target 'Demo.app' and setting a minimum
# coverage percentage of 90%.

# The result is sent to the pull request with a markdown format and
# notifies failure if the minimum coverage threshold is not reached.

xcov.report(
  scheme: 'EasyPeasy',
  workspace: 'Example/EasyPeasy.xcworkspace',
  exclude_targets: 'Demo.app',
  minimum_coverage_percentage: 90
)

See Also:

  • nakiostudio/danger-xcov

Instance Method Summary collapse

Instance Method Details

#report(*args) ⇒ void

This method returns an undefined value.

Validates the code coverage of the files changed within a Pull Request. This method accepts the same arguments allowed by the xcov gem.

Parameters:

  • args

    Hash=> String This method accepts the same arguments accepted by the xcov gem. A complete list of parameters allowed is available here: github.com/nakiostudio/xcov



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/danger_plugin.rb', line 34

def report(*args)
  # Check xcov availability, install it if needed
  `gem install xcov` unless xcov_available?
  unless xcov_available?
    puts "xcov is not available on this machine"
    return
  end

  require "xcov"

  # Init Xcov
  config = args.first
  Xcov.config = config
  Xcov.ignore_handler = Xcov::IgnoreHandler.new

  # Init project
  FastlaneCore::Project.detect_projects(config)
  Xcov.project = FastlaneCore::Project.new(config)

  # Parse .xccoverage
  report_json = Xcov::Runner.new.parse_xccoverage

  # Map and process report
  report = process_report(Xcov::Report.map(report_json))

  # Create markdown
  report_markdown = report.markdown_value

  # Send markdown
  markdown(report_markdown)

  # Notify failure if minimum coverage hasn't been reached
  threshold = config[:minimum_coverage_percentage].to_i
  if !threshold.nil? && (report.coverage * 100) < threshold
    fail("Code coverage under minimum of #{threshold}%")
  end
end