list_branches
Retrieve and manage branch listings in Codeup repositories to track development work and organize code versions for team collaboration.
Instructions
[Code Management] List branches in a Codeup repository
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) | |
| page | No | Page number | |
| perPage | No | Items per page | |
| sort | No | Sort order: name_asc - name ascending, name_desc - name descending, updated_asc - update time ascending, updated_desc - update time descending | name_asc |
| search | No | Search query |
Implementation Reference
- tool-handlers/code-management.ts:50-63 (handler)Handler for list_branches tool: parses arguments with ListBranchesSchema, calls branches.listBranchesFunc, and returns JSON stringified result.case "list_branches": { const args = types.ListBranchesSchema.parse(request.params.arguments); const branchList = await branches.listBranchesFunc( args.organizationId, args.repositoryId, args.page, args.perPage, args.sort, args.search ?? undefined ); return { content: [{ type: "text", text: JSON.stringify(branchList, null, 2) }], }; }
- operations/codeup/types.ts:238-245 (schema)Zod schema definition for list_branches input validation: defines organizationId, repositoryId, pagination, sort, and search params.export const ListBranchesSchema = 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)"), page: z.number().int().default(1).optional().describe("Page number"), perPage: z.number().int().default(20).optional().describe("Items per page"), sort: z.enum(["name_asc", "name_desc", "updated_asc", "updated_desc"]).default("name_asc").optional().describe("Sort order: name_asc - name ascending, name_desc - name descending, updated_asc - update time ascending, updated_desc - update time descending"), search: z.string().nullable().optional().describe("Search query"), });
- tool-registry/code-management.ts:23-25 (registration)Tool registration: defines name, description, and inputSchema for list_branches in the code management tools array.name: "list_branches", description: "[Code Management] List branches in a Codeup repository", inputSchema: zodToJsonSchema(types.ListBranchesSchema),
- Core helper function listBranchesFunc: makes API request to list branches in a repository, handles URL encoding for repoId, builds query params, calls yunxiaoRequest, parses array of branches with CodeupBranchSchema.export async function listBranchesFunc( organizationId: string, repositoryId: string, page?: number, perPage?: number, sort?: string, // Possible values: name_asc, name_desc, updated_asc, updated_desc search?: string ): Promise<z.infer<typeof CodeupBranchSchema>[]> { console.error("listBranchesFunc page:" + page + " perPage:" + perPage + " sort:" + sort + " search:" + search); // Automatically handle unencoded slashes in repositoryId if (repositoryId.includes("/")) { // Found unencoded slash, automatically URL encode it const parts = repositoryId.split("/", 2); if (parts.length === 2) { const encodedRepoName = encodeURIComponent(parts[1]); // Remove + signs from encoding (spaces are encoded as +, but we need %20) const formattedEncodedName = encodedRepoName.replace(/\+/g, "%20"); repositoryId = `${parts[0]}%2F${formattedEncodedName}`; } } const baseUrl = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${repositoryId}/branches`; // Build query parameters - use lowercase parameter names as expected by the API const queryParams: Record<string, string | number | undefined> = {}; if (page !== undefined && page !== null) { queryParams.page = page; } if (perPage !== undefined && perPage !== null) { queryParams.perPage = perPage; } if (sort !== undefined && sort !== null) { queryParams.sort = sort; } if (search !== undefined && search !== null) { queryParams.search = search; } const url = buildUrl(baseUrl, queryParams); const response = await yunxiaoRequest(url, { method: "GET", }); if (!Array.isArray(response)) { return []; } // Map each branch object and handle null values return response.map(branchData => { // Filter out null values that would cause parsing errors // This is a defensive approach until we update all schemas properly return CodeupBranchSchema.parse(branchData); }); }