-
Notifications
You must be signed in to change notification settings - Fork 6
feat(infrahubctl): add task list command #579
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
base: stable
Are you sure you want to change the base?
Conversation
WalkthroughAdds a new AsyncTyper CLI group "task" (infrahub_sdk/ctl/task.py) with a list command supporting state, limit, offset, include-related-nodes, include-logs, --json and debug flags, and registers it on the main CLI. Changes infrahub_sdk/task/models.py::from_graphql to use explicit key membership checks for Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying infrahub-sdk-python with
|
| Latest commit: |
6b8f6a3
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a71476c5.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://fac-tasks-command.infrahub-sdk-python.pages.dev |
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## stable #579 +/- ##
==========================================
+ Coverage 75.69% 75.90% +0.21%
==========================================
Files 100 101 +1
Lines 8894 8957 +63
Branches 1751 1766 +15
==========================================
+ Hits 6732 6799 +67
+ Misses 1680 1677 -3
+ Partials 482 481 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
infrahub_sdk/ctl/task.py (2)
87-87: Consider using a less aggressive logging level.Setting the logging level to
CRITICALwill suppress all errors and warnings from the SDK. Consider usingWARNINGorERRORinstead to allow important diagnostic information through while still reducing noise.Apply this diff to use a less aggressive level:
- logging.getLogger("infrahub_sdk").setLevel(logging.CRITICAL) + logging.getLogger("infrahub_sdk").setLevel(logging.WARNING)
103-107: Remove redundant JSON serialization.The code serializes to JSON with
ujson.dumps, then passes the resulting string toconsole.print_json, which will parse it again. This is inefficient and unnecessary.Apply this diff to pass the data structure directly:
if json_output: - console.print_json( - ujson.dumps([task.model_dump(mode="json") for task in tasks], indent=2, sort_keys=True), highlight=False - ) + console.print_json( + data=[task.model_dump(mode="json") for task in tasks], + indent=2, + sort_keys=True, + ) return
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
docs/docs/infrahubctl/infrahubctl-task.mdx(1 hunks)docs/sidebars-infrahubctl.ts(1 hunks)infrahub_sdk/ctl/cli_commands.py(2 hunks)infrahub_sdk/ctl/task.py(1 hunks)infrahub_sdk/task/models.py(1 hunks)tests/unit/ctl/test_task_app.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
When implementing Infrahub checks, subclass InfrahubCheck and override validate(data); do not implement or rely on a check() method
Files:
infrahub_sdk/ctl/cli_commands.pyinfrahub_sdk/task/models.pytests/unit/ctl/test_task_app.pyinfrahub_sdk/ctl/task.py
infrahub_sdk/ctl/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
infrahub_sdk/ctl/**/*.py: Build CLI commands with Typer
Organize and keep all CLI commands within infrahub_sdk/ctl/
Files:
infrahub_sdk/ctl/cli_commands.pyinfrahub_sdk/ctl/task.py
tests/unit/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Place and write unit tests under tests/unit/ (isolated component tests)
Files:
tests/unit/ctl/test_task_app.py
tests/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Use the custom pytest plugin (infrahub_sdk.pytest_plugin) fixtures for clients, configuration, and Infrahub-specific testing
Files:
tests/unit/ctl/test_task_app.py
docs/**/*.{md,mdx}
📄 CodeRabbit inference engine (CLAUDE.md)
docs/**/*.{md,mdx}: Follow the Diataxis framework and classify docs as Tutorials, How-to guides, Explanation, or Reference
Structure How-to guides with required frontmatter and sections: introduction, prerequisites, step-by-step steps, validation, related resources
Structure Topics (Explanation) docs with introduction, concepts & definitions, background & context, architecture & design, connections, further reading
Use a professional, concise, informative tone with consistent structure across documents
Use proper language tags on all code blocks
Include both async and sync examples where applicable using the Tabs component
Add validation steps to guides to confirm success and expected outputs
Use callouts for warnings, tips, and important notes
Define new terms on first use and use domain-relevant terminology consistent with Infrahub’s model/UI
Conform to markdown style rules in .markdownlint.yaml and Vale styles in .vale/styles/
Files:
docs/docs/infrahubctl/infrahubctl-task.mdx
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: opsmill/infrahub-sdk-python#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T13:35:12.998Z
Learning: Applies to infrahub_sdk/ctl/**/*.py : Build CLI commands with Typer
📚 Learning: 2025-08-24T13:35:12.998Z
Learnt from: CR
PR: opsmill/infrahub-sdk-python#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T13:35:12.998Z
Learning: Applies to infrahub_sdk/ctl/**/*.py : Build CLI commands with Typer
Applied to files:
infrahub_sdk/ctl/cli_commands.pyinfrahub_sdk/ctl/task.py
📚 Learning: 2025-08-24T13:35:12.998Z
Learnt from: CR
PR: opsmill/infrahub-sdk-python#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T13:35:12.998Z
Learning: Applies to infrahub_sdk/ctl/**/*.py : Organize and keep all CLI commands within infrahub_sdk/ctl/
Applied to files:
docs/sidebars-infrahubctl.ts
🧬 Code graph analysis (1)
infrahub_sdk/ctl/task.py (4)
infrahub_sdk/async_typer.py (2)
AsyncTyper(11-31)command(29-31)infrahub_sdk/task/models.py (3)
TaskFilter(63-74)Task(32-60)TaskState(9-18)infrahub_sdk/ctl/client.py (1)
initialize_client(10-25)infrahub_sdk/ctl/utils.py (1)
catch_exception(78-106)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: integration-tests-latest-infrahub
- GitHub Check: unit-tests (3.13)
- GitHub Check: unit-tests (3.12)
- GitHub Check: Cloudflare Pages
🔇 Additional comments (5)
infrahub_sdk/task/models.py (1)
52-58: LGTM! Defensive key membership checks.The change from implicit truthiness checks to explicit
inmembership tests is a defensive pattern that prevents edge cases where keys might be present with falsy values (e.g., empty lists).docs/sidebars-infrahubctl.ts (1)
27-27: LGTM! Documentation navigation updated.The new task command is properly integrated into the sidebar navigation.
infrahub_sdk/ctl/cli_commands.py (1)
35-35: LGTM! CLI group registration follows established pattern.The task app is properly imported and registered under the "task" namespace, consistent with other CLI groups in this file.
Also applies to: 67-67
docs/docs/infrahubctl/infrahubctl-task.mdx (1)
1-40: LGTM! Comprehensive command documentation.The documentation clearly describes the task command and its options, following the established format for CLI documentation.
tests/unit/ctl/test_task_app.py (1)
1-100: LGTM! Comprehensive test coverage.The test suite covers key scenarios:
- Basic task listing with table output
- JSON output format validation
- State filtering behavior
- Invalid state handling
Tests appropriately mock GraphQL responses and verify both exit codes and output content.
1e7b83a to
4aeec5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
docs/docs/infrahubctl/infrahubctl-task.mdx(1 hunks)docs/sidebars-infrahubctl.ts(1 hunks)infrahub_sdk/ctl/cli_commands.py(2 hunks)infrahub_sdk/ctl/task.py(1 hunks)infrahub_sdk/task/models.py(1 hunks)tests/unit/ctl/test_task_app.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
- docs/docs/infrahubctl/infrahubctl-task.mdx
- infrahub_sdk/ctl/cli_commands.py
- tests/unit/ctl/test_task_app.py
- infrahub_sdk/ctl/task.py
- docs/sidebars-infrahubctl.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
When implementing Infrahub checks, subclass InfrahubCheck and override validate(data); do not implement or rely on a check() method
Files:
infrahub_sdk/task/models.py
🧬 Code graph analysis (1)
infrahub_sdk/task/models.py (1)
infrahub_sdk/operation.py (1)
related_nodes(57-59)
4aeec5d to
ead0d2f
Compare
Signed-off-by: Fatih Acar <[email protected]>
ead0d2f to
6b8f6a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
infrahub_sdk/ctl/task.py (1)
91-102: Consider usingfilters.limitandfilters.offsetfor consistency.The
TaskFiltermodel includeslimitandoffsetfields, but the code passes these as separate parameters toclient.task.filter(). While this works, settingfilters.limit = limitandfilters.offset = offsetwould centralize filter configuration and align with the model design.If you prefer to keep pagination separate from logical filters, consider documenting this design choice.
Apply this diff if you choose to consolidate:
client = initialize_client() filters = TaskFilter() parsed_states = _parse_states(state) if parsed_states: filters.state = parsed_states +if limit is not None: + filters.limit = limit +if offset is not None: + filters.offset = offset tasks = await client.task.filter( filter=filters, - limit=limit, - offset=offset, include_related_nodes=include_related_nodes, include_logs=include_logs, )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
docs/docs/infrahubctl/infrahubctl-task.mdx(1 hunks)docs/sidebars-infrahubctl.ts(1 hunks)infrahub_sdk/ctl/cli_commands.py(2 hunks)infrahub_sdk/ctl/task.py(1 hunks)infrahub_sdk/task/models.py(1 hunks)tests/unit/ctl/test_task_app.py(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- docs/docs/infrahubctl/infrahubctl-task.mdx
🚧 Files skipped from review as they are similar to previous changes (2)
- infrahub_sdk/ctl/cli_commands.py
- tests/unit/ctl/test_task_app.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
When implementing Infrahub checks, subclass InfrahubCheck and override validate(data); do not implement or rely on a check() method
Files:
infrahub_sdk/task/models.pyinfrahub_sdk/ctl/task.py
infrahub_sdk/ctl/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
infrahub_sdk/ctl/**/*.py: Build CLI commands with Typer
Organize and keep all CLI commands within infrahub_sdk/ctl/
Files:
infrahub_sdk/ctl/task.py
🧠 Learnings (2)
📚 Learning: 2025-08-24T13:35:12.998Z
Learnt from: CR
PR: opsmill/infrahub-sdk-python#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T13:35:12.998Z
Learning: Applies to infrahub_sdk/ctl/**/*.py : Organize and keep all CLI commands within infrahub_sdk/ctl/
Applied to files:
docs/sidebars-infrahubctl.ts
📚 Learning: 2025-08-24T13:35:12.998Z
Learnt from: CR
PR: opsmill/infrahub-sdk-python#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T13:35:12.998Z
Learning: Applies to infrahub_sdk/ctl/**/*.py : Build CLI commands with Typer
Applied to files:
infrahub_sdk/ctl/task.py
🧬 Code graph analysis (2)
infrahub_sdk/task/models.py (1)
infrahub_sdk/task/manager.py (2)
get(190-203)get(423-436)
infrahub_sdk/ctl/task.py (4)
infrahub_sdk/async_typer.py (2)
AsyncTyper(11-31)command(29-31)infrahub_sdk/task/models.py (3)
TaskFilter(65-76)Task(32-62)TaskState(9-18)infrahub_sdk/ctl/client.py (1)
initialize_client(10-25)infrahub_sdk/ctl/utils.py (2)
catch_exception(78-106)init_logging(42-50)
🔇 Additional comments (7)
infrahub_sdk/task/models.py (2)
52-55: LGTM! Past review concerns addressed.The nested
ifchecks now properly preventTypeErrorwhenrelated_nodesisNoneor missing. The outer check confirms key existence, and the inner check ensures the value is truthy before iteration.
57-60: Verifyedgesfield is not None before iteration.While the nested
ifprotects againstdata["logs"]beingNone, if GraphQL returns{"edges": None}the outer check passes (dict is truthy) but line 59 raisesTypeError: 'NoneType' object is not iterable.Apply this diff for defensive handling:
if "logs" in data: if data.get("logs"): - logs = [TaskLog(**item["node"]) for item in data["logs"]["edges"]] + edges = data["logs"].get("edges") or [] + logs = [TaskLog(**item["node"]) for item in edges] del data["logs"]docs/sidebars-infrahubctl.ts (1)
27-27: LGTM!The sidebar entry is correctly placed in alphabetical order and follows the established naming convention.
infrahub_sdk/ctl/task.py (4)
1-22: LGTM!The module structure follows established CLI patterns: AsyncTyper for async command support, Rich for output formatting, and appropriate relative imports. The callback provides clear documentation for the task command group.
Based on coding guidelines.
25-39: LGTM! Good error handling and UX.State validation is robust: normalizes input to uppercase, validates against the
TaskStateenum, and provides a helpful error message listing available states when validation fails.
42-69: LGTM! Clean table rendering.The table formatting is well-structured: handles empty results gracefully, formats optional fields with fallbacks, and uses appropriate Rich styling for readability.
Based on learnings.
72-110: LGTM! Well-structured command with proper async handling.The command implementation is solid: uses
catch_exceptionfor error handling, initializes logging, supports multiple output formats, and properly handles pagination and filters.
GPT-5-Codex
Summary by CodeRabbit
New Features
Documentation
Tests