Skip to content

Commit dacb6c6

Browse files
committed
Opens all changes after open in worktree flow finished for PRs
1 parent 51d03bd commit dacb6c6

File tree

7 files changed

+68
-12
lines changed

7 files changed

+68
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17924,7 +17924,7 @@
1792417924
"lint:fix": "pnpm run clean:lint && eslint . --fix",
1792517925
"lint:webviews": "pnpm run clean:lint && eslint \"src/webviews/apps/**/*.ts?(x)\"",
1792617926
"package": "vsce package --no-dependencies",
17927-
"package-pre": "pnpm run patch-pre && pnpm run package --pre-release",
17927+
"//package-pre": "pnpm run patch-pre && pnpm run package --pre-release",
1792817928
"patch-pre": "node ./scripts/applyPreReleasePatch.mjs",
1792917929
"prep-release": "node ./scripts/prep-release.mjs",
1793017930
"pretty": "prettier --config .prettierrc --write .",
@@ -17946,7 +17946,7 @@
1794617946
"update-emoji": "node ./scripts/generateEmojiShortcodeMap.mjs",
1794717947
"update-licenses": "node ./scripts/generateLicenses.mjs",
1794817948
"pretest": "pnpm run build:tests",
17949-
"vscode:prepublish": "pnpm run bundle"
17949+
"//vscode:prepublish": "pnpm run bundle"
1795017950
},
1795117951
"dependencies": {
1795217952
"@gitkraken/gitkraken-components": "10.7.0",

src/commands/git/worktree.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ interface CreateState {
102102
title?: string;
103103
};
104104

105+
prId?: string;
106+
105107
onWorkspaceChanging?: (() => Promise<void>) | (() => void);
106108
skipWorktreeConfirmations?: boolean;
107109
}
@@ -128,6 +130,8 @@ interface OpenState {
128130
worktree: GitWorktree;
129131
flags: OpenFlags[];
130132

133+
prId?: string;
134+
131135
openOnly?: boolean;
132136
overrides?: {
133137
disallowBack?: boolean;

src/git/actions/worktree.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ export function copyChangesToWorktree(
5656
});
5757
}
5858

