Skip to main content
Glama

gitea_compliance_check_branch

Validate branch names against naming conventions to ensure compliance with repository standards. Returns status and improvement suggestions.

Instructions

Check if branch name complies with naming conventions. Returns compliance status and suggestions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branchYesBranch name to check
config_pathNoPath to compliance config file (.gitea/compliance.yaml)

Implementation Reference

  • The core handler function that checks if the provided branch name complies with the naming patterns defined in the compliance configuration. It loads the config, tests regex patterns, and generates issues/suggestions if non-compliant.
    export async function checkBranch( ctx: ComplianceToolsContext, params: CheckBranchParams ): Promise<BranchCheckResult> { const config = loadComplianceConfig(params.config_path); const branch = params.branch; logger.info({ branch }, 'Checking branch naming'); const issues: string[] = []; const suggestions: string[] = []; let matchedPattern: string | undefined; // 检查分支名是否匹配任何允许的模式 for (const pattern of config.branch.patterns) { const regex = new RegExp(pattern); if (regex.test(branch)) { matchedPattern = pattern; break; } } if (!matchedPattern) { issues.push(`分支名 "${branch}" 不符合任何允许的命名模式`); // 提供建议 if (branch.includes('feat') || branch.includes('feature')) { suggestions.push('功能分支建议格式: feat/issue-{id}-{描述}'); } else if (branch.includes('fix') || branch.includes('bug')) { suggestions.push('修复分支建议格式: fix/issue-{id}-{描述}'); } else if (branch.includes('doc')) { suggestions.push('文档分支建议格式: docs/{描述}'); } else { suggestions.push('建议的分支格式:'); suggestions.push(' - feat/issue-{id}-{描述} (新功能)'); suggestions.push(' - fix/issue-{id}-{描述} (修复)'); suggestions.push(' - docs/{描述} (文档)'); suggestions.push(' - refactor/{描述} (重构)'); } } return { branch, compliant: issues.length === 0, issues, suggestions, matched_pattern: matchedPattern, }; }
  • Registers the 'gitea_compliance_check_branch' tool with the MCP server, providing title, description, input schema, and an async handler that delegates to ComplianceTools.checkBranch.
    mcpServer.registerTool( 'gitea_compliance_check_branch', { title: '检查分支命名规范', description: 'Check if branch name complies with naming conventions. Returns compliance status and suggestions.', inputSchema: z.object({ branch: z.string().min(1).describe('Branch name to check'), config_path: z.string().optional().describe('Path to compliance config file (.gitea/compliance.yaml)'), }), }, async (args) => { try { const result = await ComplianceTools.checkBranch(toolsContext, args as any); return { content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }] }; } 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 defining the parameters for the tool: required 'branch' string and optional 'config_path'.
    inputSchema: z.object({ branch: z.string().min(1).describe('Branch name to check'), config_path: z.string().optional().describe('Path to compliance config file (.gitea/compliance.yaml)'), }),
  • Helper function to load compliance configuration from .gitea/compliance.yaml or fallback to defaults. Used by the handler to get branch patterns.
    export function loadComplianceConfig(configPath?: string): ComplianceConfig { const searchPaths = [ configPath, path.join(process.cwd(), '.gitea', 'compliance.yaml'), path.join(process.cwd(), '.gitea', 'compliance.yml'), ].filter(Boolean) as string[]; for (const p of searchPaths) { if (fs.existsSync(p)) { try { const content = fs.readFileSync(p, 'utf-8'); const parsed = yaml.parse(content); logger.info({ path: p }, 'Loaded compliance config'); return mergeConfig(DEFAULT_CONFIG, parsed); } catch (err) { logger.warn({ path: p, error: err }, 'Failed to parse compliance config'); } } } logger.info('Using default compliance config'); return DEFAULT_CONFIG; }
  • TypeScript interface defining the structure of the compliance configuration, including branch patterns used for checking.
    export interface ComplianceConfig { branch: { patterns: string[]; }; commit: { types: string[]; scope_required: boolean; max_subject_length: number; }; pr: { required_sections: string[]; require_issue_link: boolean; }; }

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