chore: add ruff linting and formatting#80
Conversation
feat: add PR labeler workflow with path and size labels
- Fix image exclusion to match nested directories at any depth (agents/*/images/*, etc.) instead of only top-level images/* - Only catch 404 in ensure_label_exists, re-raise 403/429/500 - Pin PyGithub==2.6.0 to avoid supply-chain risk in pull_request_target - Add warning step when size labeling fails for better observability Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix: address CodeRabbit review findings
Avoids noisy "removed size/xl, added size/xl" timeline entries when a push doesn't change the PR's size bucket. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix: skip label remove/add cycle when size bucket unchanged
- SHA-pin all actions to match repo convention (agent-deployment-test.yaml) - Add concurrency group to prevent parallel runs on the same PR - Collect-then-act pattern in update_size_label to handle stale labels that appear after the matching label in iteration order Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix: address CodeRabbit review — SHA-pin, concurrency, defensive labels
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis pull request introduces a comprehensive code linting and formatting infrastructure using Ruff. A GitHub Actions workflow, pre-commit configuration, and Ruff configuration file are added. Across ~100 agent and test files, import statements are reordered, function signatures reformatted for readability, and unnecessary blank lines removed to enforce consistent code style. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Large PR detected (1450 lines changed) This PR exceeds 1200 lines of code changes (excluding lock files, generated content, and images). Large PRs are harder to review thoroughly and are more likely to introduce bugs. Consider splitting this PR into smaller, focused changes. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
agents/langgraph/react_with_database_memory/src/react_with_database_memory/utils.py (1)
16-26:⚠️ Potential issue | 🔴 CriticalAdd validation for missing environment variables.
The function will raise
TypeErrorif any required environment variables are not set, becausegetenv()returnsNoneby default, andquote_plus(None)fails. This is a pre-existing reliability issue unrelated to this PR's formatting changes, but should be addressed to prevent runtime crashes.🛡️ Proposed fix to add validation
def get_database_uri() -> str: """ Construct PostgresSQL database URI from environment variables. Expected env vars: - POSTGRES_HOST - POSTGRES_PORT - POSTGRES_DB - POSTGRES_USER - POSTGRES_PASSWORD """ host = getenv("POSTGRES_HOST") user = getenv("POSTGRES_USER") password = getenv("POSTGRES_PASSWORD") database = getenv("POSTGRES_DB") port = getenv("POSTGRES_PORT") + + missing = [ + name for name, value in [ + ("POSTGRES_HOST", host), + ("POSTGRES_USER", user), + ("POSTGRES_PASSWORD", password), + ("POSTGRES_DB", database), + ("POSTGRES_PORT", port), + ] if value is None + ] + if missing: + raise ValueError(f"Missing required environment variables: {', '.join(missing)}") safe_host = quote_plus(host) safe_user = quote_plus(user) safe_password = quote_plus(password) return f"postgresql://{safe_user}:{safe_password}@{safe_host}:{port}/{database}"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@agents/langgraph/react_with_database_memory/src/react_with_database_memory/utils.py` around lines 16 - 26, The code constructs a PostgreSQL URL from environment vars (host, user, password, database, port) but calls quote_plus on values that may be None; update the function to validate these env vars before encoding: read host, user, password, database, port via getenv, collect any that are missing, and if any are missing raise a clear ValueError listing the missing names; only after validation call quote_plus to create safe_host/safe_user/safe_password and then return the formatted connection string as before (ensure you reference the existing identifiers host, user, password, database, port, quote_plus, safe_host/safe_user/safe_password, and the final return string).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In
`@agents/langgraph/react_with_database_memory/src/react_with_database_memory/utils.py`:
- Around line 16-26: The code constructs a PostgreSQL URL from environment vars
(host, user, password, database, port) but calls quote_plus on values that may
be None; update the function to validate these env vars before encoding: read
host, user, password, database, port via getenv, collect any that are missing,
and if any are missing raise a clear ValueError listing the missing names; only
after validation call quote_plus to create safe_host/safe_user/safe_password and
then return the formatted connection string as before (ensure you reference the
existing identifiers host, user, password, database, port, quote_plus,
safe_host/safe_user/safe_password, and the final return string).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: b19dc3d9-4ae8-4ac4-a261-22cd3bc606af
📒 Files selected for processing (91)
.github/workflows/ruff.yml.pre-commit-config.yamlCONTRIBUTING.mdagents/a2a/langgraph_crewai_agent/src/a2a_langgraph_crewai/a2a_reply.pyagents/a2a/langgraph_crewai_agent/src/a2a_langgraph_crewai/crew_a2a_server.pyagents/a2a/langgraph_crewai_agent/src/a2a_langgraph_crewai/langgraph_a2a_server.pyagents/autogen/mcp_agent/main.pyagents/autogen/mcp_agent/mcp_automl_template/interact_with_mcp.pyagents/autogen/mcp_agent/mcp_automl_template/mcp_server.pyagents/autogen/mcp_agent/mcp_automl_template/register_tools.pyagents/autogen/mcp_agent/mcp_automl_template/utils.pyagents/autogen/mcp_agent/src/autogen_agent_base/agent.pyagents/autogen/mcp_agent/src/autogen_agent_base/tracing.pyagents/crewai/websearch_agent/examples/_interactive_chat.pyagents/crewai/websearch_agent/examples/ai_service.pyagents/crewai/websearch_agent/main.pyagents/crewai/websearch_agent/playground/app.pyagents/crewai/websearch_agent/src/crewai_web_search/crew.pyagents/crewai/websearch_agent/src/crewai_web_search/tools/__init__.pyagents/crewai/websearch_agent/src/crewai_web_search/tracing.pyagents/google/adk/examples/_interactive_chat.pyagents/google/adk/examples/ai_service.pyagents/google/adk/main.pyagents/google/adk/src/adk_agent/agent.pyagents/langgraph/agentic_rag/data/load_documents.pyagents/langgraph/agentic_rag/examples/_interactive_chat.pyagents/langgraph/agentic_rag/examples/ai_service.pyagents/langgraph/agentic_rag/main.pyagents/langgraph/agentic_rag/playground/app.pyagents/langgraph/agentic_rag/src/agentic_rag/agent.pyagents/langgraph/agentic_rag/src/agentic_rag/tools.pyagents/langgraph/agentic_rag/src/agentic_rag/tracing.pyagents/langgraph/agentic_rag/tests/test_tools.pyagents/langgraph/human_in_the_loop/examples/_interactive_chat.pyagents/langgraph/human_in_the_loop/examples/ai_service.pyagents/langgraph/human_in_the_loop/examples/execute_ai_service_locally.pyagents/langgraph/human_in_the_loop/main.pyagents/langgraph/human_in_the_loop/src/human_in_the_loop/tracing.pyagents/langgraph/react_agent/examples/_interactive_chat.pyagents/langgraph/react_agent/examples/ai_service.pyagents/langgraph/react_agent/main.pyagents/langgraph/react_agent/playground/app.pyagents/langgraph/react_agent/src/react_agent/tracing.pyagents/langgraph/react_agent/tests/behavioral/conftest.pyagents/langgraph/react_agent/tests/behavioral/test_response_quality.pyagents/langgraph/react_agent/tests/behavioral/test_tool_usage.pyagents/langgraph/react_agent/tests/test_tools.pyagents/langgraph/react_with_database_memory/examples/_interactive_chat.pyagents/langgraph/react_with_database_memory/examples/ai_service.pyagents/langgraph/react_with_database_memory/examples/clear_thread_history.pyagents/langgraph/react_with_database_memory/examples/execute_ai_service_locally.pyagents/langgraph/react_with_database_memory/examples/query_existing_deployment.pyagents/langgraph/react_with_database_memory/examples/test_memory_fifo.ipynbagents/langgraph/react_with_database_memory/main.pyagents/langgraph/react_with_database_memory/playground/app.pyagents/langgraph/react_with_database_memory/src/react_with_database_memory/agent.pyagents/langgraph/react_with_database_memory/src/react_with_database_memory/tracing.pyagents/langgraph/react_with_database_memory/src/react_with_database_memory/utils.pyagents/llamaindex/websearch_agent/examples/_interactive_chat.pyagents/llamaindex/websearch_agent/examples/ai_service.pyagents/llamaindex/websearch_agent/main.pyagents/llamaindex/websearch_agent/playground/app.pyagents/llamaindex/websearch_agent/src/websearch_agent/__init__.pyagents/llamaindex/websearch_agent/src/websearch_agent/tracing.pyagents/llamaindex/websearch_agent/src/websearch_agent/workflow.pyagents/llamaindex/websearch_agent/tests/test_tools.pyagents/vanilla_python/openai_responses_agent/examples/_interactive_chat.pyagents/vanilla_python/openai_responses_agent/examples/ai_service.pyagents/vanilla_python/openai_responses_agent/main.pyagents/vanilla_python/openai_responses_agent/playground/app.pyagents/vanilla_python/openai_responses_agent/src/openai_responses_agent/__init__.pyagents/vanilla_python/openai_responses_agent/src/openai_responses_agent/agent.pyagents/vanilla_python/openai_responses_agent/src/openai_responses_agent/tracing.pyagents/vanilla_python/openai_responses_agent/tests/behavioral/conftest.pyagents/vanilla_python/openai_responses_agent/tests/behavioral/test_cost_latency.pyagents/vanilla_python/openai_responses_agent/tests/behavioral/test_reliability.pyagents/vanilla_python/openai_responses_agent/tests/behavioral/test_response_quality.pyagents/vanilla_python/openai_responses_agent/tests/behavioral/test_tool_usage.pyruff.tomltests/behavioral/adversarial/conftest.pytests/behavioral/adversarial/test_boundary_conditions.pytests/behavioral/adversarial/test_prompt_injection.pytests/behavioral/adversarial/test_safety.pytests/behavioral/api_contract/test_api_contract.pytests/behavioral/conftest.pytests/behavioral/harness/__init__.pytests/behavioral/harness/mlflow_client.pytests/behavioral/harness/runner.pytests/behavioral/harness/scorers/plan_coherence.pytests/behavioral/harness/scorers/safety.pytests/behavioral/harness/scorers/tool_sequence.py
💤 Files with no reviewable changes (7)
- agents/autogen/mcp_agent/mcp_automl_template/register_tools.py
- agents/a2a/langgraph_crewai_agent/src/a2a_langgraph_crewai/a2a_reply.py
- agents/langgraph/react_with_database_memory/src/react_with_database_memory/agent.py
- agents/vanilla_python/openai_responses_agent/tests/behavioral/test_cost_latency.py
- agents/autogen/mcp_agent/mcp_automl_template/mcp_server.py
- agents/vanilla_python/openai_responses_agent/tests/behavioral/test_reliability.py
- agents/crewai/websearch_agent/src/crewai_web_search/tools/init.py
be4f70e to
ed5da62
Compare
Description
Add ruff linting/formatting and pre-commit hooks to enforce consistent Python code style across the repo.
ruff.tomlwith Python 3.12 target, E/F/I rule set, and per-file-ignores for intentional E402 patterns.pre-commit-config.yamlwith SHA-pinned ruff hooks and pre-commit-hooks bundle (trailing-whitespace, end-of-file-fixer, check-yaml, check-added-large-files).github/workflows/ruff.yml— blocking CI check with inline PR annotations, SHA-pinned actions, concurrency groups, minimal permissions, 10-min timeoutF821(undefinedgetenv),F841(unused variable),E721(incorrect type comparison)CONTRIBUTING.mdJira Ticket
RHAIENG-4067
Testing
make testpasses (run from the affected agent directory)Manual testing performed (describe steps below)
No testing required (documentation/config change only)
CI workflow
Ruffpasses on this PR (ruff check + ruff format --check)ruff check .locally — all checks passruff format --check .locally — no formatting changes neededpre-commit run --all-fileslocally — all hooks passChecklist
.envor secret files are included in this PRReview Guidance
ruff.toml(rule selection, per-file-ignores),.pre-commit-config.yaml(hook config), and.github/workflows/ruff.yml(CI workflow)F821,F841,E721comments or check the commitstyle: apply ruff auto-fixes and formattingRelated PRs
None