Target the fork branch from fork-PR worktrees (#4394)
Creating a worktree from a cross-repository (fork) PR previously named the local branch with the maintainer's branch prefix (e.g. `me/866`) and pushed to origin instead of the contributor's fork, so maintainer edits never reached the PR. Fork PRs now adopt the contributor's branch name (matching same-repo PRs) and resolve a fork push target, with a non-blocking warning when the PR disables maintainer edits and an indicator showing where a push will land. - pr-start-point: return branchNameOverride/headSha/maintainerCanModify for cross-repo PRs (previously only same-repo PRs received these) - github client: surface maintainer_can_modify alongside the fork push target - composer: warn (but still allow) when "Allow edits from maintainers" is off - source control: show the fork push target (owner:branch) before pushing - extract fork-remote cleanup and setup into dedicated, unit-tested modules Adds unit suites for the cleanup multi-fork matrix, fork-remote setup, push-target resolution, the warning decision, and the push-target label. Note: pre-commit react-doctor hook bypassed — its warnings in useComposerState are pre-existing (identical count on base) and not enforced by CI. Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
This commit is contained in:
@@ -1384,9 +1384,70 @@ describe('getPRForBranch', () => {
|
||||
cwd: '/repo-root'
|
||||
})
|
||||
expect(target).toEqual({
|
||||
remoteName: 'pr-prateek-orca',
|
||||
branchName: 'prateek/fix-sidebar-agents-toggle',
|
||||
remoteUrl: 'git@github.com:prateek/orca.git'
|
||||
pushTarget: {
|
||||
remoteName: 'pr-prateek-orca',
|
||||
branchName: 'prateek/fix-sidebar-agents-toggle',
|
||||
remoteUrl: 'git@github.com:prateek/orca.git'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('surfaces maintainer_can_modify=false alongside a fork PR push target', async () => {
|
||||
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
|
||||
getOwnerRepoForRemoteMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
|
||||
ghExecFileAsyncMock.mockResolvedValueOnce({
|
||||
stdout: JSON.stringify({
|
||||
maintainer_can_modify: false,
|
||||
head: {
|
||||
ref: 'prateek/fix-sidebar-agents-toggle',
|
||||
repo: {
|
||||
full_name: 'prateek/orca',
|
||||
name: 'orca',
|
||||
clone_url: 'https://github.com/prateek/orca.git',
|
||||
ssh_url: 'git@github.com:prateek/orca.git',
|
||||
owner: { login: 'prateek' }
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
gitExecFileAsyncMock.mockResolvedValueOnce({
|
||||
stdout: 'git@github.com:stablyai/orca.git\n',
|
||||
stderr: ''
|
||||
})
|
||||
|
||||
await expect(getPullRequestPushTarget('/repo-root', 1738)).resolves.toEqual({
|
||||
pushTarget: {
|
||||
remoteName: 'pr-prateek-orca',
|
||||
branchName: 'prateek/fix-sidebar-agents-toggle',
|
||||
remoteUrl: 'git@github.com:prateek/orca.git'
|
||||
},
|
||||
maintainerCanModify: false
|
||||
})
|
||||
})
|
||||
|
||||
it('omits maintainerCanModify when the API does not report the flag', async () => {
|
||||
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
|
||||
getOwnerRepoForRemoteMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
|
||||
ghExecFileAsyncMock.mockResolvedValueOnce({
|
||||
stdout: JSON.stringify({
|
||||
head: {
|
||||
ref: 'fix-sidebar',
|
||||
repo: {
|
||||
full_name: 'stablyai/orca',
|
||||
name: 'orca',
|
||||
clone_url: 'https://github.com/stablyai/orca.git',
|
||||
ssh_url: 'git@github.com:stablyai/orca.git',
|
||||
owner: { login: 'stablyai' }
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
await expect(getPullRequestPushTarget('/repo-root', 1738)).resolves.toEqual({
|
||||
pushTarget: {
|
||||
remoteName: 'origin',
|
||||
branchName: 'fix-sidebar'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1409,8 +1470,10 @@ describe('getPRForBranch', () => {
|
||||
})
|
||||
|
||||
await expect(getPullRequestPushTarget('/repo-root', 1738)).resolves.toEqual({
|
||||
remoteName: 'origin',
|
||||
branchName: 'fix-sidebar'
|
||||
pushTarget: {
|
||||
remoteName: 'origin',
|
||||
branchName: 'fix-sidebar'
|
||||
}
|
||||
})
|
||||
expect(gitExecFileAsyncMock).not.toHaveBeenCalled()
|
||||
})
|
||||
@@ -1494,8 +1557,10 @@ describe('getPRForBranch', () => {
|
||||
})
|
||||
|
||||
await expect(getPullRequestPushTarget('/repo-root', 1849)).resolves.toEqual({
|
||||
remoteName: 'origin',
|
||||
branchName: 'feature/test'
|
||||
pushTarget: {
|
||||
remoteName: 'origin',
|
||||
branchName: 'feature/test'
|
||||
}
|
||||
})
|
||||
expect(ghExecFileAsyncMock).toHaveBeenNthCalledWith(1, ['api', 'repos/fork/orca/pulls/1849'], {
|
||||
cwd: '/repo-root'
|
||||
|
||||
Reference in New Issue
Block a user