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

Feature: Add option to ignore ansible-lint warnings #20

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,7 @@ $RECYCLE.BIN/
.tags

ansible-lint-junit.xml
output.txt
output.txt

bin/
pyvenv.cfg
12 changes: 9 additions & 3 deletions src/ansible_lint_junit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def main():
help="print XML to console as command output", default=False)
parser.add_argument("-d", "--dummy-test", dest="dummy", action="store_true",
help="Adds single (1) dummy test if there were 0 tests and/or 0 errors", default=False)
parser.add_argument('--version', action='version',
parser.add_argument("--version", action="version",
version='%(prog)s {version}'.format(version=version()))
parser.add_argument("-w", "--ignore-warnings", action="store_true", default=False,
help="Ignore ansible-lint warnings")

arguments = parser.parse_args()

Expand All @@ -49,7 +51,7 @@ def main():

for line in ansible_lint_output:
if len(line):
errors_count = str(len(ansible_lint_output) - 1)
# Break ansible_lint_output is empty, I suppose?
break

if arguments.dummy:
Expand All @@ -71,19 +73,21 @@ def main():
parsed_lines = []
for line in ansible_lint_output:
if 0 < len(line):

line_match = line_regex.match(line)

if not line_match:
continue

if arguments.ignore_warnings and line_match.group(3).endswith(" (warning)"):
continue
line_data = {
"filename": line_match.group(1),
"line": int(line_match.group(2)),
"error": line_match.group(3),
"text": line_match.group(3),
}
parsed_lines.append(line_data)
errors_count = int(errors_count) + 1

testcase = ET.SubElement(
testsuite, "testcase", name="{}-{}".format(line_data['filename'], len(parsed_lines)))
Expand All @@ -97,6 +101,8 @@ def main():
type="Ansible Lint"
).text = line_data['error']

testsuite.set("errors", str(errors_count))

xml_string = ET.tostring(testsuites, encoding='utf8', method='xml')
xml_nice = minidom.parseString(xml_string)
xml_nice = xml_nice.toprettyxml(indent="\t")
Expand Down