Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to skip summary #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions lib/codenarc/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DangerCodenarc < Plugin
# The project root, which will be used to make the paths relative.
# Defaults to `pwd`.
# @return [String] project_root value
# attr_accessor :project_root
attr_accessor :project_root
def project_root
root = @project_root || Dir.pwd
root += "/" unless root.end_with? "/"
Expand All @@ -28,11 +28,19 @@ def project_root
# Defines if the test summary will be sticky or not.
# Defaults to `false`.
# @return [Boolean] sticky
# attr_accessor :sticky_summary
attr_accessor :sticky_summary
def sticky_summary
@sticky_summary || false
end

# Defines if the test summary will be skipped or not.
# Defaults to `false`.
# @return [Boolean] skip
attr_accessor :skip_summary
def skip_summary
@skip_summary || false
end

# Reads a puppet-lint summary file and reports it.
#
# @param [String] file_path Path for puppet-lint report.
Expand All @@ -49,14 +57,16 @@ def run_summary(report_file)
doc = Nokogiri::XML(File.open(report_file))

# Create Summary
pkg_summary = doc.xpath("//PackageSummary")[0]
tf = pkg_summary.attr("totalFiles")
fwv = pkg_summary.attr("filesWithViolations")
p1_count = pkg_summary.attr("priority1")
p2_count = pkg_summary.attr("priority2")
p3_count = pkg_summary.attr("priority3")
summary = "CodeNarc scanned #{tf} files. Found #{fwv} files with violations. #{p1_count} P1 violations, #{p2_count} P2 violations, and #{p3_count} P3 violations"
message(summary, sticky: sticky_summary)
unless skip_summary
pkg_summary = doc.xpath("//PackageSummary")[0]
tf = pkg_summary.attr("totalFiles")
fwv = pkg_summary.attr("filesWithViolations")
p1_count = pkg_summary.attr("priority1")
p2_count = pkg_summary.attr("priority2")
p3_count = pkg_summary.attr("priority3")
summary = "CodeNarc scanned #{tf} files. Found #{fwv} files with violations. #{p1_count} P1 violations, #{p2_count} P2 violations, and #{p3_count} P3 violations"
message(summary, sticky: sticky_summary)
end

# Iterate Packages
doc.xpath("//Package").each do |pack_el|
Expand Down