59-
export function open(worktree: GitWorktree, options?: { location?: OpenWorkspaceLocation; openOnly?: boolean }) {
59+
export function open(
60+
worktree: GitWorktree,
61+
options?: { location?: OpenWorkspaceLocation; openOnly?: boolean; prId?: string },
62+
) {
6063
return executeGitCommand({
6164
command: 'worktree',
6265
state: {
6366
subcommand: 'open',
67+
prId: options?.prId,
6468
repo: worktree.repoPath,
6569
worktree: worktree,
6670
flags: convertLocationToOpenFlags(options?.location),

src/plus/launchpad/launchpadProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ export function getPullRequestBranchDeepLink(
10231023
headRefBranchName: string,
10241024
remoteUrl: string,
10251025
action?: DeepLinkActionType,
1026+
prId?: string,
10261027
) {
10271028
const schemeOverride = configuration.get('deepLinks.schemeOverride');
10281029
const scheme = typeof schemeOverride === 'string' ? schemeOverride : env.uriScheme;
@@ -1033,7 +1034,7 @@ export function getPullRequestBranchDeepLink(
10331034
DeepLinkType.Branch
10341035
}/${encodeURIComponent(headRefBranchName)}?url=${encodeURIComponent(ensureRemoteUrl(remoteUrl))}${
10351036
action != null ? `&action=${action}` : ''
1036-
}`,
1037+
}${prId != null ? `&prId=${prId}` : ''}`,
10371038
);
10381039
}
10391040

src/uris/deepLinks/deepLink.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export interface DeepLink {
9292
secondaryTargetId?: string;
9393
secondaryRemoteUrl?: string;
9494
action?: string;
95+
prId?: string;
9596
params?: URLSearchParams;
9697
}
9798

@@ -170,6 +171,7 @@ export function parseDeepLinkUri(uri: Uri): DeepLink | undefined {
170171
secondaryRemoteUrl: secondaryRemoteUrl,
171172
action: action,
172173
params: urlParams,
174+
prId: urlParams.get('prId') ?? undefined,
173175
};
174176
}
175177
case DeepLinkType.Draft: {
@@ -231,6 +233,7 @@ export const enum DeepLinkServiceState {
231233
OpenInspect,
232234
SwitchToRef,
233235
RunCommand,
236+
OpenAllPrChanges,
234237
}
235238

236239
export const enum DeepLinkServiceAction {
@@ -263,6 +266,7 @@ export const enum DeepLinkServiceAction {
263266
OpenFile,
264267
OpenInspect,
265268
OpenSwitch,
269+
OpenAllPrChanges,
266270
}
267271

268272
export type DeepLinkRepoOpenType = 'clone' | 'folder' | 'workspace' | 'current';
@@ -284,6 +288,7 @@ export interface DeepLinkServiceContext {
284288
targetSha?: string | undefined;
285289
secondaryTargetSha?: string | undefined;
286290
action?: string | undefined;
291+
prId?: string | undefined;
287292
repoOpenLocation?: OpenWorkspaceLocation | undefined;
288293
repoOpenUri?: Uri | undefined;
289294
params?: URLSearchParams | undefined;
@@ -409,6 +414,12 @@ export const deepLinkStateTransitionTable: Record<string, Record<string, DeepLin
409414
[DeepLinkServiceAction.DeepLinkCancelled]: DeepLinkServiceState.Idle,
410415
},
411416
[DeepLinkServiceState.OpenInspect]: {
417+
[DeepLinkServiceAction.OpenAllPrChanges]: DeepLinkServiceState.OpenAllPrChanges,
418+
[DeepLinkServiceAction.DeepLinkResolved]: DeepLinkServiceState.Idle,
419+
[DeepLinkServiceAction.DeepLinkErrored]: DeepLinkServiceState.Idle,
420+
[DeepLinkServiceAction.DeepLinkCancelled]: DeepLinkServiceState.Idle,
421+
},
422+
[DeepLinkServiceState.OpenAllPrChanges]: {
412423
[DeepLinkServiceAction.DeepLinkResolved]: DeepLinkServiceState.Idle,
413424
[DeepLinkServiceAction.DeepLinkErrored]: DeepLinkServiceState.Idle,
414425
[DeepLinkServiceAction.DeepLinkCancelled]: DeepLinkServiceState.Idle,

src/uris/deepLinks/deepLinkService.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { Commands } from '../../constants.commands';
44
import type { StoredDeepLinkContext, StoredNamedRef } from '../../constants.storage';
55
import type { Container } from '../../container';
66
import { executeGitCommand } from '../../git/actions';
7-
import { openFileAtRevision } from '../../git/actions/commit';
7+
import { openComparisonChanges, openFileAtRevision } from '../../git/actions/commit';
88
import type { GitBranch } from '../../git/models/branch';
99
import { getBranchNameWithoutRemote } from '../../git/models/branch';
1010
import type { GitCommit } from '../../git/models/commit';
11+
import type { PullRequest } from '../../git/models/pullRequest';
12+
import { getComparisonRefsForPullRequest } from '../../git/models/pullRequest';
1113
import type { GitReference } from '../../git/models/reference';
1214
import { createReference, isSha } from '../../git/models/reference';
1315
import type { Repository, RepositoryChangeEvent } from '../../git/models/repository';
@@ -19,6 +21,7 @@ import { missingRepositoryId } from '../../gk/models/repositoryIdentities';
1921
import { ensureAccount, ensurePaidPlan } from '../../plus/utils';
2022
import type { ShowInCommitGraphCommandArgs } from '../../plus/webviews/graph/protocol';
2123
import { createQuickPickSeparator } from '../../quickpicks/items/common';
24+
import { debug } from '../../system/decorators/log';
2225
import { once } from '../../system/event';
2326
import { Logger } from '../../system/logger';
2427
import { normalizePath } from '../../system/path';
@@ -68,10 +71,7 @@ export class DeepLinkService implements Disposable {
6871
this._disposables.push(container.uri.onDidReceiveUri(async (uri: Uri) => this.processDeepLinkUri(uri)));
6972

7073
const pendingDeepLink = this.container.storage.get('deepLinks:pending');
71-
if (pendingDeepLink != null) {
72-
void this.container.storage.delete('deepLinks:pending');
73-
void this.processPendingDeepLink(pendingDeepLink);
74-
}
74+
void this.processPendingDeepLink(pendingDeepLink);
7575
}
7676

7777
dispose() {
@@ -114,6 +114,7 @@ export class DeepLinkService implements Disposable {
114114
targetId: link.targetId,
115115
secondaryTargetId: link.secondaryTargetId,
116116
secondaryRemoteUrl: link.secondaryRemoteUrl,
117+
prId: link.prId,
117118
action: link.action,
118119
params: link.params,
119120
};
@@ -241,8 +242,10 @@ export class DeepLinkService implements Disposable {
241242
}
242243
}
243244

244-
private async processPendingDeepLink(pendingDeepLink: StoredDeepLinkContext) {
245-
if (pendingDeepLink.url == null) return;
245+
@debug()
246+
private async processPendingDeepLink(pendingDeepLink: StoredDeepLinkContext | undefined) {
247+
if (pendingDeepLink?.url == null) return;
248+
void this.container.storage.delete('deepLinks:pending');
246249

247250
const link = parseDeepLinkUri(Uri.parse(pendingDeepLink.url));
248251
if (link == null) return;
@@ -312,6 +315,19 @@ export class DeepLinkService implements Disposable {
312315
return repo.git.getBranch(targetId);
313316
}
314317

318+
private async getPullRequest(targetId: string): Promise<PullRequest | undefined> {
319+
const { repo, remote } = this._context;
320+
if (!repo) return undefined;
321+
const pullRequests = remote
322+
? await this.container.integrations.getMyPullRequestsForRemotes(remote)
323+
: await this.container.integrations.getMyPullRequests();
324+
325+
if (!pullRequests?.value) {
326+
return;
327+
}
328+
return pullRequests.value.find(x => x.pullRequest.id === targetId)?.pullRequest;
329+
}
330+
315331
private async getCommit(targetId: string): Promise<GitCommit | undefined> {
316332
const { repo } = this._context;
317333
if (!repo) return undefined;
@@ -509,6 +525,7 @@ export class DeepLinkService implements Disposable {
509525
// TODO @axosoft-ramint: Move all the logic for matching a repo, prompting to add repo, matching remote, etc. for a target (branch, PR, etc.)
510526
// to a separate service where it can be used outside of the context of deep linking. Then the deep link service should leverage it,
511527
// and we should stop using deep links to process things like Launchpad switch actions, Open in Worktree command, etc.
528+
@debug()
512529
private async processDeepLink(
513530
initialAction: DeepLinkServiceAction = DeepLinkServiceAction.DeepLinkEventFired,
514531
useProgress: boolean = true,
@@ -1373,7 +1390,6 @@ export class DeepLinkService implements Disposable {
13731390
case DeepLinkServiceState.OpenInspect: {
13741391
// If we arrive at this step, clear any stored data used for the "new window" option
13751392
await this.container.storage.delete('deepLinks:pending');
1376-
13771393
if (!repo) {
13781394
action = DeepLinkServiceAction.DeepLinkErrored;
13791395
message = 'Missing repository.';
@@ -1386,6 +1402,25 @@ export class DeepLinkService implements Disposable {
13861402
repository: repo,
13871403
source: 'launchpad',
13881404
} satisfies ShowWipArgs);
1405+
if (this._context.prId) {
1406+
action = DeepLinkServiceAction.OpenAllPrChanges;
1407+
} else {
1408+
action = DeepLinkServiceAction.DeepLinkResolved;
1409+
}
1410+
break;
1411+
}
1412+
case DeepLinkServiceState.OpenAllPrChanges: {
1413+
const pr = await this.getPullRequest(this._context.prId!);
1414+
const refs = getComparisonRefsForPullRequest(this._context.repoPath!, pr!.refs!);
1415+
await openComparisonChanges(
1416+
this.container,
1417+
{
1418+
repoPath: refs.repoPath,
1419+
lhs: refs.base.ref,
1420+
rhs: refs.head.ref,
1421+
},
1422+
{ title: `Changes in Pull Request "${pr!.title}"` },
1423+
);
13891424
action = DeepLinkServiceAction.DeepLinkResolved;
13901425
break;
13911426
}

src/views/viewCommands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ export class ViewCommands {
808808
pr.refs.head.branch,
809809
repoIdentity.remote.url,
810810
DeepLinkActionType.SwitchToPullRequestWorktree,
811+
pr.id,
811812
);
812813

813814
const prRepo = await getOrOpenPullRequestRepository(this.container, pr, {

0 commit comments

Comments
 (0)