-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathfeature.ts
49 lines (45 loc) · 1.34 KB
/
feature.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { WebApi } from 'azure-devops-node-api';
import { WorkItemExpand } from 'azure-devops-node-api/interfaces/WorkItemTrackingInterfaces';
import {
AzureDevOpsResourceNotFoundError,
AzureDevOpsError,
} from '../../../shared/errors';
import { WorkItem } from '../types';
/**
* Get a work item by ID
*
* @param connection The Azure DevOps WebApi connection
* @param workItemId The ID of the work item
* @param expand Optional expansion options (defaults to WorkItemExpand.All)
* @returns The work item details
* @throws {AzureDevOpsResourceNotFoundError} If the work item is not found
*/
export async function getWorkItem(
connection: WebApi,
workItemId: number,
expand: WorkItemExpand = WorkItemExpand.All,
): Promise<WorkItem> {
try {
const witApi = await connection.getWorkItemTrackingApi();
// Always use expand parameter for consistent behavior
const workItem = await witApi.getWorkItem(
workItemId,
undefined,
undefined,
expand,
);
if (!workItem) {
throw new AzureDevOpsResourceNotFoundError(
`Work item '${workItemId}' not found`,
);
}
return workItem;
} catch (error) {
if (error instanceof AzureDevOpsError) {
throw error;
}
throw new Error(
`Failed to get work item: ${error instanceof Error ? error.message : String(error)}`,
);
}
}