pull/19214/merge
Shawn 2026-04-08 06:49:26 +00:00 committed by GitHub
commit 0c0a609091
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View File

@ -72,7 +72,7 @@ type GitHubPullRequest = {
}
headRepository: {
nameWithOwner: string
}
} | null
commits: {
totalCount: number
nodes: Array<{
@ -163,8 +163,8 @@ try {
// 3. Fork PR
if (isPullRequest()) {
const prData = await fetchPR()
// Local PR
if (prData.headRepository.nameWithOwner === prData.baseRepository.nameWithOwner) {
// Local PR (headRepository is null when the fork has been deleted)
if (prData.headRepository?.nameWithOwner === prData.baseRepository.nameWithOwner) {
await checkoutLocalBranch(prData)
const dataPrompt = buildPromptDataForPR(prData)
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
@ -698,6 +698,9 @@ async function checkoutForkBranch(pr: GitHubPullRequest) {
const localBranch = generateBranchName("pr")
const depth = Math.max(pr.commits.totalCount, 20)
if (!pr.headRepository?.nameWithOwner) {
throw new Error("Cannot checkout fork branch: headRepository is not available (the fork may have been deleted)")
}
await $`git remote add fork https://github.com/${pr.headRepository.nameWithOwner}.git`
await $`git fetch fork --depth=${depth} ${remoteBranch}`
await $`git checkout -b ${localBranch} fork/${remoteBranch}`

View File

@ -94,7 +94,7 @@ type GitHubPullRequest = {
}
headRepository: {
nameWithOwner: string
}
} | null
commits: {
totalCount: number
nodes: Array<{
@ -606,8 +606,8 @@ export const GithubRunCommand = cmd({
issueEvent?.issue.pull_request
) {
const prData = await fetchPR()
// Local PR
if (prData.headRepository.nameWithOwner === prData.baseRepository.nameWithOwner) {
// Local PR (headRepository is null when the fork has been deleted)
if (prData.headRepository?.nameWithOwner === prData.baseRepository.nameWithOwner) {
await checkoutLocalBranch(prData)
const head = await gitText(["rev-parse", "HEAD"])
const dataPrompt = buildPromptDataForPR(prData)
@ -1113,6 +1113,9 @@ export const GithubRunCommand = cmd({
const localBranch = generateBranchName("pr")
const depth = Math.max(pr.commits.totalCount, 20)
if (!pr.headRepository?.nameWithOwner) {
throw new Error("Cannot checkout fork branch: headRepository is not available (the fork may have been deleted)")
}
await gitRun(["remote", "add", "fork", `https://github.com/${pr.headRepository.nameWithOwner}.git`])
await gitRun(["fetch", "fork", `--depth=${depth}`, remoteBranch])
await gitRun(["checkout", "-b", localBranch, `fork/${remoteBranch}`])