From 5829a1149a751deddc2b9346a350c92c7e079b24 Mon Sep 17 00:00:00 2001 From: Georg Bremer Date: Mon, 5 Aug 2024 11:08:44 +0200 Subject: [PATCH] fix: Fetching more than 200 Azure DevOps issues (#10073) --- .../server/utils/AzureDevOpsServerManager.ts | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/server/utils/AzureDevOpsServerManager.ts b/packages/server/utils/AzureDevOpsServerManager.ts index 419b19df360..16950351455 100644 --- a/packages/server/utils/AzureDevOpsServerManager.ts +++ b/packages/server/utils/AzureDevOpsServerManager.ts @@ -425,21 +425,23 @@ class AzureDevOpsServerManager implements TaskIntegrationManager { const workItems = [] as WorkItem[] let firstError: Error | undefined const uri = `https://${instanceId}/_apis/wit/workitemsbatch?api-version=7.1-preview.1` - const payload = !!fields - ? {ids: workItemIds, fields: fields} - : {ids: workItemIds, $expand: 'Links'} - const res = await this.post(uri, payload) - if (res instanceof Error) { - if (!firstError) { - firstError = res - } - } else { - const mappedWorkItems = (res.value as WorkItem[]).map((workItem) => { - return { - ...workItem + // we can fetch at most 200 items at once VS403474 + for (let i = 0; i < workItemIds.length; i += 200) { + const ids = workItemIds.slice(i, i + 200) + const payload = !!fields ? {ids, fields: fields} : {ids, $expand: 'Links'} + const res = await this.post(uri, payload) + if (res instanceof Error) { + if (!firstError) { + firstError = res } - }) - workItems.push(...mappedWorkItems) + } else { + const mappedWorkItems = (res.value as WorkItem[]).map((workItem) => { + return { + ...workItem + } + }) + workItems.push(...mappedWorkItems) + } } return {error: firstError, workItems: workItems} }