-
Notifications
You must be signed in to change notification settings - Fork 209
Add pull request update tool #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nikolapeja6
merged 6 commits into
microsoft:main
from
beauzeaux:users/beauzeaux/update-pull-request-tool
Jul 31, 2025
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
adbe7af
Add comprehensive pull request update tool
beauzeaux 9150cc0
Fixed formatting issues
beauzeaux b9ee457
Merge remote-tracking branch 'origin/main' into users/beauzeaux/updat…
beauzeaux c7bfdbe
Merged PR status tool into general PR update tool
beauzeaux 2b52865
Updated description veribage to match work item update
beauzeaux 92ee039
Capitalization.
beauzeaux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||
import { AccessToken } from "@azure/identity"; | ||
import { WebApi } from "azure-devops-node-api"; | ||
import { configureRepoTools, REPO_TOOLS } from "../../../src/tools/repos"; | ||
|
||
// Mock the auth module | ||
jest.mock("../../../src/tools/auth", () => ({ | ||
getCurrentUserDetails: jest.fn(), | ||
})); | ||
|
||
describe("repos tools", () => { | ||
let server: McpServer; | ||
let tokenProvider: jest.MockedFunction<() => Promise<AccessToken>>; | ||
let connectionProvider: jest.MockedFunction<() => Promise<WebApi>>; | ||
let mockGitApi: { | ||
updatePullRequest: jest.MockedFunction<(...args: unknown[]) => Promise<unknown>>; | ||
}; | ||
|
||
beforeEach(() => { | ||
server = { | ||
tool: jest.fn(), | ||
} as unknown as McpServer; | ||
|
||
tokenProvider = jest.fn(); | ||
mockGitApi = { | ||
updatePullRequest: jest.fn(), | ||
}; | ||
|
||
connectionProvider = jest.fn().mockResolvedValue({ | ||
getGitApi: jest.fn().mockResolvedValue(mockGitApi), | ||
}); | ||
}); | ||
|
||
describe("repo_update_pull_request", () => { | ||
it("should update pull request with all provided fields", async () => { | ||
configureRepoTools(server, tokenProvider, connectionProvider); | ||
|
||
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === REPO_TOOLS.update_pull_request); | ||
|
||
if (!call) throw new Error("repo_update_pull_request tool not registered"); | ||
const [, , , handler] = call; | ||
|
||
const mockUpdatedPR = { | ||
pullRequestId: 123, | ||
title: "Updated Title", | ||
description: "Updated Description", | ||
isDraft: true, | ||
}; | ||
mockGitApi.updatePullRequest.mockResolvedValue(mockUpdatedPR); | ||
|
||
const params = { | ||
repositoryId: "repo123", | ||
pullRequestId: 123, | ||
title: "Updated Title", | ||
description: "Updated Description", | ||
isDraft: true, | ||
targetRefName: "refs/heads/main", | ||
}; | ||
|
||
const result = await handler(params); | ||
|
||
expect(mockGitApi.updatePullRequest).toHaveBeenCalledWith( | ||
{ | ||
title: "Updated Title", | ||
description: "Updated Description", | ||
isDraft: true, | ||
targetRefName: "refs/heads/main", | ||
}, | ||
"repo123", | ||
123 | ||
); | ||
|
||
expect(result.content[0].text).toBe(JSON.stringify(mockUpdatedPR, null, 2)); | ||
}); | ||
|
||
it("should update pull request with only title", async () => { | ||
configureRepoTools(server, tokenProvider, connectionProvider); | ||
|
||
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === REPO_TOOLS.update_pull_request); | ||
|
||
if (!call) throw new Error("repo_update_pull_request tool not registered"); | ||
const [, , , handler] = call; | ||
|
||
const mockUpdatedPR = { pullRequestId: 123, title: "New Title" }; | ||
mockGitApi.updatePullRequest.mockResolvedValue(mockUpdatedPR); | ||
|
||
const params = { | ||
repositoryId: "repo123", | ||
pullRequestId: 123, | ||
title: "New Title", | ||
}; | ||
|
||
const result = await handler(params); | ||
|
||
expect(mockGitApi.updatePullRequest).toHaveBeenCalledWith( | ||
{ | ||
title: "New Title", | ||
}, | ||
"repo123", | ||
123 | ||
); | ||
|
||
expect(result.content[0].text).toBe(JSON.stringify(mockUpdatedPR, null, 2)); | ||
}); | ||
|
||
it("should return error when no fields provided", async () => { | ||
configureRepoTools(server, tokenProvider, connectionProvider); | ||
|
||
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === REPO_TOOLS.update_pull_request); | ||
|
||
if (!call) throw new Error("repo_update_pull_request tool not registered"); | ||
const [, , , handler] = call; | ||
|
||
const params = { | ||
repositoryId: "repo123", | ||
pullRequestId: 123, | ||
}; | ||
|
||
const result = await handler(params); | ||
|
||
expect(mockGitApi.updatePullRequest).not.toHaveBeenCalled(); | ||
expect(result.isError).toBe(true); | ||
expect(result.content[0].text).toContain("At least one field"); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add an optional parameter for
status
in this tool, and then remove theupdate_pull_request_status
tool - they use the same node API, and it's better for the LLM to keep the number of tools down.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. The description of the tool was a result of me trying to hint the model not to attempt to use this for
status
. I've removedupdate_pull_request_status
and made the description align with the one used forupdate_work_item
.