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
5 changes: 0 additions & 5 deletions src/git/models/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ export interface IssueRepository {
id?: string;
}

export interface SearchedIssue {
issue: IssueShape;
reasons: string[];
}

export type IssueRepositoryIdentityDescriptor = RequireSomeWithProps<
RequireSome<RepositoryIdentityDescriptor<string>, 'provider'>,
'provider',
Expand Down
5 changes: 0 additions & 5 deletions src/git/models/pullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,3 @@ export type PullRequestRepositoryIdentityDescriptor = RequireSomeWithProps<
'id' | 'domain' | 'repoDomain' | 'repoName'
> &
RequireSomeWithProps<RequireSome<RepositoryIdentityDescriptor<string>, 'remote'>, 'remote', 'domain'>;

export interface SearchedPullRequest {
pullRequest: PullRequest;
reasons: string[];
}
33 changes: 14 additions & 19 deletions src/plus/integrations/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@ import { AuthenticationError, CancellationError, RequestClientError } from '../.
import type { PagedResult } from '../../git/gitProvider';
import type { Account, UnidentifiedAuthor } from '../../git/models/author';
import type { DefaultBranch } from '../../git/models/defaultBranch';
import type { Issue, SearchedIssue } from '../../git/models/issue';
import type { Issue, IssueShape } from '../../git/models/issue';
import type { IssueOrPullRequest } from '../../git/models/issueOrPullRequest';
import type {
PullRequest,
PullRequestMergeMethod,
PullRequestState,
SearchedPullRequest,
} from '../../git/models/pullRequest';
import type { PullRequest, PullRequestMergeMethod, PullRequestState } from '../../git/models/pullRequest';
import type { RepositoryMetadata } from '../../git/models/repositoryMetadata';
import type { PullRequestUrlIdentity } from '../../git/utils/pullRequest.utils';
import { showIntegrationDisconnectedTooManyFailedRequestsWarningMessage } from '../../messages';
Expand Down Expand Up @@ -418,16 +413,16 @@ export abstract class IntegrationBase<
async searchMyIssues(
resource?: ResourceDescriptor,
cancellation?: CancellationToken,
): Promise<SearchedIssue[] | undefined>;
): Promise<IssueShape[] | undefined>;
async searchMyIssues(
resources?: ResourceDescriptor[],
cancellation?: CancellationToken,
): Promise<SearchedIssue[] | undefined>;
): Promise<IssueShape[] | undefined>;
@debug()
async searchMyIssues(
resources?: ResourceDescriptor | ResourceDescriptor[],
cancellation?: CancellationToken,
): Promise<SearchedIssue[] | undefined> {
): Promise<IssueShape[] | undefined> {
const scope = getLogScope();
const connected = this.maybeConnected ?? (await this.isConnected());
if (!connected) return undefined;
Expand All @@ -441,15 +436,15 @@ export abstract class IntegrationBase<
this.resetRequestExceptionCount();
return issues;
} catch (ex) {
return this.handleProviderException<SearchedIssue[] | undefined>(ex, scope, undefined);
return this.handleProviderException<IssueShape[] | undefined>(ex, scope, undefined);
}
}

protected abstract searchProviderMyIssues(
session: ProviderAuthenticationSession,
resources?: ResourceDescriptor[],
cancellation?: CancellationToken,
): Promise<SearchedIssue[] | undefined>;
): Promise<IssueShape[] | undefined>;

@debug()
async getIssueOrPullRequest(
Expand Down Expand Up @@ -660,7 +655,7 @@ export abstract class IssueIntegration<
async getIssuesForProject(
project: T,
options?: { user?: string; filters?: IssueFilter[] },
): Promise<SearchedIssue[] | undefined> {
): Promise<IssueShape[] | undefined> {
const connected = this.maybeConnected ?? (await this.isConnected());
if (!connected) return undefined;

Expand All @@ -669,15 +664,15 @@ export abstract class IssueIntegration<
this.resetRequestExceptionCount();
return issues;
} catch (ex) {
return this.handleProviderException<SearchedIssue[] | undefined>(ex, undefined, undefined);
return this.handleProviderException<IssueShape[] | undefined>(ex, undefined, undefined);
}
}

protected abstract getProviderIssuesForProject(
session: ProviderAuthenticationSession,
project: T,
options?: { user?: string; filters?: IssueFilter[] },
): Promise<SearchedIssue[] | undefined>;
): Promise<IssueShape[] | undefined>;
}

