create_change_request
Create a new change request in Alibaba Cloud DevOps to manage code modifications by specifying source and target branches, reviewers, and associated work items.
Instructions
[Code Management] Create a new change request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| organizationId | Yes | Organization ID, can be found in the basic information page of the organization admin console | |
| repositoryId | Yes | Repository ID or a combination of organization ID and repository name, for example: 2835387 or organizationId%2Frepo-name (Note: slashes need to be URL encoded as %2F) | |
| title | Yes | Title, no more than 256 characters | |
| description | No | Description, no more than 10000 characters | |
| sourceBranch | Yes | Source branch name | |
| sourceProjectId | No | Source repository ID (if not provided, will try to get automatically) | |
| targetBranch | Yes | Target branch name | |
| targetProjectId | No | Target repository ID (if not provided, will try to get automatically) | |
| reviewerUserIds | No | Reviewer user ID list | |
| workItemIds | No | Associated work item ID list | |
| createFrom | No | Creation source. Possible values: WEB (created from web page), COMMAND_LINE (created from command line). Default is WEB | WEB |
| triggerAIReviewRun | No | Whether to trigger AI review, default is false |
Implementation Reference
- tool-handlers/code-management.ts:218-237 (handler)Tool handler switch case that validates input with CreateChangeRequestSchema and invokes the createChangeRequestFunc to perform the API call.case "create_change_request": { const args = types.CreateChangeRequestSchema.parse(request.params.arguments); const changeRequest = await changeRequests.createChangeRequestFunc( args.organizationId, args.repositoryId, args.title, args.sourceBranch, args.targetBranch, args.description ?? undefined, args.sourceProjectId, args.targetProjectId, args.reviewerUserIds ?? undefined, args.workItemIds ?? undefined, args.createFrom, args.triggerAIReviewRun ?? false ); return { content: [{ type: "text", text: JSON.stringify(changeRequest, null, 2) }], }; }
- Core implementation function that handles repository ID resolution (numeric conversion if needed), constructs the payload, and makes the POST request to Codeup API to create the change request.export async function createChangeRequestFunc( organizationId: string, repositoryId: string, title: string, sourceBranch: string, targetBranch: string, description?: string, sourceProjectId?: number, targetProjectId?: number, reviewerUserIds?: string[], workItemIds?: string[], createFrom: string = "WEB", // Possible values: WEB, COMMAND_LINE triggerAIReviewRun: boolean = false // Whether to trigger AI review ): Promise<z.infer<typeof ChangeRequestSchema>> { const encodedRepoId = handleRepositoryIdEncoding(repositoryId); // 检查和获取sourceProjectId和targetProjectId let sourceIdString: string | undefined; let targetIdString: string | undefined; if (sourceProjectId !== undefined) { sourceIdString = floatToIntString(sourceProjectId); } if (targetProjectId !== undefined) { targetIdString = floatToIntString(targetProjectId); } // 如果repositoryId是纯数字,且sourceProjectId或targetProjectId未提供,直接使用repositoryId的值 if (!isNaN(Number(repositoryId))) { // 是数字ID,可以直接使用 if (sourceIdString === undefined) { sourceIdString = repositoryId; } if (targetIdString === undefined) { targetIdString = repositoryId; } } else if (repositoryId.includes("%2F") || repositoryId.includes("/")) { // 如果是组织ID与仓库名称的组合,调用API获取数字ID if (sourceIdString === undefined || targetIdString === undefined) { try { const numericId = await getRepositoryNumericId(organizationId, encodedRepoId); if (sourceIdString === undefined) { sourceIdString = numericId; } if (targetIdString === undefined) { targetIdString = numericId; } } catch (error) { throw new Error(`When using 'organizationId%2Frepo-name' format, you must first get the numeric ID of the repository and use it for sourceProjectId and targetProjectId parameters. Please use get_repository tool to get the numeric ID of '${repositoryId}' and then use that ID as the value for sourceProjectId and targetProjectId.`); } } } // 确保sourceProjectId和targetProjectId已设置 if (sourceIdString === undefined) { throw new Error("Could not get sourceProjectId, please provide this parameter manually"); } if (targetIdString === undefined) { throw new Error("Could not get targetProjectId, please provide this parameter manually"); } const url = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/changeRequests`; // 准备payload const payload: Record<string, any> = { title: title, sourceBranch: sourceBranch, targetBranch: targetBranch, sourceProjectId: sourceIdString, targetProjectId: targetIdString, createFrom: createFrom, }; // 添加可选参数 if (description !== undefined) { payload.description = description; } if (reviewerUserIds !== undefined) { payload.reviewerUserIds = reviewerUserIds; } if (workItemIds !== undefined) { payload.workItemIds = workItemIds; } if (triggerAIReviewRun !== undefined) { payload.triggerAIReviewRun = triggerAIReviewRun; } const response = await yunxiaoRequest(url, { method: "POST", body: payload, }); return ChangeRequestSchema.parse(response); }
- operations/codeup/types.ts:340-353 (schema)Zod schema defining the input parameters and validation for the create_change_request tool.export const CreateChangeRequestSchema = z.object({ organizationId: z.string().describe("Organization ID, can be found in the basic information page of the organization admin console"), repositoryId: z.string().describe("Repository ID or a combination of organization ID and repository name, for example: 2835387 or organizationId%2Frepo-name (Note: slashes need to be URL encoded as %2F)"), title: z.string().describe("Title, no more than 256 characters"), description: z.string().nullable().optional().describe("Description, no more than 10000 characters"), sourceBranch: z.string().describe("Source branch name"), sourceProjectId: z.number().optional().describe("Source repository ID (if not provided, will try to get automatically)"), targetBranch: z.string().describe("Target branch name"), targetProjectId: z.number().optional().describe("Target repository ID (if not provided, will try to get automatically)"), reviewerUserIds: z.array(z.string()).nullable().optional().describe("Reviewer user ID list"), workItemIds: z.array(z.string()).nullable().optional().describe("Associated work item ID list"), createFrom: z.string().optional().default("WEB").describe("Creation source. Possible values: WEB (created from web page), COMMAND_LINE (created from command line). Default is WEB"), triggerAIReviewRun: z.boolean().optional().default(false).describe("Whether to trigger AI review, default is false"), });
- tool-registry/code-management.ts:90-93 (registration)Tool registration entry that defines the tool name, description, and input schema for the MCP tool registry.name: "create_change_request", description: "[Code Management] Create a new change request", inputSchema: zodToJsonSchema(types.CreateChangeRequestSchema), },
- operations/codeup/types.ts:158-216 (schema)Zod schema for the response object returned by the create change request API.export const ChangeRequestSchema = z.object({ ahead: z.number().int().nullable().optional().describe("源分支领先目标分支的commit数量"), allRequirementsPass: z.boolean().nullable().optional().describe("是否所有卡点项通过"), author: z.object({ avatar: z.string().nullable().optional().describe("用户头像地址"), email: z.string().nullable().optional().describe("用户邮箱"), name: z.string().nullable().optional().describe("用户名称"), state: z.string().nullable().optional().describe("用户状态:active - 激活可用;blocked - 阻塞暂不可用"), userId: z.string().nullable().optional().describe("云效用户ID"), username: z.string().nullable().optional().describe("用户登录名") }).nullable().optional().describe("创建者信息"), behind: z.number().int().nullable().optional().describe("目标分支领先源分支的commit数量"), canRevertOrCherryPick: z.boolean().nullable().optional().describe("是否能Revert或者CherryPick"), conflictCheckStatus: z.string().nullable().optional().describe("冲突检测状态:CHECKING - 检测中;HAS_CONFLICT - 有冲突;NO_CONFLICT - 无冲突;FAILED - 检测失败"), createFrom: z.string().nullable().optional().describe("创建来源:WEB - 页面创建;COMMAND_LINE - 命令行创建"), createTime: z.string().nullable().optional().describe("创建时间 (ISO 8601格式)"), description: z.string().nullable().optional().describe("描述"), detailUrl: z.string().nullable().optional().describe("合并请求详情地址"), hasReverted: z.boolean().nullable().optional().describe("是否Revert过"), localId: z.union([z.string(), z.number().int()]).nullable().optional().describe("局部ID,表示代码库中第几个合并请求"), mergedRevision: z.string().nullable().optional().describe("合并版本(提交ID),仅已合并状态才有值"), mrType: z.string().nullable().optional().describe("合并请求类型"), projectId: z.number().int().nullable().optional().describe("项目ID"), reviewers: z.array(z.object({ avatar: z.string().nullable().optional().describe("用户头像地址"), email: z.string().nullable().optional().describe("用户邮箱"), hasCommented: z.boolean().nullable().optional().describe("是否已评论"), hasReviewed: z.boolean().nullable().optional().describe("是否已审阅"), name: z.string().nullable().optional().describe("用户名称"), reviewOpinionStatus: z.string().nullable().optional().describe("审阅意见状态"), reviewTime: z.string().nullable().optional().describe("审阅时间 (ISO 8601格式)"), state: z.string().nullable().optional().describe("用户状态"), userId: z.string().nullable().optional().describe("云效用户ID"), username: z.string().nullable().optional().describe("用户登录名") })).nullable().optional().describe("评审人列表"), sourceBranch: z.string().nullable().optional().describe("源分支"), sourceCommitId: z.string().nullable().optional().describe("源提交ID,当createFrom=COMMAND_LINE时有值"), sourceProjectId: z.union([z.string(), z.number().int()]).nullable().optional().describe("源库ID"), sourceRef: z.string().nullable().optional().describe("源提交引用,当createFrom=COMMAND_LINE时有值"), status: z.string().nullable().optional().describe("合并请求状态:UNDER_DEV - 开发中;UNDER_REVIEW - 评审中;TO_BE_MERGED - 待合并;CLOSED - 已关闭;MERGED - 已合并"), subscribers: z.array(z.object({ avatar: z.string().nullable().optional().describe("用户头像地址"), email: z.string().nullable().optional().describe("用户邮箱"), name: z.string().nullable().optional().describe("用户名称"), state: z.string().nullable().optional().describe("用户状态"), userId: z.string().nullable().optional().describe("云效用户ID"), username: z.string().nullable().optional().describe("用户登录名") })).nullable().optional().describe("订阅人列表"), supportMergeFastForwardOnly: z.boolean().nullable().optional().describe("是否支持fast-forward-only"), targetBranch: z.string().nullable().optional().describe("目标分支"), targetProjectId: z.union([z.string(), z.number().int()]).nullable().optional().describe("目标库ID"), targetProjectNameWithNamespace: z.string().nullable().optional().describe("目标库名称(含完整父路径)"), targetProjectPathWithNamespace: z.string().nullable().optional().describe("目标库路径(含完整父路径)"), title: z.string().nullable().optional().describe("标题"), totalCommentCount: z.number().int().nullable().optional().describe("总评论数"), unResolvedCommentCount: z.number().int().nullable().optional().describe("未解决评论数"), updateTime: z.string().nullable().optional().describe("更新时间 (ISO 8601格式)"), webUrl: z.string().nullable().optional().describe("页面地址") });