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

  • Core implementation of the branch compliance check. Loads config, matches branch name against allowed regex patterns, generates issues and 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,
      };
    }
  • Tool registration for 'gitea_compliance_check_branch' including title, description, input schema, and wrapper handler delegating to checkBranch implementation.
    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 parameters for the tool: required branch name 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 fall back to defaults, used by the checkBranch handler.
    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;
    }
  • Default compliance configuration including branch naming patterns used when no config file is provided.
    const DEFAULT_CONFIG: ComplianceConfig = {
      branch: {
        patterns: [
          '^feat/issue-\\d+-.*$',
          '^fix/issue-\\d+-.*$',
          '^docs/.*$',
          '^refactor/.*$',
          '^test/.*$',
          '^chore/.*$',
          '^main$',
          '^dev$',
          '^release/.*$',
        ],
      },
      commit: {
        types: ['feat', 'fix', 'docs', 'refactor', 'test', 'chore', 'style', 'perf', 'ci', 'build', 'revert'],
        scope_required: false,
        max_subject_length: 72,
      },
      pr: {
        required_sections: ['Summary', 'Test Plan'],
        require_issue_link: true,
      },
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the tool returns 'compliance status and suggestions,' which adds some behavioral context beyond the input schema. However, it lacks details on permissions, rate limits, error handling, or whether it's read-only or mutative. For a tool with zero annotation coverage, this is insufficient for safe agent use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded and concise: two sentences that directly state the tool's function and output. Every sentence earns its place by providing essential information without redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete. It covers the basic purpose and output but lacks details on behavioral traits, error cases, or how to interpret the 'suggestions.' For a compliance-checking tool with potential configuration dependencies, this leaves gaps for an AI agent to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters ('branch' and 'config_path') adequately. The description doesn't add any extra meaning about parameters beyond what's in the schema, such as examples or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Check if branch name complies with naming conventions.' It specifies the verb ('Check') and resource ('branch name'), and distinguishes it from siblings like 'gitea_compliance_check_all' or 'gitea_compliance_check_commit' by focusing on branch naming. However, it doesn't explicitly contrast with all siblings, so it's not a perfect 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'gitea_compliance_check_all' for broader checks or 'gitea_workflow_check_blocked' for workflow-specific issues. There's no context on prerequisites, such as needing a configured compliance file, or exclusions for when not to use it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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