export abstract class HostingIntegration<
Expand Down Expand Up @@ -1293,18 +1288,18 @@ export abstract class HostingIntegration<
repo?: T,
cancellation?: CancellationToken,
silent?: boolean,
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>>;
): Promise<IntegrationResult<PullRequest[] | undefined>>;
async searchMyPullRequests(
repos?: T[],
cancellation?: CancellationToken,
silent?: boolean,
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>>;
): Promise<IntegrationResult<PullRequest[] | undefined>>;
@debug()
async searchMyPullRequests(
repos?: T | T[],
cancellation?: CancellationToken,
silent?: boolean,
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>> {
): Promise<IntegrationResult<PullRequest[] | undefined>> {
const scope = getLogScope();
const connected = this.maybeConnected ?? (await this.isConnected());
if (!connected) return undefined;
Expand All @@ -1329,7 +1324,7 @@ export abstract class HostingIntegration<
repos?: T[],
cancellation?: CancellationToken,
silent?: boolean,
): Promise<SearchedPullRequest[] | undefined>;
): Promise<PullRequest[] | undefined>;

async searchPullRequests(
searchQuery: string,
Expand Down
30 changes: 14 additions & 16 deletions src/plus/integrations/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type { Source } from '../../constants.telemetry';
import { sourceToContext } from '../../constants.telemetry';
import type { Container } from '../../container';
import type { Account } from '../../git/models/author';
import type { SearchedIssue } from '../../git/models/issue';
import type { SearchedPullRequest } from '../../git/models/pullRequest';
import type { IssueShape } from '../../git/models/issue';
import type { PullRequest } from '../../git/models/pullRequest';
import type { GitRemote } from '../../git/models/remote';
import type { RemoteProvider, RemoteProviderId } from '../../git/remotes/remoteProvider';
import { configuration } from '../../system/-webview/configuration';
Expand Down Expand Up @@ -726,7 +726,7 @@ export class IntegrationService implements Disposable {
| SupportedSelfHostedIntegrationIds
)[],
options?: { openRepositoriesOnly?: boolean; cancellation?: CancellationToken },
): Promise<SearchedIssue[] | undefined> {
): Promise<IssueShape[] | undefined> {
const integrations: Map<Integration, ResourceDescriptor[] | undefined> = new Map();
const hostingIntegrationIds = integrationIds?.filter(
id => id in HostingIntegrationId || id in SelfHostedIntegrationId,
Expand Down Expand Up @@ -796,8 +796,8 @@ export class IntegrationService implements Disposable {
private async getMyIssuesCore(
integrations: Map<Integration, ResourceDescriptor[] | undefined>,
cancellation?: CancellationToken,
): Promise<SearchedIssue[] | undefined> {
const promises: Promise<SearchedIssue[] | undefined>[] = [];
): Promise<IssueShape[] | undefined> {
const promises: Promise<IssueShape[] | undefined>[] = [];
for (const [integration, repos] of integrations) {
if (integration == null) continue;

Expand All @@ -808,12 +808,12 @@ export class IntegrationService implements Disposable {
return [...flatten(filterMap(results, r => (r.status === 'fulfilled' ? r.value : undefined)))];
}

async getMyIssuesForRemotes(remote: GitRemote): Promise<SearchedIssue[] | undefined>;
async getMyIssuesForRemotes(remotes: GitRemote[]): Promise<SearchedIssue[] | undefined>;
async getMyIssuesForRemotes(remote: GitRemote): Promise<IssueShape[] | undefined>;
async getMyIssuesForRemotes(remotes: GitRemote[]): Promise<IssueShape[] | undefined>;
@debug<IntegrationService['getMyIssuesForRemotes']>({
args: { 0: (r: GitRemote | GitRemote[]) => (Array.isArray(r) ? r.map(rp => rp.name) : r.name) },
})
async getMyIssuesForRemotes(remoteOrRemotes: GitRemote | GitRemote[]): Promise<SearchedIssue[] | undefined> {
async getMyIssuesForRemotes(remoteOrRemotes: GitRemote | GitRemote[]): Promise<IssueShape[] | undefined> {
if (!Array.isArray(remoteOrRemotes)) {
remoteOrRemotes = [remoteOrRemotes];
}
Expand Down Expand Up @@ -874,7 +874,7 @@ export class IntegrationService implements Disposable {
integrationIds?: (HostingIntegrationId | CloudSelfHostedIntegrationId)[],
cancellation?: CancellationToken,
silent?: boolean,
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>> {
): Promise<IntegrationResult<PullRequest[] | undefined>> {
const integrations: Map<HostingIntegration, ResourceDescriptor[] | undefined> = new Map();
for (const integrationId of integrationIds?.length ? integrationIds : Object.values(HostingIntegrationId)) {
let integration;
Expand All @@ -894,10 +894,10 @@ export class IntegrationService implements Disposable {
integrations: Map<HostingIntegration, ResourceDescriptor[] | undefined>,
cancellation?: CancellationToken,
silent?: boolean,
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>> {
): Promise<IntegrationResult<PullRequest[] | undefined>> {
const start = Date.now();

const promises: Promise<IntegrationResult<SearchedPullRequest[] | undefined>>[] = [];
const promises: Promise<IntegrationResult<PullRequest[] | undefined>>[] = [];
for (const [integration, repos] of integrations) {
if (integration == null) continue;

Expand Down Expand Up @@ -932,16 +932,14 @@ export class IntegrationService implements Disposable {
};
}

async getMyPullRequestsForRemotes(remote: GitRemote): Promise<IntegrationResult<SearchedPullRequest[] | undefined>>;
async getMyPullRequestsForRemotes(
remotes: GitRemote[],
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>>;
async getMyPullRequestsForRemotes(remote: GitRemote): Promise<IntegrationResult<PullRequest[] | undefined>>;
async getMyPullRequestsForRemotes(remotes: GitRemote[]): Promise<IntegrationResult<PullRequest[] | undefined>>;
@debug<IntegrationService['getMyPullRequestsForRemotes']>({
args: { 0: (r: GitRemote | GitRemote[]) => (Array.isArray(r) ? r.map(rp => rp.name) : r.name) },
})
async getMyPullRequestsForRemotes(
remoteOrRemotes: GitRemote | GitRemote[],
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>> {
): Promise<IntegrationResult<PullRequest[] | undefined>> {
if (!Array.isArray(remoteOrRemotes)) {
remoteOrRemotes = [remoteOrRemotes];
}
Expand Down
33 changes: 12 additions & 21 deletions src/plus/integrations/providers/azureDevOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ import { window } from 'vscode';
import { HostingIntegrationId } from '../../../constants.integrations';
import type { Account } from '../../../git/models/author';
import type { DefaultBranch } from '../../../git/models/defaultBranch';
import type { Issue, SearchedIssue } from '../../../git/models/issue';
import type { Issue, IssueShape } from '../../../git/models/issue';
import type { IssueOrPullRequest } from '../../../git/models/issueOrPullRequest';
import type {
PullRequest,
PullRequestMergeMethod,
PullRequestState,
SearchedPullRequest,
} from '../../../git/models/pullRequest';
import type { PullRequest, PullRequestMergeMethod, PullRequestState } from '../../../git/models/pullRequest';
import type { RepositoryMetadata } from '../../../git/models/repositoryMetadata';
import { getSettledValue } from '../../../system/promise';
import type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider';
Expand Down Expand Up @@ -316,7 +311,7 @@ export class AzureDevOpsIntegration extends HostingIntegration<
protected override async searchProviderMyPullRequests(
session: AuthenticationSession,
repos?: AzureRepositoryDescriptor[],
): Promise<SearchedPullRequest[] | undefined> {
): Promise<PullRequest[] | undefined> {
const api = await this.getProvidersApi();
if (repos != null) {
// TODO: implement repos version
Expand Down Expand Up @@ -351,17 +346,15 @@ export class AzureDevOpsIntegration extends HostingIntegration<
authorLogin: user.username,
})
)?.map(pr => this.fromAzureProviderPullRequest(pr, repoDescriptors, projects));
const prsById = new Map<string, SearchedPullRequest>();
const prsById = new Map<string, PullRequest>();
for (const pr of authoredPrs ?? []) {
prsById.set(pr.id, { pullRequest: pr, reasons: ['authored'] });
prsById.set(pr.id, pr);
}

for (const pr of assignedPrs ?? []) {
const existing = prsById.get(pr.id);
if (existing != null) {
existing.reasons.push('assigned');
} else {
prsById.set(pr.id, { pullRequest: pr, reasons: ['assigned'] });
if (existing == null) {
prsById.set(pr.id, pr);
}
}

Expand All @@ -371,7 +364,7 @@ export class AzureDevOpsIntegration extends HostingIntegration<
protected override async searchProviderMyIssues(
session: AuthenticationSession,
_repos?: AzureRepositoryDescriptor[],
): Promise<SearchedIssue[] | undefined> {
): Promise<IssueShape[] | undefined> {
const api = await this.getProvidersApi();

const user = await this.getProviderCurrentAccount(session);
Expand Down Expand Up @@ -410,18 +403,16 @@ export class AzureDevOpsIntegration extends HostingIntegration<
)
).flat();
// TODO: Add mentioned issues
const issuesById = new Map<string, SearchedIssue>();
const issuesById = new Map<string, IssueShape>();

for (const issue of authoredIssues ?? []) {
issuesById.set(issue.id, { issue: issue, reasons: ['authored'] });
issuesById.set(issue.id, issue);
}

for (const issue of assignedIssues ?? []) {
const existing = issuesById.get(issue.id);
if (existing != null) {
existing.reasons.push('assigned');
} else {
issuesById.set(issue.id, { issue: issue, reasons: ['assigned'] });
if (existing == null) {
issuesById.set(issue.id, issue);
}
}

Expand Down
13 changes: 4 additions & 9 deletions src/plus/integrations/providers/bitbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ import type { AuthenticationSession, CancellationToken } from 'vscode';
import { HostingIntegrationId } from '../../../constants.integrations';
import type { Account } from '../../../git/models/author';
import type { DefaultBranch } from '../../../git/models/defaultBranch';
import type { Issue, SearchedIssue } from '../../../git/models/issue';
import type { Issue, IssueShape } from '../../../git/models/issue';
import type { IssueOrPullRequest } from '../../../git/models/issueOrPullRequest';
import type {
PullRequest,
PullRequestMergeMethod,
PullRequestState,
SearchedPullRequest,
} from '../../../git/models/pullRequest';
import type { PullRequest, PullRequestMergeMethod, PullRequestState } from '../../../git/models/pullRequest';
import type { RepositoryMetadata } from '../../../git/models/repositoryMetadata';
import type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider';
import type { ResourceDescriptor } from '../integration';
Expand Down Expand Up @@ -126,14 +121,14 @@ export class BitbucketIntegration extends HostingIntegration<
protected override async searchProviderMyPullRequests(
_session: AuthenticationSession,
_repos?: BitbucketRepositoryDescriptor[],
): Promise<SearchedPullRequest[] | undefined> {
): Promise<PullRequest[] | undefined> {
return Promise.resolve(undefined);
}

protected override async searchProviderMyIssues(
_session: AuthenticationSession,
_repos?: BitbucketRepositoryDescriptor[],
): Promise<SearchedIssue[] | undefined> {
): Promise<IssueShape[] | undefined> {
return Promise.resolve(undefined);
}
}
Expand Down
13 changes: 4 additions & 9 deletions src/plus/integrations/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import type { Sources } from '../../../constants.telemetry';
import type { Container } from '../../../container';
import type { Account, UnidentifiedAuthor } from '../../../git/models/author';
import type { DefaultBranch } from '../../../git/models/defaultBranch';
import type { Issue, SearchedIssue } from '../../../git/models/issue';
import type { Issue, IssueShape } from '../../../git/models/issue';
import type { IssueOrPullRequest } from '../../../git/models/issueOrPullRequest';
import type {
PullRequest,
PullRequestMergeMethod,
PullRequestState,
SearchedPullRequest,
} from '../../../git/models/pullRequest';
import type { PullRequest, PullRequestMergeMethod, PullRequestState } from '../../../git/models/pullRequest';
import type { RepositoryMetadata } from '../../../git/models/repositoryMetadata';
import type { PullRequestUrlIdentity } from '../../../git/utils/pullRequest.utils';
import { log } from '../../../system/decorators/log';
Expand Down Expand Up @@ -190,7 +185,7 @@ abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends
repos?: GitHubRepositoryDescriptor[],
cancellation?: CancellationToken,
silent?: boolean,
): Promise<SearchedPullRequest[] | undefined> {
): Promise<PullRequest[] | undefined> {
return (await this.container.github)?.searchMyPullRequests(
this,
accessToken,
Expand All @@ -207,7 +202,7 @@ abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends
{ accessToken }: AuthenticationSession,
repos?: GitHubRepositoryDescriptor[],
cancellation?: CancellationToken,
): Promise<SearchedIssue[] | undefined> {
): Promise<IssueShape[] | undefined> {
return (await this.container.github)?.searchMyIssues(
this,
accessToken,
Expand Down
Loading