Quality Gates API
The Quality Gates API provides configurable quality checks for your codebase, including type checking, linting, testing, and security audits.
Overview#
Quality gates are predefined sets of checks that run at different stages of development:
- pre-commit: Quick checks before committing code
- pre-push: Thorough checks before pushing to remote
- pre-deploy: Full audit before deployment
The system automatically detects available tools in your project and runs appropriate checks.
REST API Endpoints#
List Quality Gates#
GET /api/v1/quality/gatesReturns available quality gates.
Response:
1{
2 "data": [
3 {
4 "id": "pre-commit",
5 "name": "Pre-Commit",
6 "description": "Quick checks before committing code",
7 "checks": ["typecheck", "lint", "format"]
8 },
9 {
10 "id": "pre-push",
11 "name": "Pre-Push",
12 "description": "Thorough checks before pushing to remote",
13 "checks": ["typecheck", "lint", "test", "build"]
14 },
15 {
16 "id": "pre-deploy",
17 "name": "Pre-Deploy",
18 "description": "Full audit before deployment",
19 "checks": ["typecheck", "lint", "test", "build", "security"]
20 }
21 ]
22}Run Quality Gate#
POST /api/v1/quality/runRun a quality gate and get results.
Request Body:
1{
2 "gate": "pre-commit",
3 "options": {
4 "skip": ["format"],
5 "strict": true,
6 "verbose": false
7 }
8}Response:
1{
2 "data": {
3 "gate": "pre-commit",
4 "name": "Pre-Commit",
5 "status": "pass",
6 "passed": 2,
7 "failed": 0,
8 "skipped": 1,
9 "total": 3,
10 "results": [
11 {
12 "id": "typecheck",
13 "name": "TypeScript",
14 "status": "pass",
15 "message": "Passed"
16 },
17 {
18 "id": "lint",
19 "name": "Linting",
20 "status": "pass",
21 "message": "Passed"
22 },
23 {
24 "id": "format",
25 "name": "Formatting",
26 "status": "skip",
27 "message": "Skipped by user"
28 }
29 ]
30 },
31 "meta": {
32 "executionTime": 5230,
33 "requestId": "req_abc123"
34 }
35}Get Report#
GET /api/v1/quality/reports/:idGet a previously generated quality report.
JavaScript/Node.js API#
Module Import#
const quality = require('bootspring/quality');Running Gates#
runGate(gateId, projectRoot, options)#
Run a quality gate against a project.
Parameters:
| Parameter | Type | Description |
|---|---|---|
gateId | string | Gate identifier (pre-commit, pre-push, pre-deploy) |
projectRoot | string | Path to project root |
options | object | Optional configuration |
Options:
| Option | Type | Default | Description |
|---|---|---|---|
customGates | object | {} | Custom gate definitions |
skip | array | [] | Check IDs to skip |
strict | boolean | false | Stop on first failure |
verbose | boolean | false | Include full output |
Returns: Gate results object.
1const results = quality.runGate('pre-commit', '/path/to/project', {
2 skip: ['format'],
3 strict: true
4});
5
6// Returns:
7// {
8// gate: 'pre-commit',
9// name: 'Pre-Commit',
10// description: 'Quick checks before committing code',
11// status: 'pass', // or 'fail'
12// passed: 2,
13// failed: 0,
14// skipped: 1,
15// total: 3,
16// results: [
17// { id: 'typecheck', name: 'TypeScript', status: 'pass', message: 'Passed' },
18// { id: 'lint', name: 'Linting', status: 'pass', message: 'Passed' },
19// { id: 'format', name: 'Formatting', status: 'skip', message: 'Skipped by user' }
20// ]
21// }Check Management#
resolveCheck(checkId, projectRoot)#
Resolve a check to its executable command.
Parameters:
| Parameter | Type | Description |
|---|---|---|
checkId | string | Check identifier |
projectRoot | string | Path to project root |
Returns: Check configuration or null if tool not available.
1const check = quality.resolveCheck('lint', '/path/to/project');
2// Returns:
3// {
4// id: 'lint',
5// name: 'Linting',
6// description: 'Code linting',
7// command: 'npx eslint .',
8// tool: 'eslint'
9// }executeCheck(check, projectRoot, options)#
Execute a single check.
Parameters:
| Parameter | Type | Description |
|---|---|---|
check | object | Check configuration from resolveCheck |
projectRoot | string | Path to project root |
options | object | Execution options |
Options:
| Option | Type | Default | Description |
|---|---|---|---|
timeout | number | 300000 | Timeout in milliseconds (5 min) |
verbose | boolean | false | Include full output |
1const check = quality.resolveCheck('test', '/path/to/project');
2const result = quality.executeCheck(check, '/path/to/project', {
3 timeout: 60000,
4 verbose: true
5});
6
7// Returns:
8// {
9// id: 'test',
10// name: 'Tests',
11// status: 'pass', // or 'fail'
12// message: 'Passed',
13// output: '...' // if verbose
14// }getAvailableChecks(projectRoot)#
Get all checks available for a project.
1const checks = quality.getAvailableChecks('/path/to/project');
2// Returns:
3// [
4// { id: 'typecheck', name: 'TypeScript', tool: 'tsc', command: 'npx tsc --noEmit' },
5// { id: 'lint', name: 'Linting', tool: 'eslint', command: 'npx eslint .' },
6// { id: 'test', name: 'Tests', tool: 'vitest', command: 'npm test' },
7// // ...
8// ]Gate Management#
getGate(gateId, customGates)#
Get a gate definition.
1const gate = quality.getGate('pre-commit');
2// Returns:
3// {
4// name: 'Pre-Commit',
5// description: 'Quick checks before committing code',
6// checks: ['typecheck', 'lint', 'format']
7// }listGates(customGates)#
List all available gate IDs.
const gates = quality.listGates();
// Returns: ['pre-commit', 'pre-push', 'pre-deploy']Tool Detection#
detectTool(projectRoot, detect)#
Check if a tool is available in the project.
Parameters:
| Parameter | Type | Description |
|---|---|---|
projectRoot | string | Path to project root |
detect | string | Detection pattern |
Detection Patterns:
filename- Check if file exists (e.g.,tsconfig.json)package.json:property- Check package.json property (e.g.,package.json:scripts.test)
// Check for TypeScript
const hasTS = quality.detectTool('/path/to/project', 'tsconfig.json');
// Check for test script
const hasTests = quality.detectTool('/path/to/project', 'package.json:scripts.test');Git Hook Generation#
generateHookScript(gateId, options)#
Generate a git hook script.
Parameters:
| Parameter | Type | Description |
|---|---|---|
gateId | string | Gate to run |
options | object | Hook options |
Options:
| Option | Type | Default | Description |
|---|---|---|---|
strict | boolean | true | Fail on first error |
skip | array | [] | Checks to skip |
1const script = quality.generateHookScript('pre-commit', {
2 skip: ['format']
3});
4
5// Returns:
6// #!/bin/sh
7// # Bootspring Quality Gate Hook
8//
9// npx bootspring quality pre-commit --strict --skip formatAvailable Checks#
typecheck#
TypeScript type checking.
| Tool | Command | Detection |
|---|---|---|
| tsc | npx tsc --noEmit | tsconfig.json |
lint#
Code linting.
| Tool | Command | Detection |
|---|---|---|
| eslint | npx eslint . | eslint.config.js, .eslintrc.js, .eslintrc.json |
| biome | npx biome check . | biome.json |
format#
Code formatting.
| Tool | Command | Detection |
|---|---|---|
| prettier | npx prettier --check . | .prettierrc, .prettierrc.json, prettier.config.js |
| biome | npx biome format --check . | biome.json |
test#
Test execution.
| Tool | Command | Detection |
|---|---|---|
| jest | npm test | jest.config.js |
| vitest | npm test | vitest.config.ts |
| mocha | npm test | package.json:mocha |
| npm | npm test | package.json:scripts.test |
build#
Production build.
| Tool | Command | Detection |
|---|---|---|
| next | npm run build | next.config.js |
| vite | npm run build | vite.config.ts |
| npm | npm run build | package.json:scripts.build |
security#
Security audit.
| Tool | Command | Detection |
|---|---|---|
| npm | npm audit --audit-level=high | package-lock.json |
| yarn | yarn audit --level high | yarn.lock |
| pnpm | pnpm audit --audit-level high | pnpm-lock.yaml |
Default Gates#
pre-commit#
Quick checks before committing.
Checks: typecheck, lint, format
pre-push#
Thorough checks before pushing.
Checks: typecheck, lint, test, build
pre-deploy#
Full audit before deployment.
Checks: typecheck, lint, test, build, security
MCP Tool#
The bootspring_quality MCP tool provides quality gate functionality.
Tool Definition#
1{
2 "name": "bootspring_quality",
3 "description": "Run quality gates to check code quality and security",
4 "inputSchema": {
5 "properties": {
6 "gate": {
7 "type": "string",
8 "enum": ["pre-commit", "pre-push", "pre-deploy"],
9 "description": "Quality gate to run"
10 }
11 },
12 "required": ["gate"]
13 }
14}Example#
{
"gate": "pre-commit"
}Custom Gates#
Define custom gates for your project:
1const quality = require('bootspring/quality');
2
3const customGates = {
4 'quick-check': {
5 name: 'Quick Check',
6 description: 'Fast validation for CI',
7 checks: ['typecheck', 'lint']
8 },
9 'full-audit': {
10 name: 'Full Audit',
11 description: 'Complete project audit',
12 checks: ['typecheck', 'lint', 'format', 'test', 'build', 'security']
13 }
14};
15
16const results = quality.runGate('quick-check', '/path/to/project', {
17 customGates
18});CLI Commands#
1# Run pre-commit gate
2bootspring quality pre-commit
3
4# Run with strict mode (stop on first failure)
5bootspring quality pre-push --strict
6
7# Skip specific checks
8bootspring quality pre-deploy --skip format --skip security
9
10# Verbose output
11bootspring quality pre-commit --verboseError Handling#
Unknown Gate#
1{
2 "error": {
3 "code": "NOT_FOUND",
4 "message": "Unknown gate: invalid-gate"
5 }
6}Check Failure#
1// Individual check result on failure
2{
3 id: 'lint',
4 name: 'Linting',
5 status: 'fail',
6 message: 'src/index.ts:10:5 - Unexpected any. Specify a different type.',
7 exitCode: 1
8}Tool Not Available#
1// When a check's tool is not detected
2{
3 id: 'typecheck',
4 name: 'TypeScript',
5 status: 'skip',
6 message: 'Tool not available'
7}Constants#
DEFAULT_GATES#
1const { DEFAULT_GATES } = require('bootspring/quality');
2
3// {
4// 'pre-commit': { name: 'Pre-Commit', checks: [...] },
5// 'pre-push': { name: 'Pre-Push', checks: [...] },
6// 'pre-deploy': { name: 'Pre-Deploy', checks: [...] }
7// }CHECK_DEFINITIONS#
1const { CHECK_DEFINITIONS } = require('bootspring/quality');
2
3// {
4// typecheck: { name: 'TypeScript', commands: [...] },
5// lint: { name: 'Linting', commands: [...] },
6// format: { name: 'Formatting', commands: [...] },
7// test: { name: 'Tests', commands: [...] },
8// build: { name: 'Build', commands: [...] },
9// security: { name: 'Security', commands: [...] }
10// }Best Practices#
- Start with pre-commit: Run quick checks before every commit
- Use pre-push for CI: Mirror your CI checks in pre-push
- Skip thoughtfully: Only skip checks when necessary
- Use strict mode in CI: Fail fast on any issue
- Run pre-deploy before releases: Catch security issues early
- Customize for your needs: Create custom gates for your workflow