Automated Code Review
Relevant source files
The following files were used as context for generating this wiki page:
Automated code review in the Infrahub Ansible collection enforces code quality, project principles, and documentation standards through multi-tiered quality gates. The system identifies defects using static analysis linters, verifies Ansible compliance via sanity tests, and validates procedural requirements like changelog fragments during the Continuous Integration (CI) process.
These gates ensure that every Pull Request (PR) to the develop branch adheres to the Constitution before human review occurs.
Sources: dev/constitution.md:120-135, AGENTS.md:65-70
Review Architecture and Workflow
The review process triggers automatically on every PR submission. The workflow executes static analysis, standard compliance checks, and behavioral verification in a parallelized Docker-based environment.
The diagram shows the parallel CI jobs that must pass to allow a code merge.
Sources: dev/guidelines/testing.md:162-170, specs/002-towncrier-release-process/tasks.md:40-55
Static Analysis and Linting
The project employs specific tools to enforce formatting and prevent common coding errors.
Python Code Quality
- Ruff: Acts as the primary formatter and linter. It enforces a line length of 120 characters and manages import sorting via
isort. - Mypy: Conducts static type checking. CI enforces strict rules such as
disallow_untyped_defsandwarn_return_any. Note thatplugins/module_utils/infrahub_utils.pyis currently excluded from Mypy checks. - Autoflake: Automatically removes unused imports and variables during the
invoke linttask.
Sources: dev/guidelines/python.md:3-30, pyproject.toml:60-80, AGENTS.md:58-62
Prose and Structure Quality
- rumdl: Validates Markdown structure and formatting according to project-specific rules in
pyproject.toml. - Vale: Checks documentation prose style against the custom
Infrahubstyle guide. - yamllint: Ensures all YAML files, including Ansible docstrings and Towncrier fragments, are correctly formatted.
Sources: dev/guidelines/markdown.md:11-25, pyproject.toml:170-180
| Tool | Purpose | Enforced In |
|---|---|---|
| Ruff | Formatting and Linting | invoke lint, CI |
| Mypy | Type Hint Validation | CI (manual uv run mypy .) |
| rumdl | Markdown Linting | invoke lint, CI |
| yamllint | YAML Validation | invoke lint, CI |
| Vale | Documentation Style | CI |
Sources: dev/guidelines/python.md:50-70, AGENTS.md:40-55
Ansible Sanity Compliance
The ansible-test sanity suite is a critical gate for collection integrity. It validates requirements specific to Ansible modules that general linters cannot detect.
- Boilerplate Verification: Ensures every plugin file contains
__metaclass__ = typeandfrom __future__ import absolute_import, annotations, division, print_function. - Docstring Validation: Checks that
DOCUMENTATION,EXAMPLES, andRETURNYAML blocks exist and match the module'sargument_spec. - Import Compliance: Verifies that the
infrahub-sdkis imported using the conditionalHAS_INFRAHUBCLIENTpattern to prevent execution failures in environments without the SDK.
Sources: dev/constitution.md:12-25, dev/guidelines/testing.md:65-75, plugins/AGENTS.md:25-30
Procedural Quality Gates
Changelog Enforcement
The system blocks PRs that lack a corresponding news fragment in the changelog/ directory.
- Towncrier Fragments: Every behavior-changing PR must include a file named
<issue>.<type>.md. - Validation Logic: The
changelog-check.ymlworkflow queries the GitHub API to ensure a fragment exists or theci/skip-changeloglabel is applied.
Sources: AGENTS.md:75-90, specs/002-towncrier-release-process/tasks.md:42-52
Documentation Accuracy
The "Documentation Accuracy" guardrail prevents manual edits to generated files.
- Generation Gate: If an author changes module docstrings, they must run
invoke generate-doc. - CI Rejection: CI verifies that the documentation renders correctly from source docstrings using Jinja2 templates.
Sources: dev/constitution.md:78-85, dev/adr/0005-doc-generation-pipeline.md:15-25
Automation Summary
Automated code review reduces manual overhead by catching syntax errors, type mismatches, and standard violations before human intervention. Developers use invoke lint and invoke tests-sanity locally to mirror CI checks. Passing these automated gates is a constitutional requirement for merging code into the develop or stable branches.
Sources: dev/constitution.md:120-135, AGENTS.md:40-50