Skip to content

Commit f42ab17

Browse files
authored
feat: add support for fork source repository in pull request creation (Issue 254) (#356)
This pull request enhances the `create_pull_request` tool in `src/tools/repos.ts` to support creating pull requests from forked repositories. The changes include adding a new parameter for specifying the fork repository ID and updating the logic to handle this parameter when creating pull requests. ## GitHub issue number Fixes #254 ## **Associated Risks** none ## ✅ **PR Checklist** - [x] **I have read the [contribution guidelines](https://github.com/microsoft/azure-devops-mcp/blob/main/CONTRIBUTING.md)** - [x] **I have read the [code of conduct guidelines](https://github.com/microsoft/azure-devops-mcp/blob/main/CODE_OF_CONDUCT.md)** - [x] Title of the pull request is clear and informative. - [x] 👌 Code hygiene - [x] 🔭 Telemetry added, updated, or N/A - [x] 📄 Documentation added, updated, or N/A - [x] 🛡️ Automated tests added, or N/A ## 🧪 **How did you test it?** Tested manually - managed to create a PR from a forked repo into the original one.
1 parent d7432b9 commit f42ab17

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/tools/repos.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
66
import { WebApi } from "azure-devops-node-api";
77
import {
88
GitRef,
9+
GitForkRef,
910
PullRequestStatus,
1011
GitQueryCommitsCriteria,
1112
GitVersionType,
@@ -107,12 +108,21 @@ function configureRepoTools(server: McpServer, tokenProvider: () => Promise<Acce
107108
description: z.string().optional().describe("The description of the pull request. Optional."),
108109
isDraft: z.boolean().optional().default(false).describe("Indicates whether the pull request is a draft. Defaults to false."),
109110
workItems: z.string().optional().describe("Work item IDs to associate with the pull request, space-separated."),
111+
forkSourceRepositoryId: z.string().optional().describe("The ID of the fork repository that the pull request originates from. Optional, used when creating a pull request from a fork."),
110112
},
111-
async ({ repositoryId, sourceRefName, targetRefName, title, description, isDraft, workItems }) => {
113+
async ({ repositoryId, sourceRefName, targetRefName, title, description, isDraft, workItems, forkSourceRepositoryId }) => {
112114
const connection = await connectionProvider();
113115
const gitApi = await connection.getGitApi();
114116
const workItemRefs = workItems ? workItems.split(" ").map((id) => ({ id: id.trim() })) : [];
115117

118+
const forkSource: GitForkRef | undefined = forkSourceRepositoryId
119+
? {
120+
repository: {
121+
id: forkSourceRepositoryId,
122+
},
123+
}
124+
: undefined;
125+
116126
const pullRequest = await gitApi.createPullRequest(
117127
{
118128
sourceRefName,
@@ -121,6 +131,7 @@ function configureRepoTools(server: McpServer, tokenProvider: () => Promise<Acce
121131
description,
122132
isDraft,
123133
workItemRefs: workItemRefs,
134+
forkSource,
124135
},
125136
repositoryId
126137
);

0 commit comments

Comments
 (0)