Skip to main content
Glama

gitea_workflow_sync_labels

Sync repository labels automatically using workflow configuration. Creates status, priority, and type labels defined in your config to maintain consistent labeling across projects.

Instructions

Sync repository labels based on workflow configuration. Creates status/, priority/, type/* and other labels defined in the config.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerNoRepository owner. Uses context if not provided
repoNoRepository name. Uses context if not provided
dry_runNoPreview changes without applying (default: false)

Implementation Reference

  • The core handler function `workflowSyncLabels` that implements the tool logic. Loads workflow config, fetches existing repo labels via Gitea API, generates required labels from config using `getAllLabels`, creates missing labels and updates colors/descriptions as needed, supports dry-run mode, returns sync report.
    /** * 同步标签系统 */ export async function workflowSyncLabels( ctx: WorkflowToolsContext, args: { owner?: string; repo?: string; config?: WorkflowConfig; dry_run?: boolean; } ): Promise<{ success: boolean; created: string[]; updated: string[]; skipped: string[]; errors: string[]; }> { logger.debug({ args: { ...args, config: args.config ? '[provided]' : undefined } }, 'Syncing labels'); const { owner, repo } = ctx.contextManager.resolveOwnerRepo(args.owner, args.repo); const dryRun = args.dry_run ?? false; // 获取配置 let config = args.config; if (!config) { const loadResult = await workflowLoadConfig(ctx, { owner, repo }); if (!loadResult.success || !loadResult.config) { return { success: false, created: [], updated: [], skipped: [], errors: [loadResult.error || '无法加载配置'], }; } config = loadResult.config; } const created: string[] = []; const updated: string[] = []; const skipped: string[] = []; const errors: string[] = []; // 获取现有标签 const existingLabels = await ctx.client.get<Array<{ id: number; name: string; color: string }>>( `/repos/${owner}/${repo}/labels` ); const existingLabelMap = new Map(existingLabels.map((l) => [l.name, l])); // 获取配置中的所有标签 const configLabels = getAllLabels(config); for (const { name, config: labelConfig } of configLabels) { try { const existing = existingLabelMap.get(name); if (existing) { // 检查是否需要更新 if (existing.color !== labelConfig.color) { if (!dryRun) { await ctx.client.patch(`/repos/${owner}/${repo}/labels/${existing.id}`, { color: labelConfig.color, description: labelConfig.description, }); } updated.push(name); } else { skipped.push(name); } } else { // 创建新标签 if (!dryRun) { await ctx.client.post(`/repos/${owner}/${repo}/labels`, { name, color: labelConfig.color, description: labelConfig.description, }); } created.push(name); } } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); errors.push(`标签 ${name}: ${errorMessage}`); } } logger.info( { owner, repo, created: created.length, updated: updated.length, skipped: skipped.length }, 'Labels synced' ); return { success: errors.length === 0, created, updated, skipped, errors, }; }
  • Registers the `gitea_workflow_sync_labels` tool with the MCP server. Defines title, description, Zod input schema (owner, repo, dry_run), and a wrapper handler that calls the core `workflowSyncLabels` function from workflow.ts, handles errors, and formats response.
    mcpServer.registerTool( 'gitea_workflow_sync_labels', { title: '同步标签系统', description: 'Sync repository labels based on workflow configuration. Creates status/*, priority/*, type/* and other labels defined in the config.', inputSchema: z.object({ owner: z.string().optional().describe('Repository owner. Uses context if not provided'), repo: z.string().optional().describe('Repository name. Uses context if not provided'), dry_run: z.boolean().optional().describe('Preview changes without applying (default: false)'), }), }, async (args) => { try { const result = await WorkflowTools.workflowSyncLabels( { client: ctx.client, contextManager: ctx.contextManager }, args ); return { content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }], isError: !result.success, }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: 'text' as const, text: `Error: ${errorMessage}` }], isError: true, }; } } );
  • Zod input schema for the tool defining parameters: owner (optional string), repo (optional string), dry_run (optional boolean). Used for input validation during registration.
    inputSchema: z.object({ owner: z.string().optional().describe('Repository owner. Uses context if not provided'), repo: z.string().optional().describe('Repository name. Uses context if not provided'), dry_run: z.boolean().optional().describe('Preview changes without applying (default: false)'), }),

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SupenBysz/gitea-mcp-tool'

If you have feedback or need assistance with the MCP directory API, please join our Discord server