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

Changed success/failure message #2567

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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