update_pull_request_branch
Update a pull request branch to include the latest commits from its base branch, keeping the PR current.
Instructions
Update the branch of a pull request with the latest changes from the base branch
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Repository owner | |
| repo | Yes | Repository name | |
| pullNumber | Yes | Pull request number | |
| expectedHeadSha | No | The expected SHA of the pull request's HEAD ref |
Implementation Reference
- src/tools/pullrequests.ts:488-510 (handler)The async handler function that executes the 'update_pull_request_branch' tool logic. It calls octokit.rest.pulls.updateBranch with owner, repo, pull_number, and optional expected_head_sha, then returns a success message or error.
async ({ owner, repo, pullNumber, expectedHeadSha }) => { try { const response = await octokit.rest.pulls.updateBranch({ owner, repo, pull_number: pullNumber, ...(expectedHeadSha ? { expected_head_sha: expectedHeadSha } : {}), }) return { content: [ { type: "text", text: `Branch updated successfully.\n\nMessage: ${response.data.message}\nURL: ${response.data.url}`, }, ], } } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.message}` }], } } }, - src/tools/pullrequests.ts:479-487 (schema)Zod schema definitions for the 'update_pull_request_branch' tool's input parameters: owner (string), repo (string), pullNumber (number), and optional expectedHeadSha (string).
{ owner: z.string().describe("Repository owner"), repo: z.string().describe("Repository name"), pullNumber: z.number().describe("Pull request number"), expectedHeadSha: z .string() .optional() .describe("The expected SHA of the pull request's HEAD ref"), }, - src/tools/pullrequests.ts:476-511 (registration)Registration of the tool via server.tool('update_pull_request_branch', ...) within registerPullRequestTools function.
server.tool( "update_pull_request_branch", "Update the branch of a pull request with the latest changes from the base branch", { owner: z.string().describe("Repository owner"), repo: z.string().describe("Repository name"), pullNumber: z.number().describe("Pull request number"), expectedHeadSha: z .string() .optional() .describe("The expected SHA of the pull request's HEAD ref"), }, async ({ owner, repo, pullNumber, expectedHeadSha }) => { try { const response = await octokit.rest.pulls.updateBranch({ owner, repo, pull_number: pullNumber, ...(expectedHeadSha ? { expected_head_sha: expectedHeadSha } : {}), }) return { content: [ { type: "text", text: `Branch updated successfully.\n\nMessage: ${response.data.message}\nURL: ${response.data.url}`, }, ], } } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.message}` }], } } }, ) - src/index.ts:18-18 (registration)Top-level registration: registerPullRequestTools(server, octokit) is called from registerAllToolsAndResources to register all pull request tools including 'update_pull_request_branch'.
registerPullRequestTools(server, octokit)