get-pull-request-data
Extract comprehensive GitHub Pull Request details, including files, diffs, comments, and reviews, for efficient analysis and review processes.
Instructions
Get detailed information about a GitHub Pull Request including files, diff, comments, and reviews
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | GitHub repository owner | |
| pullNumber | Yes | Pull request number | |
| repo | Yes | GitHub repository name | |
| token | No | GitHub personal access token (optional) |
Implementation Reference
- src/index.ts:26-56 (handler)The asynchronous handler function for the 'get-pull-request-data' tool. It initializes the Octokit client, fetches PR data using the helper function, and returns formatted JSON or error response.async ({ owner, repo, pullNumber, token }) => { try { // Initialize Octokit with token if provided const octokit = new Octokit({ auth: token, baseUrl: GITHUB_API_BASE, }); // Get all PR information const prData = await getAllPullRequestInfo(octokit, owner, repo, pullNumber); return { content: [ { type: "text", text: JSON.stringify(prData, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error: ${error instanceof Error ? error.message : "An unknown error occurred"}` } ], isError: true }; } }
- src/index.ts:20-25 (schema)Zod input schema defining the parameters for the 'get-pull-request-data' tool: owner, repo, pullNumber, and optional token.{ owner: z.string().describe("GitHub repository owner"), repo: z.string().describe("GitHub repository name"), pullNumber: z.number().describe("Pull request number"), token: z.string().optional().describe("GitHub personal access token (optional)"), },
- src/index.ts:17-57 (registration)Registration of the 'get-pull-request-data' tool using server.tool(), including name, description, input schema, and handler function.server.tool( "get-pull-request-data", "Get detailed information about a GitHub Pull Request including files, diff, comments, and reviews", { owner: z.string().describe("GitHub repository owner"), repo: z.string().describe("GitHub repository name"), pullNumber: z.number().describe("Pull request number"), token: z.string().optional().describe("GitHub personal access token (optional)"), }, async ({ owner, repo, pullNumber, token }) => { try { // Initialize Octokit with token if provided const octokit = new Octokit({ auth: token, baseUrl: GITHUB_API_BASE, }); // Get all PR information const prData = await getAllPullRequestInfo(octokit, owner, repo, pullNumber); return { content: [ { type: "text", text: JSON.stringify(prData, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error: ${error instanceof Error ? error.message : "An unknown error occurred"}` } ], isError: true }; } } );
- src/helpers/github.ts:109-134 (helper)Helper function that fetches comprehensive Pull Request data by calling sub-helpers for details, diff, comments, and reviews in parallel.export async function getAllPullRequestInfo( octokit: Octokit, owner: string, repo: string, pullNumber: number ): Promise<{ details: PullRequestDetails; diff: string; comments: any[]; }> { const [details, diff, comments,] = await Promise.all([ getPullRequestDetails(octokit, owner, repo, pullNumber), getPullRequestDiff(octokit, owner, repo, pullNumber), getPullRequestComments(octokit, owner, repo, pullNumber), getPullRequestReviews(octokit, owner, repo, pullNumber), ]); return { details, diff, comments, }; }