Class: Danger::DangerShroud

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

Overview

Parse a Kover or Jacoco report to enforce code coverage on CI. Results are passed out as a table in markdown.

Shroud depends on having a Kover or Jacoco coverage report generated for your project.

Examples:

Running Shroud with default values for Kover


# Report coverage of modified files, fail if either total project coverage
# or any modified file's coverage is under 90%
shroud.reportKover 'Project Name', 'path/to/kover/report.xml'

Running Shroud with custom coverage thresholds for Kover


# Report coverage of modified files, fail if total project coverage is under 80%,
# or if any modified file's coverage is under 95%
shroud.reportKover 'Project Name', 'path/to/kover/report.xml', 80, 95

Warn on builds instead of fail for Kover


# Report coverage of modified files the same as the above example, except the
# builds will only warn instead of fail if below thresholds
shroud.reportKover 'Project Name', 'path/to/kover/report.xml', 80, 95, false, false

Running Shroud with default values for Jacoco


# Report coverage of modified files, fail if either total project coverage
# or any modified file's coverage is under 90%
shroud.reportJacoco 'Project Name', 'path/to/jacoco/report.xml'

Running Shroud with custom coverage thresholds for Jacoco


# Report coverage of modified files, fail if total project coverage is under 80%,
# or if any modified file's coverage is under 95%
shroud.reportJacoco 'Project Name', 'path/to/jacoco/report.xml', 80, 95

Warn on builds instead of fail for Jacoco


# Report coverage of modified files the same as the above example, except the
# builds will only warn instead of fail if below thresholds
shroud.reportJacoco 'Project Name', 'path/to/jacoco/report.xml', 80, 95, false, false

Instance Method Summary collapse

Instance Method Details

#report(file, totalProjectThreshold = 90, modifiedFileThreshold = 90, failIfUnderProjectThreshold = true, failIfUnderFileThreshold = failIfUnderProjectThreshold) ⇒ void

This method returns an undefined value.

DEPRECATED: Please use reportJacoco or reportKover instead.

Report coverage on diffed files, as well as overall coverage.

Parameters:

  • file (String)

    file path to a Jacoco xml coverage report.

  • totalProjectThreshold (Integer) (defaults to: 90)

    defines the required percentage of total project coverage for a passing build. default 90.

  • modifiedFileThreshold (Integer) (defaults to: 90)

    defines the required percentage of files modified in a PR for a passing build. default 90.

  • failIfUnderProjectThreshold (Boolean) (defaults to: true)

    if true, will fail builds that are under the provided thresholds for the overall project. If false, will only warn. default true.

  • failIfUnderFileThreshold (Boolean) (defaults to: failIfUnderProjectThreshold)

    if true, will fail builds that are under the provided thresholds per file. If false, will only warn. default true.



74
75
76
77
# File 'lib/shroud/plugin.rb', line 74

def report(file, totalProjectThreshold = 90, modifiedFileThreshold = 90, failIfUnderProjectThreshold = true, failIfUnderFileThreshold = failIfUnderProjectThreshold)
  warn "[DEPRECATION] `report` is deprecated.  Please use `reportJacoco` or `reportKover` instead."
  reportJacoco('Project', file, totalProjectThreshold = 90, modifiedFileThreshold = 90, failIfUnderProjectThreshold, failIfUnderFileThreshold)
end

#reportJacoco(moduleName, file, totalProjectThreshold = 90, modifiedFileThreshold = 90, failIfUnderProjectThreshold = true, failIfUnderFileThreshold = false) ⇒ void

This method returns an undefined value.

Report coverage on diffed files, as well as overall coverage.

Parameters:

  • moduleName (String)

    the display name of the project or module

  • file (String)

    file path to a Jacoco xml coverage report.

  • totalProjectThreshold (Integer) (defaults to: 90)

    defines the required percentage of total project coverage for a passing build. default 90.

  • modifiedFileThreshold (Integer) (defaults to: 90)

    defines the required percentage of files modified in a PR for a passing build. default 90.

  • failIfUnderProjectThreshold (Boolean) (defaults to: true)

    if true, will fail builds that are under the provided thresholds for the overall project. If false, will only warn. default true.

  • failIfUnderFileThreshold (Boolean) (defaults to: false)

    if true, will fail builds that are under the provided thresholds per file. If false, will only warn. default true.



104
105
106
# File 'lib/shroud/plugin.rb', line 104

def reportJacoco(moduleName, file, totalProjectThreshold = 90, modifiedFileThreshold = 90, failIfUnderProjectThreshold = true, failIfUnderFileThreshold = false)
  internalReport('Jacoco', moduleName, file, totalProjectThreshold, modifiedFileThreshold, failIfUnderProjectThreshold, failIfUnderFileThreshold)
end

#reportKover(moduleName, file, totalProjectThreshold = 90, modifiedFileThreshold = 90, failIfUnderProjectThreshold = true, failIfUnderFileThreshold = failIfUnderProjectThreshold) ⇒ void

This method returns an undefined value.

Report coverage on diffed files, as well as overall coverage.

Parameters:

  • moduleName (String)

    the display name of the project or module

  • file (String)

    file path to a Kover xml coverage report.

  • totalProjectThreshold (Integer) (defaults to: 90)

    defines the required percentage of total project coverage for a passing build. default 90.

  • modifiedFileThreshold (Integer) (defaults to: 90)

    defines the required percentage of files modified in a PR for a passing build. default 90.

  • failIfUnderProjectThreshold (Boolean) (defaults to: true)

    if true, will fail builds that are under the provided thresholds for the overall project. If false, will only warn. default true.

  • failIfUnderFileThreshold (Boolean) (defaults to: failIfUnderProjectThreshold)

    if true, will fail builds that are under the provided thresholds per file. If false, will only warn. default true.



133
134
135
# File 'lib/shroud/plugin.rb', line 133

def reportKover(moduleName, file, totalProjectThreshold = 90, modifiedFileThreshold = 90, failIfUnderProjectThreshold = true, failIfUnderFileThreshold = failIfUnderProjectThreshold)
  internalReport('Kover', moduleName, file, totalProjectThreshold, modifiedFileThreshold, failIfUnderProjectThreshold, failIfUnderFileThreshold)
end