Skip to content

Commit f00abb9

Browse files
committed
fix(github): Include owner in head parameter for PRs from forks
1 parent 239accc commit f00abb9

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

apps/desktop/src/components/ReviewCreation.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import { StackService } from '$lib/stacks/stackService.svelte';
3131
import { UserService } from '$lib/user/userService';
3232
import { getBranchNameFromRef } from '$lib/utils/branch';
33+
import { parseRemoteUrl } from '$lib/url/gitUrl';
3334
import { sleep } from '$lib/utils/sleep';
3435
import { getContext } from '@gitbutler/shared/context';
3536
import { persisted } from '@gitbutler/shared/persisted';
@@ -41,6 +42,7 @@
4142
import { error } from '@gitbutler/ui/toasts';
4243
import { isDefined } from '@gitbutler/ui/utils/typeguards';
4344
import { tick } from 'svelte';
45+
import { RemotesService } from '$lib/remotes/remotesService';
4446
4547
type Props = {
4648
projectId: string;
@@ -63,6 +65,7 @@
6365
const userService = getContext(UserService);
6466
const templateService = getContext(TemplateService);
6567
const aiService = getContext(AIService);
68+
const remotesService = getContext(RemotesService);
6669
6770
const user = userService.user;
6871
const project = projectsService.getProjectStore(projectId);
@@ -276,12 +279,21 @@
276279
base = branchParent.name;
277280
}
278281
282+
const pushRemoteName = baseBranch.actualPushRemoteName();
283+
const allRemotes = await remotesService.remotes(projectId);
284+
const pushRemote = allRemotes.find((r) => r.name === pushRemoteName);
285+
const pushRemoteUrl = pushRemote?.url;
286+
287+
const repoInfo = parseRemoteUrl(pushRemoteUrl);
288+
const headOwner = repoInfo?.owner;
289+
279290
const pr = await prService.createPr({
280291
title: params.title,
281292
body: params.body,
282293
draft: params.draft,
283294
baseBranchName: base,
284-
upstreamName: params.upstreamBranchName
295+
upstreamName: params.upstreamBranchName,
296+
headOwner
285297
});
286298
287299
// Store the new pull request number with the branch data.

apps/desktop/src/lib/forge/github/githubPrService.svelte.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ export class GitHubPrService implements ForgePrService {
3636
body,
3737
draft,
3838
baseBranchName,
39-
upstreamName
39+
upstreamName,
40+
headOwner
4041
}: CreatePullRequestArgs): Promise<PullRequest> {
4142
this.loading.set(true);
4243
const request = async () => {
44+
const head = headOwner ? `${headOwner}:${upstreamName}` : upstreamName;
4345
return ghResponseToInstance(
4446
await this.api.endpoints.createPr.mutate({
45-
head: upstreamName,
47+
head,
4648
base: baseBranchName,
4749
title,
4850
body,

apps/desktop/src/lib/forge/interface/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@ export type CreatePullRequestArgs = {
8888
draft: boolean;
8989
baseBranchName: string;
9090
upstreamName: string;
91+
headOwner?: string;
9192
};

0 commit comments

Comments
 (0)