Skip to content

Commit abd2ee1

Browse files
committed
feat: added exit code 8 for successfully fixed violations (#4674)
1 parent 901003b commit abd2ee1

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

src/ansiblelint/app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ def report_outcome(
198198
) -> int:
199199
"""Display information about how to skip found rules.
200200
201-
Returns exit code, 2 if errors were found, 0 when only warnings were found.
201+
Returns exit code:
202+
- 0: when no errors were found
203+
- 2: if errors were found
204+
- 8: if all errors were fixed automatically
202205
"""
203206
msg = ""
204207

@@ -260,6 +263,8 @@ def report_outcome(
260263
files_count,
261264
is_success=mark_as_success,
262265
)
266+
if not summary.failures and changed_files_count > 0:
267+
return RC.FIXED_VIOLATIONS
263268
if mark_as_success:
264269
if not files_count:
265270
# success without any file being analyzed is reported as failure

src/ansiblelint/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class RC: # pylint: disable=too-few-public-methods
3737
INVALID_CONFIG = 3
3838
LOCK_TIMEOUT = 4
3939
NO_FILES_MATCHED = 5
40+
FIXED_VIOLATIONS = 8
4041
EXIT_CONTROL_C = 130
4142

4243

src/ansiblelint/schemas/__store__.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible-lint-config.json"
55
},
66
"ansible-navigator-config": {
7-
"etag": "730a0572f872af3ce271fb5116bc9d4609da10dc2e35448b5ec1050f12b72e2b",
7+
"etag": "5f454fdaeb3d92c4bb2cc15dcc48faa67925fecfbdb72efffeddee01860d6bcb",
88
"url": "https://raw.githubusercontent.com/ansible/ansible-navigator/main/src/ansible_navigator/data/ansible-navigator.json"
99
},
1010
"changelog": {
@@ -24,7 +24,7 @@
2424
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/inventory.json"
2525
},
2626
"meta": {
27-
"etag": "fa83d61b00b254d54a7c9a69e4fb8b722f356adec906da7beb733cadda1342bc",
27+
"etag": "2f5c7deb174136b48a4bc1d8d4399b1a175379dd4b8a863baa9c9bd56ffda489",
2828
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/meta.json"
2929
},
3030
"meta-runtime": {

src/ansiblelint/schemas/ansible-navigator-config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"additionalProperties": false,
4-
"description": "See https://docs.ansible.com/projects/navigator/settings/",
4+
"description": "See https://ansible.readthedocs.io/projects/navigator/settings/",
55
"properties": {
66
"ansible-navigator": {
77
"additionalProperties": false,
@@ -525,7 +525,7 @@
525525
"required": [
526526
"ansible-navigator"
527527
],
528-
"title": "ansible-navigator settings v25",
528+
"title": "ansible-navigator settings v26",
529529
"type": "object",
530-
"version": "25"
530+
"version": "26"
531531
}

test/test_app.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,26 @@ def test_with_inventory_concurrent_syntax_checks(tmp_path: Path) -> None:
5252
# https://github.com/ansible/ansible-lint/issues/4446.
5353
assert "AttributeError" not in result.stderr
5454
counter += 1
55+
56+
57+
def test_app_fixed_violations_coverage(tmp_path: Path) -> None:
58+
"""Directly test App.report_outcome to get coverage on RC.FIXED_VIOLATIONS."""
59+
from ansiblelint.app import App
60+
from ansiblelint.config import Options
61+
from ansiblelint.runner import LintResult
62+
63+
options = Options()
64+
options.project_dir = str(tmp_path)
65+
options.cache_dir = tmp_path / ".cache"
66+
options.cache_dir.mkdir()
67+
68+
app = App(options)
69+
70+
mock_file = Lintable(tmp_path / "playbook.yml", kind="playbook")
71+
mock_file.updated = True
72+
73+
result = LintResult(files={mock_file}, matches=[])
74+
75+
exit_code = app.report_outcome(result)
76+
77+
assert exit_code == RC.FIXED_VIOLATIONS

0 commit comments

Comments
 (0)