Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/git/models/pullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export function getVirtualUriForPullRequest(pr: PullRequest): Uri | undefined {
export async function getOrOpenPullRequestRepository(
container: Container,
pr: PullRequest,
options?: { promptIfNeeded?: boolean },
options?: { promptIfNeeded?: boolean; skipVirtual?: boolean },
): Promise<Repository | undefined> {
const identity = getRepositoryIdentityForPullRequest(pr);
let repo = await container.repositoryIdentity.getRepository(identity, {
Expand All @@ -318,7 +318,7 @@ export async function getOrOpenPullRequestRepository(
prompt: false,
});

if (repo == null) {
if (repo == null && !options?.skipVirtual) {
const virtualUri = getVirtualUriForPullRequest(pr);
if (virtualUri != null) {
repo = await container.git.getOrOpenRepository(virtualUri, { closeOnOpen: true, detectNested: false });
Expand Down
11 changes: 9 additions & 2 deletions src/plus/launchpad/launchpadProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import type { Account } from '../../git/models/author';
import type { GitBranch } from '../../git/models/branch';
import { getLocalBranchByUpstream } from '../../git/models/branch';
import type { PullRequest, SearchedPullRequest } from '../../git/models/pullRequest';
import { getComparisonRefsForPullRequest, getRepositoryIdentityForPullRequest } from '../../git/models/pullRequest';
import {
getComparisonRefsForPullRequest,
getOrOpenPullRequestRepository,
getRepositoryIdentityForPullRequest,
} from '../../git/models/pullRequest';
import type { GitRemote } from '../../git/models/remote';
import type { Repository } from '../../git/models/repository';
import type { CodeSuggestionCounts, Draft } from '../../gk/models/drafts';
Expand Down Expand Up @@ -488,8 +492,11 @@ export class LaunchpadProvider implements Disposable {
);
if (deepLinkUrl == null) return;

const prRepo = await getOrOpenPullRequestRepository(this.container, item.underlyingPullRequest, {
skipVirtual: true,
});
this._codeSuggestions?.delete(item.uuid);
await this.container.deepLinks.processDeepLinkUri(deepLinkUrl, false);
await this.container.deepLinks.processDeepLinkUri(deepLinkUrl, false, prRepo);
}

@log<LaunchpadProvider['openChanges']>({ args: { 0: i => `${i.id} (${i.provider.name} ${i.type})` } })
Expand Down
18 changes: 13 additions & 5 deletions src/uris/deepLinks/deepLinkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getBranchNameWithoutRemote } from '../../git/models/branch';
import type { GitCommit } from '../../git/models/commit';
import type { GitReference } from '../../git/models/reference';
import { createReference, isSha } from '../../git/models/reference';
import type { RepositoryChangeEvent } from '../../git/models/repository';
import type { Repository, RepositoryChangeEvent } from '../../git/models/repository';
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../git/models/repository';
import type { GitTag } from '../../git/models/tag';
import { parseGitRemoteUrl } from '../../git/parsers/remoteParser';
Expand Down Expand Up @@ -100,7 +100,7 @@ export class DeepLinkService implements Disposable {
};
}

private setContextFromDeepLink(link: DeepLink, url: string) {
private setContextFromDeepLink(link: DeepLink, url: string, repo?: Repository) {
this._context = {
...this._context,
mainId: link.mainId,
Expand All @@ -115,9 +115,14 @@ export class DeepLinkService implements Disposable {
action: link.action,
params: link.params,
};

if (repo != null) {
this._context.repo = repo;
this._context.repoPath = repo.path;
}
}

async processDeepLinkUri(uri: Uri, useProgress: boolean = true) {
async processDeepLinkUri(uri: Uri, useProgress: boolean = true, repo?: Repository) {
const link = parseDeepLinkUri(uri);
if (link == null) return;

Expand Down Expand Up @@ -150,7 +155,7 @@ export class DeepLinkService implements Disposable {
return;
}

this.setContextFromDeepLink(link, uri.toString());
this.setContextFromDeepLink(link, uri.toString(), repo);

await this.processDeepLink(undefined, useProgress);
}
Expand Down Expand Up @@ -499,6 +504,9 @@ export class DeepLinkService implements Disposable {
return remoteName;
}

// TODO @axosoft-ramint: Move all the logic for matching a repo, prompting to add repo, matching remote, etc. for a target (branch, PR, etc.)
// to a separate service where it can be used outside of the context of deep linking. Then the deep link service should leverage it,
// and we should stop using deep links to process things like Launchpad switch actions, Open in Worktree command, etc.
private async processDeepLink(
initialAction: DeepLinkServiceAction = DeepLinkServiceAction.DeepLinkEventFired,
useProgress: boolean = true,
Expand Down Expand Up @@ -660,7 +668,7 @@ export class DeepLinkService implements Disposable {
}
case DeepLinkServiceState.RepoMatch:
case DeepLinkServiceState.AddedRepoMatch: {
if (repo != null && repoOpenUri != null && repoOpenLocation != null) {
if (repo != null) {
action = DeepLinkServiceAction.RepoMatched;
break;
}
Expand Down
7 changes: 6 additions & 1 deletion src/views/viewCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ensurePullRequestRefs,
getComparisonRefsForPullRequest,
getOpenedPullRequestRepo,
getOrOpenPullRequestRepository,
getRepositoryIdentityForPullRequest,
} from '../git/models/pullRequest';
import { createReference, shortenRevision } from '../git/models/reference';
Expand Down Expand Up @@ -807,7 +808,11 @@ export class ViewCommands {
repoIdentity.remote.url,
DeepLinkActionType.SwitchToPullRequestWorktree,
);
return this.container.deepLinks.processDeepLinkUri(deepLink, false);

const prRepo = await getOrOpenPullRequestRepository(this.container, pr, {
skipVirtual: true,
});
return this.container.deepLinks.processDeepLinkUri(deepLink, false, prRepo);
}
}

Expand Down
Loading