UNPKG

@tiberriver256/mcp-server-azure-devops

Version:

Azure DevOps reference server for the Model Context Protocol (MCP)

78 lines 3.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getWorkItemComments = getWorkItemComments; const WorkItemTrackingInterfaces_1 = require("azure-devops-node-api/interfaces/WorkItemTrackingInterfaces"); const errors_1 = require("../../../shared/errors"); /** * Maps string-based expansion options to the CommentExpandOptions enum */ const expandMap = { none: WorkItemTrackingInterfaces_1.CommentExpandOptions.None, reactions: WorkItemTrackingInterfaces_1.CommentExpandOptions.Reactions, renderedtext: WorkItemTrackingInterfaces_1.CommentExpandOptions.RenderedText, all: WorkItemTrackingInterfaces_1.CommentExpandOptions.All, }; /** * Maps string-based sort order options to the CommentSortOrder enum */ const orderMap = { asc: WorkItemTrackingInterfaces_1.CommentSortOrder.Asc, desc: WorkItemTrackingInterfaces_1.CommentSortOrder.Desc, }; function isNotFoundError(error) { if (!error || typeof error !== 'object') { return false; } const errorObj = error; return errorObj.statusCode === 404 || errorObj.response?.status === 404; } /** * Get comments for a work item * * @param connection The Azure DevOps WebApi connection * @param options Options for getting work item comments * @returns The list of work item comments */ async function getWorkItemComments(connection, options) { try { const witApi = await connection.getWorkItemTrackingApi(); const { workItemId, projectId, top, continuationToken, includeDeleted, expand = 'all', order = 'asc', } = options; let resolvedProjectId = projectId; if (!resolvedProjectId) { try { const workItem = await witApi.getWorkItem(workItemId, [ 'System.TeamProject', ]); if (!workItem || !workItem.fields || !workItem.fields['System.TeamProject']) { throw new errors_1.AzureDevOpsResourceNotFoundError(`Work item '${workItemId}' not found`); } resolvedProjectId = workItem.fields['System.TeamProject']; } catch (error) { if (error instanceof errors_1.AzureDevOpsError) { throw error; } if (isNotFoundError(error)) { throw new errors_1.AzureDevOpsResourceNotFoundError(`Work item '${workItemId}' not found`); } throw error; } } const expandVal = expandMap[expand.toLowerCase()] ?? WorkItemTrackingInterfaces_1.CommentExpandOptions.All; const orderVal = orderMap[order.toLowerCase()] ?? WorkItemTrackingInterfaces_1.CommentSortOrder.Asc; const commentList = await witApi.getComments(resolvedProjectId, workItemId, top, continuationToken, includeDeleted, expandVal, orderVal); if (!commentList) { throw new errors_1.AzureDevOpsResourceNotFoundError(`Comments for work item '${workItemId}' not found`); } return commentList; } catch (error) { if (error instanceof errors_1.AzureDevOpsError) { throw error; } throw new errors_1.AzureDevOpsError(`Failed to get work item comments: ${error instanceof Error ? error.message : String(error)}`); } } //# sourceMappingURL=feature.js.map