UNPKG

@tiberriver256/mcp-server-azure-devops

Version:

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

76 lines 3.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPipelineRun = getPipelineRun; const PipelinesInterfaces_1 = require("azure-devops-node-api/interfaces/PipelinesInterfaces"); const errors_1 = require("../../../shared/errors"); const environment_1 = require("../../../utils/environment"); const artifacts_1 = require("../artifacts"); const helpers_1 = require("../helpers"); const API_VERSION = '7.1'; async function getPipelineRun(connection, options) { try { const pipelinesApi = await connection.getPipelinesApi(); const projectId = options.projectId ?? environment_1.defaultProject; const runId = options.runId; const resolvedPipelineId = await (0, helpers_1.resolvePipelineId)(connection, projectId, runId, options.pipelineId); const baseUrl = connection.serverUrl.replace(/\/+$/, ''); const encodedProject = encodeURIComponent(projectId); const requestOptions = pipelinesApi.createRequestOptions('application/json', API_VERSION); const buildRunUrl = (pipelineId) => { const route = typeof pipelineId === 'number' ? `${encodedProject}/_apis/pipelines/${pipelineId}/runs/${runId}` : `${encodedProject}/_apis/pipelines/runs/${runId}`; const url = new URL(`${route}`, `${baseUrl}/`); url.searchParams.set('api-version', API_VERSION); return url; }; const urlsToTry = []; if (typeof resolvedPipelineId === 'number') { urlsToTry.push(buildRunUrl(resolvedPipelineId)); } urlsToTry.push(buildRunUrl()); let response = null; for (const url of urlsToTry) { const attempt = await pipelinesApi.rest.get(url.toString(), requestOptions); if (attempt.statusCode !== 404 && attempt.result) { response = attempt; break; } } if (!response || !response.result) { throw new errors_1.AzureDevOpsResourceNotFoundError(`Pipeline run ${runId} not found in project ${projectId}`); } const run = pipelinesApi.formatResponse(response.result, PipelinesInterfaces_1.TypeInfo.Run, false); if (!run) { throw new errors_1.AzureDevOpsResourceNotFoundError(`Pipeline run ${runId} not found in project ${projectId}`); } const artifacts = await (0, artifacts_1.fetchRunArtifacts)(connection, projectId, runId, resolvedPipelineId); if (typeof options.pipelineId === 'number') { const runPipelineId = (0, helpers_1.coercePipelineId)(run.pipeline?.id); if (runPipelineId !== options.pipelineId) { throw new errors_1.AzureDevOpsResourceNotFoundError(`Run ${runId} does not belong to pipeline ${options.pipelineId}`); } } return artifacts.length > 0 ? { ...run, artifacts } : run; } catch (error) { if (error instanceof errors_1.AzureDevOpsError) { throw error; } if (error instanceof Error) { const message = error.message.toLowerCase(); if (message.includes('authentication') || message.includes('unauthorized') || message.includes('401')) { throw new errors_1.AzureDevOpsAuthenticationError(`Failed to authenticate: ${error.message}`); } if (message.includes('not found') || message.includes('does not exist') || message.includes('404')) { throw new errors_1.AzureDevOpsResourceNotFoundError(`Pipeline run or project not found: ${error.message}`); } } throw new errors_1.AzureDevOpsError(`Failed to get pipeline run: ${error instanceof Error ? error.message : String(error)}`); } } //# sourceMappingURL=feature.js.map