Skip to main content
Glama

get_pull_request_changes

Retrieve detailed changes from Azure DevOps pull requests including modified files, unified diffs, branch information, and policy evaluation status for code review and integration workflows.

Instructions

Get the files changed in a pull request, their unified diffs, source/target branch names, and the status of policy evaluations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdNoThe ID or name of the project (Default: MyProject)
organizationIdNoThe ID or name of the organization (Default: mycompany)
repositoryIdYesThe ID or name of the repository
pullRequestIdYesThe ID of the pull request

Implementation Reference

  • The main handler function that fetches the latest pull request iteration changes, policy evaluations, source/target refs, and generates unified diff patches for changed files using Azure DevOps APIs.
    export async function getPullRequestChanges( connection: WebApi, options: PullRequestChangesOptions, ): Promise<PullRequestChangesResponse> { try { const gitApi = await connection.getGitApi(); const [pullRequest, iterations] = await Promise.all([ gitApi.getPullRequest( options.repositoryId, options.pullRequestId, options.projectId, ), gitApi.getPullRequestIterations( options.repositoryId, options.pullRequestId, options.projectId, ), ]); if (!iterations || iterations.length === 0) { throw new AzureDevOpsError('No iterations found for pull request'); } const latest = iterations[iterations.length - 1]; const changes = await gitApi.getPullRequestIterationChanges( options.repositoryId, options.pullRequestId, latest.id!, options.projectId, ); const policyApi = await connection.getPolicyApi(); const artifactId = `vstfs:///CodeReview/CodeReviewId/${options.projectId}/${options.pullRequestId}`; const evaluations = await policyApi.getPolicyEvaluations( options.projectId, artifactId, ); const changeEntries = changes.changeEntries ?? []; const getBlobText = async (objId?: string): Promise<string> => { if (!objId) return ''; const stream = await gitApi.getBlobContent( options.repositoryId, objId, options.projectId, ); const chunks: Uint8Array[] = []; return await new Promise<string>((resolve, reject) => { stream.on('data', (chunk) => chunks.push(Buffer.from(chunk))); stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))); stream.on('error', reject); }); }; const files = await Promise.all( changeEntries.map(async (entry: GitChange) => { const path = entry.item?.path || entry.originalPath || ''; const [oldContent, newContent] = await Promise.all([ getBlobText(entry.item?.originalObjectId), getBlobText(entry.item?.objectId), ]); const patch = createTwoFilesPatch( entry.originalPath || path, path, oldContent, newContent, ); return { path, patch }; }), ); return { changes, evaluations, files, sourceRefName: pullRequest?.sourceRefName, targetRefName: pullRequest?.targetRefName, }; } catch (error) { if (error instanceof AzureDevOpsError) { throw error; } throw new Error( `Failed to get pull request changes: ${error instanceof Error ? error.message : String(error)}`, ); } }
  • Input schema validation using Zod for the get_pull_request_changes tool parameters.
    export const GetPullRequestChangesSchema = z.object({ projectId: z .string() .optional() .describe(`The ID or name of the project (Default: ${defaultProject})`), organizationId: z .string() .optional() .describe(`The ID or name of the organization (Default: ${defaultOrg})`), repositoryId: z.string().describe('The ID or name of the repository'), pullRequestId: z.number().describe('The ID of the pull request'), });
  • Response schema defining the structure of data returned by the get_pull_request_changes tool.
    export const GetPullRequestChangesResponseSchema = z.object({ changes: z.any(), evaluations: z.array(z.any()), files: z.array(PullRequestFileChangeSchema), sourceRefName: z.string().optional(), targetRefName: z.string().optional(), });
  • Tool registration definition including name, description, and JSON schema for inputs.
    { name: 'get_pull_request_changes', description: 'Get the files changed in a pull request, their unified diffs, source/target branch names, and the status of policy evaluations', inputSchema: zodToJsonSchema(GetPullRequestChangesSchema), },
  • Request dispatcher case that parses inputs with schema and invokes the core getPullRequestChanges handler.
    case 'get_pull_request_changes': { const params = GetPullRequestChangesSchema.parse( request.params.arguments, ); const result = await getPullRequestChanges(connection, { projectId: params.projectId ?? defaultProject, repositoryId: params.repositoryId, pullRequestId: params.pullRequestId, }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Tiberriver256/mcp-server-azure-devops'

If you have feedback or need assistance with the MCP directory API, please join our Discord server