refactor: migrate cherry-pick PR creation from hub to gh CLI#1024
refactor: migrate cherry-pick PR creation from hub to gh CLI#1024
Conversation
Replace deprecated hub CLI (v2.14.2, archived) with official gh CLI for creating cherry-pick pull requests. Changes: - Dockerfile: replace hub installation with gh CLI v2.67.0 - runner_handler.py: replace `hub pull-request` with `gh pr create` - tests: update cherry-pick test assertions for gh CLI flags Signed-off-by: Meni Yakove <myakove@gmail.com>
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Container Operations
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughReplaces deprecated Changes
Sequence Diagram(s)sequenceDiagram
participant Runner as Runner Handler
participant Git as Local Git (worktree)
participant GH as gh CLI
participant GitHub as GitHub API
Runner->>Git: create worktree, cherry-pick, commit, push branch
Runner->>GH: run `gh pr create --base ... --head ... --title ... --body ... [--assignee ...]` (via GH_TOKEN)
GH->>GitHub: call GitHub API to create PR (labels, assignee, title, body)
GitHub-->>GH: return PR URL/response
GH-->>Runner: stdout (PR URL)
Runner->>Runner: redact secrets in logs, record PR URL
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 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)
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 |
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan Review Summary by QodoMigrate cherry-pick PR creation from hub to gh CLI
WalkthroughsDescription• Replace deprecated hub CLI with official gh CLI for cherry-pick PR creation • Update Dockerfile to install gh instead of hub tarball • Refactor command construction with proper flag mapping and quoting • Update test assertions to validate gh CLI command structure Diagramflowchart LR
A["hub CLI<br/>v2.14.2<br/>deprecated"] -->|"replace with"| B["gh CLI<br/>v2.67.0<br/>official"]
C["Dockerfile<br/>hub tarball"] -->|"simplify to"| D["dnf install gh"]
E["runner_handler.py<br/>hub pull-request"] -->|"migrate to"| F["gh pr create<br/>with proper flags"]
G["test assertions<br/>hub flags"] -->|"update to"| H["gh flags<br/>validation"]
File Changes1. webhook_server/libs/handlers/runner_handler.py
|
Code Review by Qodo
1.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@webhook_server/libs/handlers/runner_handler.py`:
- Around line 729-735: The command string currently prefixes
GH_TOKEN={github_token} which exposes github_token in process listings; update
the code that builds and calls the command (the invocation that uses
github_token, repo_full_name, target_branch, new_branch_name,
CHERRY_PICKED_LABEL, assignee_flag, pr_title, pr_body) to stop injecting
GH_TOKEN into the command string and instead pass the token via an environment
dict to run_command (or add an env parameter to run_command if it doesn't exist)
so GH_TOKEN is set in the child process environment securely rather than as a
command-line argument.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: a06a0e2a-8bfc-4aff-8a68-093f8ab8550e
📒 Files selected for processing (3)
Dockerfilewebhook_server/libs/handlers/runner_handler.pywebhook_server/tests/test_runner_handler.py
The `run_command()` function uses `asyncio.create_subprocess_exec` (no shell), so `GH_TOKEN=... gh pr create` treated `GH_TOKEN=...` as the executable name. Fix by passing the token via the `env` kwarg to `run_command()`, which forwards it to `create_subprocess_exec`. Each subprocess gets its own isolated env copy, so parallel execution with different tokens per repo is safe. Signed-off-by: Meni Yakove <myakove@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
webhook_server/libs/handlers/runner_handler.py (1)
746-750:⚠️ Potential issue | 🔴 CriticalCRITICAL: return immediately after worktree setup fails.
Line 750 still enters the git loop after Lines 746-748 already marked the check failed. That can turn a repository-preparation error into a misleading cherry-pick failure and overwrite the real root cause. Fail fast here.
Suggested fix
if not success: output["text"] = self.check_run_handler.get_check_run_text(out=out, err=err) await self.check_run_handler.set_check_failure(name=CHERRY_PICKED_LABEL, output=output) + return for cmd in git_commands:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@webhook_server/libs/handlers/runner_handler.py` around lines 746 - 750, The code currently continues into the git_commands loop even when worktree setup fails (success is False) and after calling self.check_run_handler.set_check_failure, which masks the real error; modify the control flow in the method containing this block (runner handler function in runner_handler.py) so that when success is False you immediately return (or otherwise exit) after populating output and awaiting self.check_run_handler.set_check_failure(name=CHERRY_PICKED_LABEL, output=output), preventing execution of the subsequent for cmd in git_commands loop and ensuring the real repository-preparation failure is reported.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@webhook_server/libs/handlers/runner_handler.py`:
- Around line 797-813: When gh pr create fails (the rc==False branch handled
with self.check_run_handler.get_check_run_text and set_check_failure), post an
actionable comment back on the source PR that includes the cherry-pick branch
name and the exact gh pr command to run (redacting tokens the same way
_redact_secrets is used), plus the redacted stdout/stderr and a short manual
recovery instruction; use the existing check-run helper on
self.check_run_handler (e.g., use its comment/issue comment method) to add this
message before returning, and keep the existing set_check_failure and
logger.error behavior.
---
Outside diff comments:
In `@webhook_server/libs/handlers/runner_handler.py`:
- Around line 746-750: The code currently continues into the git_commands loop
even when worktree setup fails (success is False) and after calling
self.check_run_handler.set_check_failure, which masks the real error; modify the
control flow in the method containing this block (runner handler function in
runner_handler.py) so that when success is False you immediately return (or
otherwise exit) after populating output and awaiting
self.check_run_handler.set_check_failure(name=CHERRY_PICKED_LABEL,
output=output), preventing execution of the subsequent for cmd in git_commands
loop and ensuring the real repository-preparation failure is reported.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: ca29e3b5-5006-4bf1-b303-1fb89df431b6
📒 Files selected for processing (1)
webhook_server/libs/handlers/runner_handler.py
…R creation failure - Add `return` after worktree setup failure to prevent fall-through into git commands loop (pre-existing bug) - Add PR comment with manual recovery instructions when `gh pr create` fails but branch was already pushed Signed-off-by: Meni Yakove <myakove@gmail.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
/approve |
|
/verified |
|
New container for ghcr.io/myk-org/github-webhook-server:latest published |
Summary
Replace the deprecated
hubCLI (v2.14.2, archived project) with the officialghCLI for creating cherry-pick pull requests.Closes #1023
Changes
Dockerfile
ghtodnf installpackageshubtarball download and installationwebhook_server/libs/handlers/runner_handler.py
hub pull-requestcommand withgh pr create-b→--base,-h→--head,-l→--label,-a→--assignee,-m→--title/--body--repoflag for explicit repository targetingshlex.quote()on all user-provided valuesGH_TOKENenv var for authenticationwebhook_server/tests/test_runner_handler.py
ghCLI flagsNotes
Summary by CodeRabbit