-
Notifications
You must be signed in to change notification settings - Fork 336
feat(cli-v2): support --output with GitHub PR URLs in fern generate
#14901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8aa67f4
feat: support --output with GitHub PR URLs in fern generate
Swimburger 8c41950
fix: skip filesystem path resolution when --output is a git/PR URL
Swimburger 0cfbef5
fix: use head.repo.full_name for fork-based PRs
Swimburger b9c5f2c
refactor: use @octokit/rest instead of raw fetch for GitHub API
Swimburger 7aa1359
security: reject fork-based PRs to prevent pushing to unintended repos
Swimburger 612e207
fix: return full URL for uri instead of owner/repo format
Swimburger f301871
fix: use case-insensitive comparison for fork detection
Swimburger 1a56e22
fix: require --local when --output is a PR URL instead of auto-forcing
Swimburger 65f75a4
fix: restore forced-local for no-config mode (handleWithFlags)
Swimburger 6e04acc
fix: add --local check for git URLs in parseOutputArg for consistency
Swimburger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
30 changes: 28 additions & 2 deletions
30
packages/cli/cli-v2/src/commands/sdk/generate/parseOutputArg.ts
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
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
42 changes: 42 additions & 0 deletions
42
packages/cli/cli-v2/src/commands/sdk/utils/resolveGithubPrBranch.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { GithubPrUrlInfo } from "./gitUrl.js"; | ||
|
|
||
| interface GithubPrBranchInfo { | ||
| /** The head branch of the PR (e.g. "my-feature-branch") */ | ||
| branch: string; | ||
| /** The repository URI as "owner/repo" */ | ||
| uri: string; | ||
| } | ||
|
|
||
| /** | ||
| * Fetches the head branch name of a GitHub pull request. | ||
| * | ||
| * Uses the GitHub REST API. Requires a token with read access to the repository. | ||
| */ | ||
| export async function resolveGithubPrBranch(pr: GithubPrUrlInfo, token: string): Promise<GithubPrBranchInfo> { | ||
| const url = `https://api.github.com/repos/${pr.owner}/${pr.repo}/pulls/${pr.prNumber}`; | ||
| const response = await fetch(url, { | ||
| headers: { | ||
| Authorization: `Bearer ${token}`, | ||
| Accept: "application/vnd.github.v3+json", | ||
| "User-Agent": "fern-cli" | ||
| } | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| const body = await response.text().catch(() => ""); | ||
| throw new Error( | ||
| `Failed to fetch PR #${pr.prNumber} from ${pr.owner}/${pr.repo}: ${response.status} ${response.statusText}${body ? `\n${body}` : ""}` | ||
| ); | ||
| } | ||
|
|
||
| const data = (await response.json()) as { head?: { ref?: string } }; | ||
| const branch = data.head?.ref; | ||
| if (branch == null) { | ||
| throw new Error(`Could not determine head branch for PR #${pr.prNumber}`); | ||
| } | ||
|
|
||
| return { | ||
| branch, | ||
| uri: `${pr.owner}/${pr.repo}` | ||
| }; | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
Outdated
devin-ai-integration[bot] marked this conversation as resolved.
|
||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # yaml-language-server: $schema=../../../../../fern-changes-yml.schema.json | ||
|
|
||
| - summary: | | ||
| Support GitHub PR URLs in `--output` flag for `fern generate`. When a PR URL | ||
| like `https://github.com/owner/repo/pull/123` is provided, the CLI resolves | ||
| the PR's head branch and pushes generated code directly to it. | ||
| type: feat |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.