Skip to main content
Glama

gitea_workflow_sync_labels

Synchronize repository labels from workflow configuration to create standardized status, priority, and type labels in Gitea repositories.

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

  • Core handler function for 'gitea_workflow_sync_labels' that synchronizes repository labels with the workflow configuration. Loads config if not provided, fetches existing labels, creates new ones, updates colors/descriptions, supports dry-run, and 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, defining title, description, Zod input schema, and a wrapper handler that calls the core workflowSyncLabels function and formats the 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, repo (optional), dry_run (optional boolean).
    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)'), }),
  • Imports helper functions like getAllLabels used in the handler to retrieve all labels from config.
    import { type WorkflowConfig, type ProjectType, generateDefaultConfig, serializeConfig, parseConfig, validateConfig, getAllLabels, getSLAHours, getLabelPrefixes, buildLabel, matchLabel, resolveRulePlaceholders, } from '../utils/workflow-config.js';

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