Add configurable .pr_agent.toml branch selection via CLI/env with GitHub fallback#2411
Add configurable .pr_agent.toml branch selection via CLI/env with GitHub fallback#2411Copilot wants to merge 2 commits into
.pr_agent.toml branch selection via CLI/env with GitHub fallback#2411Conversation
.pr_agent.toml branch selection via CLI/env with GitHub fallback
Review Summary by QodoAdd configurable branch selection for .pr_agent.toml via CLI and environment
WalkthroughsDescription• Add --config-branch CLI flag for custom .pr_agent.toml branch selection • Support PR_AGENT_CONFIG_BRANCH environment variable for branch override • Implement GitHub provider fallback to default branch on config lookup failure • Add comprehensive unit tests for CLI parsing and provider behavior Diagramflowchart LR
CLI["CLI Flag<br/>--config-branch"]
ENV["Environment Variable<br/>PR_AGENT_CONFIG_BRANCH"]
SETTINGS["CONFIG.CONFIG_BRANCH<br/>Setting"]
GITHUB["GitHub Provider<br/>get_repo_settings"]
CUSTOM["Load from<br/>Custom Branch"]
DEFAULT["Fallback to<br/>Default Branch"]
CLI --> SETTINGS
ENV --> SETTINGS
SETTINGS --> GITHUB
GITHUB --> CUSTOM
CUSTOM -->|"On Failure"| DEFAULT
File Changes1. pr_agent/cli.py
|
Code Review by Qodo
1. Broad except Exception masks errors
|
There was a problem hiding this comment.
Pull request overview
This PR adds support for selecting the branch used to load .pr_agent.toml for GitHub PRs via CLI or environment variable, while retaining default-branch fallback behavior.
Changes:
- Adds
--config-branchCLI parsing and propagates it into runtime settings. - Updates GitHub repo settings lookup to try the configured branch first, then fall back.
- Adds unit tests for CLI/env branch selection and GitHub fallback behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pr_agent/cli.py |
Adds CLI/env config branch resolution. |
pr_agent/git_providers/github_provider.py |
Loads .pr_agent.toml from configured branch before default branch. |
tests/unittest/test_cli_config_branch.py |
Covers CLI flag and env var propagation. |
tests/unittest/test_github_provider_repo_settings.py |
Covers branch-first lookup and fallback behavior. |
|
|
||
| command = args.command.lower() | ||
| get_settings().set("CONFIG.CLI_MODE", True) | ||
| config_branch = (args.config_branch or os.environ.get("PR_AGENT_CONFIG_BRANCH") or "").strip() |
PR-Agent currently reads
.pr_agent.tomlfrom the repository default branch for GitHub PRs. This change adds explicit branch override support via CLI flag and environment variable, while preserving default-branch fallback behavior when the file is missing on the requested branch.Config input surface
--config-branch <branch>to the CLI parser.PR_AGENT_CONFIG_BRANCHsupport when CLI flag is not provided.CONFIG.CONFIG_BRANCHfor downstream consumers.GitHub provider lookup behavior
GithubProvider.get_repo_settings()now attempts.pr_agent.tomlfrom the configured branch first.Coverage for new behavior