-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Target pull requests at upstream repositories #3900
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
base: main
Are you sure you want to change the base?
Changes from all commits
cb9cf66
7f560fc
191fbd5
f314e17
f4f6e83
2527278
e9cd27e
849a0d2
10aeb38
9860b6e
04207d9
ea408ad
979fef3
e190a4e
a624695
2edec75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,8 @@ import { | |
| import { | ||
| detectSourceControlProviderFromGitRemoteUrl, | ||
| mergeGitStatusParts, | ||
| normalizeGitRemoteUrl, | ||
| parseGitHubRepositoryNameWithOwnerFromRemoteUrl, | ||
| resolveAutoFeatureBranchName, | ||
| sanitizeBranchFragment, | ||
| sanitizeFeatureBranchName, | ||
|
|
@@ -93,6 +95,7 @@ const COMMIT_TIMEOUT_MS = 10 * 60_000; | |
| const MAX_PROGRESS_TEXT_LENGTH = 500; | ||
| const SHORT_SHA_LENGTH = 7; | ||
| const TOAST_DESCRIPTION_MAX = 72; | ||
| const OPEN_PULL_REQUEST_CANDIDATE_LIMIT = 100; | ||
| const STATUS_RESULT_CACHE_TTL = Duration.seconds(1); | ||
| const STATUS_RESULT_CACHE_CAPACITY = 2_048; | ||
| type StripProgressContext<T> = T extends any ? Omit<T, "actionId" | "cwd" | "action"> : never; | ||
|
|
@@ -187,20 +190,6 @@ function resolvePullRequestWorktreeLocalBranchName( | |
| return `t3code/pr-${pullRequest.number}/${suffix}`; | ||
| } | ||
|
|
||
| function parseGitHubRepositoryNameWithOwnerFromRemoteUrl(url: string | null): string | null { | ||
| const trimmed = url?.trim() ?? ""; | ||
| if (trimmed.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const match = | ||
| /^(?:git@github\.com:|ssh:\/\/git@github\.com\/|https:\/\/github\.com\/|git:\/\/github\.com\/)([^/\s]+\/[^/\s]+?)(?:\.git)?\/?$/i.exec( | ||
| trimmed, | ||
| ); | ||
| const repositoryNameWithOwner = match?.[1]?.trim() ?? ""; | ||
| return repositoryNameWithOwner.length > 0 ? repositoryNameWithOwner : null; | ||
| } | ||
|
|
||
| function parseRepositoryOwnerLogin(nameWithOwner: string | null): string | null { | ||
| const trimmed = nameWithOwner?.trim() ?? ""; | ||
| if (trimmed.length === 0) { | ||
|
|
@@ -278,17 +267,10 @@ function matchesBranchHeadContext( | |
| if ((expectedHeadRepository || expectedHeadOwner) && !prHeadRepository && !prHeadOwner) { | ||
| return false; | ||
| } | ||
| if (expectedHeadRepository && prHeadRepository && expectedHeadRepository !== prHeadRepository) { | ||
| } else if (pr.isCrossRepository === true) { | ||
| if (!expectedHeadRepository || !prHeadRepository) { | ||
| return false; | ||
| } | ||
| if (expectedHeadOwner && prHeadOwner && expectedHeadOwner !== prHeadOwner) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| if (pr.isCrossRepository === true) { | ||
| return false; | ||
| } | ||
| if (expectedHeadRepository && prHeadRepository && expectedHeadRepository !== prHeadRepository) { | ||
| return false; | ||
|
|
@@ -937,7 +919,7 @@ export const make = Effect.gen(function* () { | |
| cwd, | ||
| headSelector, | ||
| state: "open", | ||
| limit: 1, | ||
| limit: OPEN_PULL_REQUEST_CANDIDATE_LIMIT, | ||
| }); | ||
| const normalizedPullRequests = pullRequests.map(toPullRequestInfo); | ||
|
|
||
|
|
@@ -1119,6 +1101,45 @@ export const make = Effect.gen(function* () { | |
| cwd: string, | ||
| baseBranch: string, | ||
| ) { | ||
| const provider = yield* sourceControlProvider(cwd); | ||
| const targetCloneUrls = provider.getTargetRepositoryCloneUrls | ||
| ? yield* provider.getTargetRepositoryCloneUrls({ cwd }).pipe(Effect.orElseSucceed(() => null)) | ||
| : null; | ||
| if (targetCloneUrls) { | ||
| const originUrl = yield* readConfigValueNullable(cwd, "remote.origin.url"); | ||
| const targetMatchesOrigin = | ||
| originUrl !== null && | ||
| [targetCloneUrls.url, targetCloneUrls.sshUrl].some( | ||
| (targetUrl) => normalizeGitRemoteUrl(targetUrl) === normalizeGitRemoteUrl(originUrl), | ||
| ); | ||
| const resolveTargetBaseRangeRef = Effect.gen(function* () { | ||
| const targetUrl = shouldPreferSshRemote(originUrl) | ||
| ? targetCloneUrls.sshUrl | ||
| : targetCloneUrls.url; | ||
| const remoteName = yield* gitCore.ensureRemote({ | ||
| cwd, | ||
| preferredName: "upstream", | ||
| url: targetUrl, | ||
| }); | ||
| yield* gitCore.fetchRemoteTrackingBranch({ | ||
| cwd, | ||
| remoteName, | ||
| remoteBranch: baseBranch, | ||
| }); | ||
| return yield* gitCore | ||
| .resolveRemoteTrackingCommit({ | ||
| cwd, | ||
| refName: baseBranch, | ||
| fallbackRemoteName: remoteName, | ||
| }) | ||
| .pipe(Effect.map((resolved) => resolved.commitSha)); | ||
| }); | ||
| const targetBaseRangeRef = targetMatchesOrigin | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium When 🤖 Copy this AI Prompt to have your agent fix this:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in a6246954b — the regression test now makes the intended fork behavior explicit: if the upstream base cannot be fetched, PR content generation stops rather than silently using a stale fork
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I'm unable to act on this request because you do not have permissions within this repository. |
||
| ? yield* resolveTargetBaseRangeRef.pipe(Effect.orElseSucceed(() => null)) | ||
| : yield* resolveTargetBaseRangeRef; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same-repo check misses SSH aliasesMedium Severity
Reviewed by Cursor Bugbot for commit 2edec75. Configure here.
Comment on lines
+1137
to
+1139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For same-repo GitHub checkouts whose Useful? React with 👍 / 👎. |
||
| if (targetBaseRangeRef) return targetBaseRangeRef; | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| const remoteName = yield* gitCore | ||
| .resolvePrimaryRemoteName(cwd) | ||
| .pipe(Effect.orElseSucceed(() => null)); | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For self-hosted GitHub fork checkouts,
resolveRemoteRepositoryContextleavesexpectedHeadRepositoryempty becauseparseGitHubRepositoryNameWithOwnerFromRemoteUrlonly recognizesgithub.comremotes, while the new upstream-targetedlistPullRequestscan still returnisCrossRepository: truePRs from the fork. This branch rejects those matches whenever the expected repo is missing, socreate_pron an existing GHES upstream PR will miss it and proceed togh pr create(or, after creation, fail to recover the PR URL/number).Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 849a0d275 — GitHub Enterprise remote URLs now resolve their owner/repository identity and existing cross-repository PRs are matched without duplicate creation.