fix(stage): validate public remote URL parsing and surface gh pr create stderr#19
fix(stage): validate public remote URL parsing and surface gh pr create stderr#19andyma-star wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds opt-in enhancements to venfork stage to optionally create a draft upstream PR and (optionally) copy title/body from the corresponding open private PR on origin, reducing manual copy/paste when staging work.
Changes:
- Introduces stage-specific CLI arg parsing for
--create-prand--copy-pr-body(with validation). - Updates CLI routing to parse stage flags and pass options into
stageCommand. - Extends
stageCommandto optionally rungh pr create --draft, and optionally prefill title/body from a private PR; adds docs and tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/stage-args.ts |
Adds parsing/validation for new stage flags. |
src/index.ts |
Routes stage through the new parser and passes options to stageCommand. |
src/commands.ts |
Implements optional draft PR creation and private PR title/body copy in stageCommand. |
tests/stage-args.test.ts |
Adds unit tests for stage arg parsing and validation behavior. |
tests/commands.test.ts |
Adds tests covering draft PR creation and copy-PR-body flow. |
README.md |
Documents new stage flags and updated behavior. |
Comments suppressed due to low confidence (1)
src/commands.ts:794
git remote get-url upstreamis executed withreject:falsebut the exit code is not checked. If the upstream remote is missing or the command fails,upstreamRepoPathbecomes empty and both the compare URL andgh pr create --repowill be invalid. Consider mirroring thepublicremote handling here (checkexitCodeand throwRemoteNotFoundError('upstream'), and/or validateparseRepoPath(upstreamUrl)before continuing).
const upstreamUrlResult = await $({
reject: false,
})`git remote get-url upstream`;
const upstreamUrl = upstreamUrlResult.stdout.trim();
const upstreamRepoPath = parseRepoPath(upstreamUrl);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const publicUrl = publicUrlResult.stdout.trim(); | ||
| const publicRepoPath = parseRepoPath(publicUrl); | ||
| const publicOwner = parseOwner(publicUrl); | ||
|
|
There was a problem hiding this comment.
publicRepoPath/publicOwner are used to build the compare URL and to set gh pr create --head, but neither value is validated. If the public remote URL isn’t a parseable github.com URL, parseRepoPath/parseOwner will return an empty string and --head ${publicOwner}:${branch} will be malformed. Add validation (e.g., if !publicRepoPath or (when --create-pr) !publicOwner, fail with a clear error) before constructing URLs/commands.
| if (!publicRepoPath) { | |
| p.log.error( | |
| "Could not determine the GitHub repository path from the 'public' remote URL. " + | |
| "Please ensure the 'public' remote points to a valid github.com repository.", | |
| ); | |
| process.exit(1); | |
| } | |
| if (createPr && !publicOwner) { | |
| p.log.error( | |
| "Could not determine the GitHub owner from the 'public' remote URL required for --create-pr. " + | |
| "Please ensure the 'public' remote points to a valid github.com repository.", | |
| ); | |
| process.exit(1); | |
| } |
| createdPrUrl = createResult.stdout.trim() || null; | ||
| s.stop('Draft PR created'); | ||
| } else { | ||
| s.stop('Draft PR not created'); |
There was a problem hiding this comment.
When gh pr create fails, the code only stops the spinner with "Draft PR not created" and discards the actual stderr/exit reason. This makes it hard to diagnose common cases (already-open PR, missing permissions, invalid head/base). Consider logging createResult.stderr as a warning (or including it in the error path) so users know what to do next.
| s.stop('Draft PR not created'); | |
| s.stop('Draft PR not created'); | |
| const stderr = createResult.stderr?.toString().trim(); | |
| if (stderr) { | |
| p.log.warn(`gh pr create failed: ${stderr}`); | |
| } |
|
@copilot apply changes based on the comments in this thread |
…err on pr create failure Agent-Logs-Url: https://github.com/cabljac/venfork/sessions/5618afc1-cacc-494f-9b7d-fbea1d72946a Co-authored-by: cabljac <32874567+cabljac@users.noreply.github.com>
Applied both review changes in commit bf9b528:
|
Two gaps in error handling for
venfork stage: unparseablepublicremote URLs silently produced malformed commands, andgh pr createfailures swallowed the underlying error reason.Changes
publicremote, fail fast with a clear message ifpublicRepoPathis empty (always) orpublicOwneris empty (when--create-pris set), before any URL/command constructiongh pr createfailure diagnostics — whengh pr createexits non-zero, emitstderrviap.log.warnso users see the actual failure reason (duplicate PR, missing permissions, invalid head/base, etc.)