@tiberriver256/mcp-server-azure-devops
Version:
Azure DevOps reference server for the Model Context Protocol (MCP)
90 lines • 3.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listPullRequests = listPullRequests;
const errors_1 = require("../../../shared/errors");
const GitInterfaces_1 = require("azure-devops-node-api/interfaces/GitInterfaces");
/**
* List pull requests for a repository
*
* @param connection The Azure DevOps WebApi connection
* @param projectId The ID or name of the project
* @param repositoryId The ID or name of the repository
* @param options Options for filtering pull requests
* @returns Object containing pull requests array and pagination metadata
*/
async function listPullRequests(connection, projectId, repositoryId, options) {
try {
const gitApi = await connection.getGitApi();
if (options.pullRequestId !== undefined) {
const pullRequest = await gitApi.getPullRequest(repositoryId, options.pullRequestId, projectId);
const value = pullRequest ? [pullRequest] : [];
return {
count: value.length,
value,
hasMoreResults: false,
warning: undefined,
};
}
// Create search criteria
const searchCriteria = {};
// Add filters if provided
if (options.status) {
// Map our status enum to Azure DevOps PullRequestStatus
switch (options.status) {
case 'active':
searchCriteria.status = GitInterfaces_1.PullRequestStatus.Active;
break;
case 'abandoned':
searchCriteria.status = GitInterfaces_1.PullRequestStatus.Abandoned;
break;
case 'completed':
searchCriteria.status = GitInterfaces_1.PullRequestStatus.Completed;
break;
case 'all':
// Don't set status to get all
break;
}
}
if (options.creatorId) {
searchCriteria.creatorId = options.creatorId;
}
if (options.reviewerId) {
searchCriteria.reviewerId = options.reviewerId;
}
if (options.sourceRefName) {
searchCriteria.sourceRefName = options.sourceRefName;
}
if (options.targetRefName) {
searchCriteria.targetRefName = options.targetRefName;
}
// Set default values for pagination
const top = options.top ?? 10;
const skip = options.skip ?? 0;
// List pull requests with search criteria
const pullRequests = await gitApi.getPullRequests(repositoryId, searchCriteria, projectId, undefined, // maxCommentLength
skip, top);
const results = pullRequests || [];
const count = results.length;
// Determine if there are likely more results
// If we got exactly the number requested, there are probably more
const hasMoreResults = count === top;
// Add a warning message if results were truncated
let warning;
if (hasMoreResults) {
warning = `Results limited to ${top} items. Use 'skip: ${skip + top}' to get the next page.`;
}
return {
count,
value: results,
hasMoreResults,
warning,
};
}
catch (error) {
if (error instanceof errors_1.AzureDevOpsError) {
throw error;
}
throw new Error(`Failed to list pull requests: ${error instanceof Error ? error.message : String(error)}`);
}
}
//# sourceMappingURL=feature.js.map