Skip to content

Commit 39223b8

Browse files
committed
Implements getting issues for Azure DevOps Server
(#4478, #4516)
1 parent 1117ae3 commit 39223b8

File tree

4 files changed

+45
-51
lines changed

4 files changed

+45
-51
lines changed

src/plus/integrations/providers/azureDevOps.ts

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { Issue, IssueShape } from '../../../git/models/issue';
88
import type { IssueOrPullRequest, IssueOrPullRequestType } from '../../../git/models/issueOrPullRequest';
99
import type { PullRequest, PullRequestMergeMethod, PullRequestState } from '../../../git/models/pullRequest';
1010
import type { RepositoryMetadata } from '../../../git/models/repositoryMetadata';
11-
import { getSettledValue } from '../../../system/promise';
11+
import { flatSettled } from '../../../system/promise';
1212
import { base64 } from '../../../system/string';
1313
import type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider';
1414
import type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService';
@@ -119,16 +119,13 @@ export abstract class AzureDevOpsIntegrationBase<
119119

120120
if (resourcesWithoutProjects.length > 0) {
121121
const api = await this.getProvidersApi();
122-
const azureProjects = (
123-
await Promise.allSettled(
124-
resourcesWithoutProjects.map(resource =>
125-
api.getAzureProjectsForResource(resource.name, this.id, this.getApiOptions(accessToken)),
126-
),
127-
)
128-
)
129-
.map(r => getSettledValue(r)?.values)
130-
.flat()
131-
.filter(p => p != null);
122+
const azureProjects = await flatSettled(
123+
resourcesWithoutProjects.map(
124+
async resource =>
125+
(await api.getAzureProjectsForResource(resource.name, this.id, this.getApiOptions(accessToken)))
126+
.values,
127+
),
128+
);
132129

133130
for (const resource of resourcesWithoutProjects) {
134131
const projects = azureProjects?.filter(p => p.namespace === resource.name);
@@ -412,32 +409,28 @@ export abstract class AzureDevOpsIntegrationBase<
412409
const projects = await this.getProviderProjectsForResources(session, orgs);
413410
if (projects == null || projects.length === 0) return undefined;
414411

415-
const assignedIssues = (
416-
await Promise.all(
417-
projects.map(async p => {
418-
const issuesResponse = (
419-
await api.getIssuesForAzureProject(this.id, p.resourceName, p.name, {
420-
...this.getApiOptions(session.accessToken),
421-
assigneeLogins: [user.username!],
422-
})
423-
).values;
424-
return issuesResponse.map(i => fromProviderIssue(i, this as any, { project: p }));
425-
}),
426-
)
427-
).flat();
428-
const authoredIssues = (
429-
await Promise.all(
430-
projects.map(async p => {
431-
const issuesResponse = (
432-
await api.getIssuesForAzureProject(this.id, p.resourceName, p.name, {
433-
...this.getApiOptions(session.accessToken),
434-
authorLogin: user.username!,
435-
})
436-
).values;
437-
return issuesResponse.map(i => fromProviderIssue(i, this as any, { project: p }));
438-
}),
439-
)
440-
).flat();
412+
const assignedIssues = await flatSettled(
413+
projects.map(async p => {
414+
const issuesResponse = (
415+
await api.getIssuesForAzureProject(this.id, p.resourceName, p.name, {
416+
...this.getApiOptions(session.accessToken),
417+
assigneeLogins: [user.username!],
418+
})
419+
).values;
420+
return issuesResponse.map(i => fromProviderIssue(i, this as any, { project: p }));
421+
}),
422+
);
423+
const authoredIssues = await flatSettled(
424+
projects.map(async p => {
425+
const issuesResponse = (
426+
await api.getIssuesForAzureProject(this.id, p.resourceName, p.name, {
427+
...this.getApiOptions(session.accessToken),
428+
authorLogin: user.username!,
429+
})
430+
).values;
431+
return issuesResponse.map(i => fromProviderIssue(i, this as any, { project: p }));
432+
}),
433+
);
441434
// TODO: Add mentioned issues
442435
const issuesById = new Map<string, IssueShape>();
443436

src/plus/integrations/providers/bitbucket.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { IssueOrPullRequest, IssueOrPullRequestType } from '../../../git/mo
88
import type { PullRequest, PullRequestMergeMethod, PullRequestState } from '../../../git/models/pullRequest';
99
import type { RepositoryMetadata } from '../../../git/models/repositoryMetadata';
1010
import { uniqueBy } from '../../../system/iterable';
11-
import { getSettledValue } from '../../../system/promise';
11+
import { flatSettled, nonnullSettled } from '../../../system/promise';
1212
import type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider';
1313
import type { ProviderAuthenticationSession } from '../authentication/models';
1414
import { GitHostIntegration } from '../models/gitHostIntegration';
@@ -351,15 +351,3 @@ const bitbucketCloudDomainRegex = /^bitbucket\.org$/i;
351351
export function isBitbucketCloudDomain(domain: string | undefined): boolean {
352352
return domain != null && bitbucketCloudDomainRegex.test(domain);
353353
}
354-
355-
type MaybePromiseArr<T> = (Promise<T | undefined> | T | undefined)[];
356-
357-
async function nonnullSettled<T>(arr: MaybePromiseArr<T>): Promise<T[]> {
358-
const all = await Promise.allSettled(arr);
359-
return all.map(r => getSettledValue(r)).filter(v => v != null);
360-
}
361-
362-
async function flatSettled<T>(arr: MaybePromiseArr<(T | undefined)[]>): Promise<T[]> {
363-
const all = await nonnullSettled(arr);
364-
return all.flat().filter(v => v != null);
365-
}

src/plus/integrations/providers/providersApi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ export class ProvidersApi {
10351035
providerId: GitCloudHostIntegrationId.AzureDevOps | GitSelfManagedHostIntegrationId.AzureDevOpsServer,
10361036
namespace: string,
10371037
project: string,
1038-
options?: GetIssuesOptions & { accessToken?: string; isPAT?: boolean },
1038+
options?: GetIssuesOptions & { accessToken?: string; isPAT?: boolean; baseUrl?: string },
10391039
): Promise<PagedResult<ProviderIssue>> {
10401040
const { provider, token } = await this.ensureProviderTokenAndFunction(
10411041
providerId,
@@ -1050,6 +1050,7 @@ export class ProvidersApi {
10501050
token,
10511051
options?.cursor,
10521052
options?.isPAT,
1053+
options?.baseUrl,
10531054
);
10541055
}
10551056

src/system/promise.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ export function getDeferredPromiseIfPending<T>(deferred: Deferred<T> | undefined
197197
return deferred?.pending ? deferred.promise : undefined;
198198
}
199199

200+
export type MaybePromiseArr<T> = (Promise<T | undefined> | T | undefined)[];
201+
202+
export async function nonnullSettled<T>(arr: MaybePromiseArr<T>): Promise<T[]> {
203+
const all = await Promise.allSettled(arr);
204+
return all.map(r => getSettledValue(r)).filter(v => v != null);
205+
}
206+
207+
export async function flatSettled<T>(arr: MaybePromiseArr<(T | undefined)[]>): Promise<T[]> {
208+
const all = await nonnullSettled(arr);
209+
return all.flat().filter(v => v != null);
210+
}
211+
200212
export function getSettledValue<T>(promise: PromiseSettledResult<T> | undefined): T | undefined;
201213
export function getSettledValue<T>(
202214
promise: PromiseSettledResult<T> | undefined,

0 commit comments

Comments
 (0)