compare
Compare code changes between commits, branches, or tags in Alibaba Cloud DevOps repositories to review differences and track modifications.
Instructions
[Code Management] Query code to compare content
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) | |
| from | Yes | Can be CommitSHA, branch name or tag name | |
| to | Yes | Can be CommitSHA, branch name or tag name | |
| sourceType | No | Options: branch, tag; if it's a commit comparison, you can omit this; if it's a branch comparison, you need to provide: branch, or you can omit it but ensure there are no branch or tag name conflicts; if it's a tag comparison, you need to provide: tag; if there are branches and tags with the same name, you need to strictly provide branch or tag | |
| targetType | No | Options: branch, tag; if it's a commit comparison, you can omit this; if it's a branch comparison, you need to provide: branch, or you can omit it but ensure there are no branch or tag name conflicts; if it's a tag comparison, you need to provide: tag; if there are branches and tags with the same name, you need to strictly provide branch or tag | |
| straight | No | Whether to use Merge-Base: straight=false means using Merge-Base; straight=true means not using Merge-Base; default is false, meaning using Merge-Base |
Implementation Reference
- tool-handlers/code-management.ts:139-154 (handler)Handler for the 'compare' tool: parses input using GetCompareSchema and invokes getCompareFunc from operations/codeup/compare.js, returning the result as JSON.case "compare": { const args = types.GetCompareSchema.parse(request.params.arguments); const compareResult = await compare.getCompareFunc( args.organizationId, args.repositoryId, args.from, args.to, args.sourceType ?? undefined, args.targetType ?? undefined, args.straight ?? undefined ); return { content: [{ type: "text", text: JSON.stringify(compareResult, null, 2) }], }; }
- operations/codeup/types.ts:308-316 (schema)Input schema (GetCompareSchema) for the 'compare' tool, defining parameters like organizationId, repositoryId, from, to, etc.export const GetCompareSchema = 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)"), from: z.string().describe("Can be CommitSHA, branch name or tag name"), to: z.string().describe("Can be CommitSHA, branch name or tag name"), sourceType: z.string().nullable().optional().describe("Options: branch, tag; if it's a commit comparison, you can omit this; if it's a branch comparison, you need to provide: branch, or you can omit it but ensure there are no branch or tag name conflicts; if it's a tag comparison, you need to provide: tag; if there are branches and tags with the same name, you need to strictly provide branch or tag"), targetType: z.string().nullable().optional().describe("Options: branch, tag; if it's a commit comparison, you can omit this; if it's a branch comparison, you need to provide: branch, or you can omit it but ensure there are no branch or tag name conflicts; if it's a tag comparison, you need to provide: tag; if there are branches and tags with the same name, you need to strictly provide branch or tag"), straight: z.string().default("false").nullable().optional().describe("Whether to use Merge-Base: straight=false means using Merge-Base; straight=true means not using Merge-Base; default is false, meaning using Merge-Base"), });
- tool-registry/code-management.ts:54-58 (registration)Registration of the 'compare' tool in getCodeManagementTools array, specifying name, description, and inputSchema.{ name: "compare", description: "[Code Management] Query code to compare content", inputSchema: zodToJsonSchema(types.GetCompareSchema), },
- operations/codeup/compare.ts:8-45 (helper)Core helper function getCompareFunc that performs the API call to Codeup compare endpoint and parses response with CompareSchema.export async function getCompareFunc( organizationId: string, repositoryId: string, from: string, to: string, sourceType?: string, // Possible values: branch, tag targetType?: string, // Possible values: branch, tag straight?: string ): Promise<z.infer<typeof CompareSchema>> { const encodedRepoId = handleRepositoryIdEncoding(repositoryId); const baseUrl = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/compares`; const queryParams: Record<string, string | undefined> = { from, to }; if (sourceType !== undefined) { queryParams.sourceType = sourceType; } if (targetType !== undefined) { queryParams.targetType = targetType; } if (straight !== undefined) { queryParams.straight = straight; } const url = buildUrl(baseUrl, queryParams); const response = await yunxiaoRequest(url, { method: "GET", }); return CompareSchema.parse(response); }
- operations/codeup/types.ts:73-81 (schema)Output schema (CompareSchema) used to parse the response from the compare API in getCompareFunc.export const CompareSchema = z.object({ base_commit_sha: z.string().optional(), commits: z.array(z.unknown()).optional(), commits_count: z.number().optional(), diffs: z.array(z.unknown()).optional(), files_count: z.number().optional(), from: z.string().optional(), to: z.string().optional(), });