gitea_compliance_check_all
Run comprehensive compliance checks on branches, commits, and pull requests to identify policy violations and generate detailed reports.
Instructions
Run comprehensive compliance check on branch, commits, and/or PR. Returns detailed report.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | No | Repository owner. Uses context if not provided | |
| repo | No | Repository name. Uses context if not provided | |
| branch | No | Branch name to check | |
| pr_number | No | PR number to check (also checks its commits) | |
| commit_count | No | Max number of commits to check (default: 10) | |
| config_path | No | Path to compliance config file | |
| token | No | Optional API token to override default authentication |
Implementation Reference
- src/tools/compliance.ts:469-555 (handler)Core handler function implementing the comprehensive compliance check for branches, commits, and PRs. Orchestrates individual check functions and aggregates results.export async function checkAll( ctx: ComplianceToolsContext, params: CheckAllParams ): Promise<AllCheckResult> { const owner = ctx.contextManager.resolveOwner(params.owner); const repo = ctx.contextManager.resolveRepo(params.repo); logger.info({ owner, repo }, 'Running comprehensive compliance check'); const result: AllCheckResult = { summary: { total_checks: 0, passed: 0, failed: 0, compliant: true, }, }; // 1. 检查分支(如果提供) if (params.branch) { result.branch = await checkBranch(ctx, { branch: params.branch, config_path: params.config_path, }); result.summary.total_checks++; if (result.branch.compliant) { result.summary.passed++; } else { result.summary.failed++; result.summary.compliant = false; } } // 2. 检查 PR(如果提供) if (params.pr_number) { result.pr = await checkPR(ctx, { owner, repo, pr_number: params.pr_number, config_path: params.config_path, token: params.token, }); result.summary.total_checks++; if (result.pr.compliant) { result.summary.passed++; } else { result.summary.failed++; result.summary.compliant = false; } // 如果有 PR,检查其关联的提交 try { const commitsResponse = await ctx.client.request({ method: 'GET', path: `/repos/${owner}/${repo}/pulls/${params.pr_number}/commits`, token: params.token, }); const commits = (commitsResponse.data as any[]) || []; const commitCount = params.commit_count || 10; const commitsToCheck = commits.slice(0, commitCount); result.commits = []; for (const commit of commitsToCheck) { const commitResult = await checkCommit(ctx, { owner, repo, sha: commit.sha, message: commit.commit?.message, config_path: params.config_path, token: params.token, }); result.commits.push(commitResult); result.summary.total_checks++; if (commitResult.compliant) { result.summary.passed++; } else { result.summary.failed++; result.summary.compliant = false; } } } catch (err) { logger.warn({ pr: params.pr_number, error: err }, 'Failed to fetch PR commits'); } } return result; }
- src/tools-registry/compliance-registry.ts:90-114 (registration)Registers the 'gitea_compliance_check_all' tool with the MCP server, including input schema definition and thin wrapper handler that delegates to the core checkAll implementation.mcpServer.registerTool( 'gitea_compliance_check_all', { title: '综合规范检查', description: 'Run comprehensive compliance check on branch, commits, and/or PR. Returns detailed report.', 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'), branch: z.string().optional().describe('Branch name to check'), pr_number: z.number().int().positive().optional().describe('PR number to check (also checks its commits)'), commit_count: z.number().int().positive().optional().describe('Max number of commits to check (default: 10)'), config_path: z.string().optional().describe('Path to compliance config file'), token: tokenSchema, }), }, async (args) => { try { const result = await ComplianceTools.checkAll(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: owner, repo, branch, pr_number, commit_count, config_path, token.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'), branch: z.string().optional().describe('Branch name to check'), pr_number: z.number().int().positive().optional().describe('PR number to check (also checks its commits)'), commit_count: z.number().int().positive().optional().describe('Max number of commits to check (default: 10)'), config_path: z.string().optional().describe('Path to compliance config file'), token: tokenSchema, }),
- src/tools/compliance.ts:459-464 (schema)TypeScript interface defining input parameters for checkAll, matching the Zod schema.export interface CheckAllParams extends ComplianceParams { branch?: string; pr_number?: number; commit_count?: number; config_path?: string; }
- src/tools/compliance.ts:79-101 (helper)Helper function to load compliance configuration from YAML file (.gitea/compliance.yaml), merging with defaults.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; }