Skip to content

Commit

Permalink
Enhances PR search with multiple integrations instead of only GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Nov 24, 2024
1 parent c91ee77 commit 16a244e
Showing 1 changed file with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions src/plus/launchpad/launchpadProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getOrOpenPullRequestRepository,
getRepositoryIdentityForPullRequest,
} from '../../git/models/pullRequest';
import type { PullRequestURLIdentity } from '../../git/models/pullRequest.utils';
import { getPullRequestIdentityValuesFromSearch } from '../../git/models/pullRequest.utils';
import type { GitRemote } from '../../git/models/remote';
import type { Repository } from '../../git/models/repository';
Expand All @@ -40,7 +41,7 @@ import type { UriTypes } from '../../uris/deepLinks/deepLink';
import { DeepLinkActionType, DeepLinkType } from '../../uris/deepLinks/deepLink';
import { showInspectView } from '../../webviews/commitDetails/actions';
import type { ShowWipArgs } from '../../webviews/commitDetails/protocol';
import type { IntegrationResult } from '../integrations/integration';
import type { HostingIntegration, IntegrationResult } from '../integrations/integration';
import type { ConnectionStateChangeEvent } from '../integrations/integrationService';
import type { GitHubRepositoryDescriptor } from '../integrations/providers/github';
import type { EnrichablePullRequest, ProviderActionablePullRequest } from '../integrations/providers/models';
Expand Down Expand Up @@ -326,12 +327,49 @@ export class LaunchpadProvider implements Disposable {
// The current idea is that we should iterate the connected integrations and apply their parsing.
// Probably we even want to build a map like this: { integrationId: identity }
// Then we iterate connected integrations and search in each of them with the corresponding identity.
const { ownerAndRepo, prNumber } = getPullRequestIdentityValuesFromSearch(search);
let result: TimedResult<SearchedPullRequest[] | undefined> | undefined;
const prUrlIdentity = getPullRequestIdentityValuesFromSearch(search);
const result: { readonly value: SearchedPullRequest[]; duration: number } = {
value: [],
duration: 0,
};

const connectedIntegrations = await this.getConnectedIntegrations();

await Promise.allSettled(
[...connectedIntegrations.keys()]
.filter(
(id: IntegrationId): id is SupportedLaunchpadIntegrationIds =>
(connectedIntegrations.get(id) && isSupportedLaunchpadIntegrationId(id)) ?? false,
)
.map(async (id: HostingIntegrationId) => {
const integration = await this.container.integrations.get(id);
const searchResult = await this.searchIntegrationPRs(
search,
prUrlIdentity,
integration,
cancellation,
);
const prs = searchResult?.value;
if (prs) {
result.value?.push(...prs);
result.duration = Math.max(result.duration, searchResult.duration);
}
}),
);
return {
prs: result,
suggestionCounts: undefined,
};
}

private async searchIntegrationPRs(
search: string,
{ ownerAndRepo, prNumber }: PullRequestURLIdentity,
integration: HostingIntegration,
cancellation: CancellationToken | undefined,
): Promise<undefined | TimedResult<SearchedPullRequest[] | undefined>> {
let result: TimedResult<SearchedPullRequest[] | undefined> | undefined;
if (prNumber != null && ownerAndRepo != null) {
// TODO: This needs to be generalized to work outside of GitHub
const integration = await this.container.integrations.get(HostingIntegrationId.GitHub);
const [owner, repo] = ownerAndRepo.split('/', 2);
const descriptor: GitHubRepositoryDescriptor = {
key: ownerAndRepo,
Expand All @@ -345,21 +383,20 @@ export class LaunchpadProvider implements Disposable {
);
if (pr?.value != null) {
result = { value: [{ pullRequest: pr.value, reasons: [] }], duration: pr.duration };
return { prs: result, suggestionCounts: undefined };
return result;
}
} else {
const integration = await this.container.integrations.get(HostingIntegrationId.GitHub);
const prs = await withDurationAndSlowEventOnTimeout(
integration?.searchPullRequests(search, undefined, cancellation),
integration?.searchPullRequests(search, undefined, cancellation), //
'searchPullRequests',
this.container,
);
if (prs != null) {
result = { value: prs.value?.map(pr => ({ pullRequest: pr, reasons: [] })), duration: prs.duration };
return { prs: result, suggestionCounts: undefined };
return result;
}
}
return { prs: undefined, suggestionCounts: undefined };
return undefined;
}

private _enrichedItems: CachedLaunchpadPromise<TimedResult<EnrichedItem[]>> | undefined;
Expand Down

0 comments on commit 16a244e

Please sign in to comment.