Skip to content

Commit

Permalink
fix: Fetching more than 200 Azure DevOps issues (#10073)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dschoordsch authored Aug 5, 2024
1 parent d6777ce commit 5829a11
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions packages/server/utils/AzureDevOpsServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorkItemBatchResponse>(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<WorkItemBatchResponse>(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}
}
Expand Down

0 comments on commit 5829a11

Please sign in to comment.