feat(cli-v2): support --output with GitHub PR URLs in fern generate#14901
Open
Swimburger wants to merge 3 commits intomainfrom
Open
feat(cli-v2): support --output with GitHub PR URLs in fern generate#14901Swimburger wants to merge 3 commits intomainfrom
--output with GitHub PR URLs in fern generate#14901Swimburger wants to merge 3 commits intomainfrom
Conversation
When a GitHub PR URL (e.g. https://github.com/owner/repo/pull/123) is passed to --output, the CLI resolves the PR's head branch via the GitHub API and pushes generated code directly to it, updating the existing PR instead of creating a new one. Changes: - Add isGithubPrUrl() and parseGithubPrUrl() helpers in gitUrl.ts - Add resolveGithubPrBranch() utility to fetch PR branch from GitHub API - Update parseTargetOutput() in command.ts to handle PR URLs (async) - Update getTargets() to be async to support the above - Force local generation when --output is a PR URL - Update parseOutputArg.ts for no-config mode - Update --output CLI description Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
When --output is a GitHub PR URL or git URL, don't resolve it as a local filesystem path in runGeneration. This avoids nonsensical paths like '/home/user/project/https:/github.com/owner/repo/pull/123' being passed to checkOutputDirectory and pipeline.run. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
For fork PRs, the head branch lives on the fork repo, not the base repo. Use head.repo.full_name from the GitHub API response to get the correct repository URI instead of deriving it from the PR URL path. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Refs internal Slack discussion (Niels)
Allows
fern generate --output https://github.com/owner/repo/pull/123to resolve the PR's head branch and push generated code directly to it, updating the existing PR instead of creating a new one. This eliminates the manual workflow of editinggenerators.ymlto setmode: pushandbranch: <pr-branch>when iterating on a PR.Changes Made
gitUrl.ts: AddedisGithubPrUrl()andparseGithubPrUrl()helpers; modifiedisGitUrl()to exclude PR URLs (both start withhttps://github.com/)resolveGithubPrBranch.ts(new): Fetches the PR's head branch and head repository via the GitHub REST API usingfetch()withGITHUB_TOKEN/GIT_TOKEN. Useshead.repo.full_namefor the URI so fork-based PRs resolve to the correct repository.command.ts:parseTargetOutput()andgetTargets()async to support the GitHub API call{ mode: "push", branch, uri }output config--outputis a PR URL (same as git URL output)parseTargetOutputcall out of.map()ingetTargets()to avoid redundant API callsisRemoteOutputguard so git/PR URLs are not resolved as filesystem paths incheckOutputDirectoryorpipeline.runparseOutputArg.ts: Same PR URL handling for the no-config (flags-only) code path--outputCLI help text to mention PR URL supportHuman Review Checklist
forceLocalpropagation: InhandleWithWorkspace,validateArgsreceivesargs.local || forceLocalbutrunGenerationreceives originalargs+ separateforceLocalparam — verifyrunGenerationrespects theforceLocalflag independently (it does viaisLocalon line 250)parseOutputArg.tsusage: Grep shows no imports of this file — confirm whether it is dead code or dynamically referencedoutputPath: undefined: WhenisRemoteOutputis true,pipeline.runreceivesoutputPath: undefined. Verify this doesn't cause issues downstream inresolveTargetOutput— the git output config ontarget.output.gitshould be the primary output mechanism in this caseTesting
pnpm run check)GITHUB_TOKENto verify end-to-endLink to Devin session: https://app.devin.ai/sessions/9ec43fea26df4a57b4357ec778c86d8a
Requested by: @Swimburger