repo_create_pull_request
Create a pull request in Azure DevOps by specifying source and target branches, title, and optional details. Connects via PAT authentication to streamline repository collaboration.
Instructions
Create a new pull request.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | The description of the pull request. Optional. | |
| forkSourceRepositoryId | No | The ID of the fork repository that the pull request originates from. Optional, used when creating a pull request from a fork. | |
| isDraft | No | Indicates whether the pull request is a draft. Defaults to false. | |
| repositoryId | Yes | The ID of the repository where the pull request will be created. | |
| sourceRefName | Yes | The source branch name for the pull request, e.g., 'refs/heads/feature-branch'. | |
| targetRefName | Yes | The target branch name for the pull request, e.g., 'refs/heads/main'. | |
| title | Yes | The title of the pull request. | |
| workItems | No | Work item IDs to associate with the pull request, space-separated. |
Implementation Reference
- src/tools/repos.ts:114-143 (handler)The handler function that creates the pull request. It uses the Azure DevOps Git API to call createPullRequest with the provided parameters, handles work items and fork source, and returns the created pull request as JSON.async ({ repositoryId, sourceRefName, targetRefName, title, description, isDraft, workItems, forkSourceRepositoryId }) => { const connection = await connectionProvider(); const gitApi = await connection.getGitApi(); const workItemRefs = workItems ? workItems.split(" ").map((id) => ({ id: id.trim() })) : []; const forkSource: GitForkRef | undefined = forkSourceRepositoryId ? { repository: { id: forkSourceRepositoryId, }, } : undefined; const pullRequest = await gitApi.createPullRequest( { sourceRefName, targetRefName, title, description, isDraft, workItemRefs: workItemRefs, forkSource, }, repositoryId ); return { content: [{ type: "text", text: JSON.stringify(pullRequest, null, 2) }], }; }
- src/tools/repos.ts:104-113 (schema)Zod input schema defining the parameters for creating a pull request, including repository ID, source and target refs, title, optional description, draft status, work items, and fork source.{ repositoryId: z.string().describe("The ID of the repository where the pull request will be created."), sourceRefName: z.string().describe("The source branch name for the pull request, e.g., 'refs/heads/feature-branch'."), targetRefName: z.string().describe("The target branch name for the pull request, e.g., 'refs/heads/main'."), title: z.string().describe("The title of the pull request."), description: z.string().optional().describe("The description of the pull request. Optional."), isDraft: z.boolean().optional().default(false).describe("Indicates whether the pull request is a draft. Defaults to false."), workItems: z.string().optional().describe("Work item IDs to associate with the pull request, space-separated."), 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."), },
- src/tools/repos.ts:101-144 (registration)The server.tool registration for 'repo_create_pull_request', referencing the tool name from REPO_TOOLS, providing description, input schema, and inline handler function.server.tool( REPO_TOOLS.create_pull_request, "Create a new pull request.", { repositoryId: z.string().describe("The ID of the repository where the pull request will be created."), sourceRefName: z.string().describe("The source branch name for the pull request, e.g., 'refs/heads/feature-branch'."), targetRefName: z.string().describe("The target branch name for the pull request, e.g., 'refs/heads/main'."), title: z.string().describe("The title of the pull request."), description: z.string().optional().describe("The description of the pull request. Optional."), isDraft: z.boolean().optional().default(false).describe("Indicates whether the pull request is a draft. Defaults to false."), workItems: z.string().optional().describe("Work item IDs to associate with the pull request, space-separated."), 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."), }, async ({ repositoryId, sourceRefName, targetRefName, title, description, isDraft, workItems, forkSourceRepositoryId }) => { const connection = await connectionProvider(); const gitApi = await connection.getGitApi(); const workItemRefs = workItems ? workItems.split(" ").map((id) => ({ id: id.trim() })) : []; const forkSource: GitForkRef | undefined = forkSourceRepositoryId ? { repository: { id: forkSourceRepositoryId, }, } : undefined; const pullRequest = await gitApi.createPullRequest( { sourceRefName, targetRefName, title, description, isDraft, workItemRefs: workItemRefs, forkSource, }, repositoryId ); return { content: [{ type: "text", text: JSON.stringify(pullRequest, null, 2) }], }; } );
- src/tools/repos.ts:36-36 (registration)The REPO_TOOLS constant mapping the tool name 'repo_create_pull_request' for use in registration.create_pull_request: "repo_create_pull_request",