Skip to content

Commit

Permalink
Changed success/failure message
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Oct 6, 2022
1 parent fba36ac commit 4a13a83
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
6 changes: 4 additions & 2 deletions examples/playbooks/task-has-name-success.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
hosts: all
tasks:
- name: This task has a name
ansible.builtin.command: echo "Hello World"
ansible.builtin.command: echo "Hello World" # noqa: no-free-form
changed_when: false
- name: Debug task with name
ansible.builtin.debug: msg="Hello World"
ansible.builtin.debug: msg="Hello World" # noqa: no-free-form
- name: Flush handler with name
ansible.builtin.meta: flush_handlers
changed_when: false
29 changes: 17 additions & 12 deletions src/ansiblelint/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def report_outcome(self, result: LintResult, mark_as_success: bool = False) -> i
"because 'yaml' is in 'skip_list'."
)

if (result.matches or changed_files_count) and not self.options.quiet:
if not self.options.quiet:
console_stderr.print(render_yaml(msg))
self.report_summary(summary, changed_files_count, files_count)

Expand Down Expand Up @@ -231,12 +231,6 @@ def report_summary( # pylint: disable=too-many-branches,too-many-locals
if changed_files_count:
console_stderr.print(f"Modified {changed_files_count} files.")

msg = "Finished with "
msg += f"{summary.failures} failure(s), {summary.warnings} warning(s)"
if summary.fixed:
msg += f", and fixed {summary.fixed} issue(s)"
msg += f" on {files_count} files."

# determine which profile passed
summary.passed_profile = ""
passed_profile_count = 0
Expand All @@ -247,6 +241,7 @@ def report_summary( # pylint: disable=too-many-branches,too-many-locals
summary.passed_profile = profile
passed_profile_count += 1

stars = ""
if summary.tag_stats:
table = Table(
title="Rule Violation Summary",
Expand All @@ -269,15 +264,25 @@ def report_summary( # pylint: disable=too-many-branches,too-many-locals
# rate stars for the top 5 profiles (min would not get
rating = 5 - (len(PROFILES.keys()) - passed_profile_count)
if 0 < rating < 6:
stars = f"Rated as {rating}/5 stars."
else:
stars = "No rating."
stars = f", {rating}/5 star rating"

console_stderr.print(table)
console_stderr.print()

if summary.passed_profile:
msg += f" Code passed [white bold]{summary.passed_profile}[/] profile. {stars}"
if summary.failures:
msg = "[red][bold]Failed[/][/] after "
else:
msg = "[green]Passed[/] with "

if summary.passed_profile:
msg += f"[bold]{summary.passed_profile}[/] profile"
if stars:
msg += stars

msg += f": {summary.failures} failure(s), {summary.warnings} warning(s)"
if summary.fixed:
msg += f", and fixed [/]{summary.fixed} issue(s)"
msg += f" on {files_count} files."

console_stderr.print(msg)

Expand Down
3 changes: 2 additions & 1 deletion src/ansiblelint/rules/only_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def test_only_builtin_fail() -> None:
"examples/playbooks/rule-only-builtins.yml",
)
assert result.returncode == VIOLATIONS_FOUND_RC
assert "Finished with 1 failure(s)" in result.stderr
assert "Failed" in result.stderr
assert "1 failure(s)" in result.stderr
assert "only-builtins" in result.stdout

@pytest.mark.parametrize(
Expand Down

0 comments on commit 4a13a83

Please sign in to comment.