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/gates

Returns 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/run

Run 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/:id

Get 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:

ParameterTypeDescription
gateIdstringGate identifier (pre-commit, pre-push, pre-deploy)
projectRootstringPath to project root
optionsobjectOptional configuration

Options:

OptionTypeDefaultDescription
customGatesobject{}Custom gate definitions
skiparray[]Check IDs to skip
strictbooleanfalseStop on first failure
verbosebooleanfalseInclude 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:

ParameterTypeDescription
checkIdstringCheck identifier
projectRootstringPath 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:

ParameterTypeDescription
checkobjectCheck configuration from resolveCheck
projectRootstringPath to project root
optionsobjectExecution options

Options:

OptionTypeDefaultDescription
timeoutnumber300000Timeout in milliseconds (5 min)
verbosebooleanfalseInclude 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:

ParameterTypeDescription
projectRootstringPath to project root
detectstringDetection 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:

ParameterTypeDescription
gateIdstringGate to run
optionsobjectHook options

Options:

OptionTypeDefaultDescription
strictbooleantrueFail on first error
skiparray[]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 format

Available Checks#

typecheck#

TypeScript type checking.

ToolCommandDetection
tscnpx tsc --noEmittsconfig.json

lint#

Code linting.

ToolCommandDetection
eslintnpx eslint .eslint.config.js, .eslintrc.js, .eslintrc.json
biomenpx biome check .biome.json

format#

Code formatting.

ToolCommandDetection
prettiernpx prettier --check ..prettierrc, .prettierrc.json, prettier.config.js
biomenpx biome format --check .biome.json

test#

Test execution.

ToolCommandDetection
jestnpm testjest.config.js
vitestnpm testvitest.config.ts
mochanpm testpackage.json:mocha
npmnpm testpackage.json:scripts.test

build#

Production build.

ToolCommandDetection
nextnpm run buildnext.config.js
vitenpm run buildvite.config.ts
npmnpm run buildpackage.json:scripts.build

security#

Security audit.

ToolCommandDetection
npmnpm audit --audit-level=highpackage-lock.json
yarnyarn audit --level highyarn.lock
pnpmpnpm audit --audit-level highpnpm-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 --verbose

Error 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#

  1. Start with pre-commit: Run quick checks before every commit
  2. Use pre-push for CI: Mirror your CI checks in pre-push
  3. Skip thoughtfully: Only skip checks when necessary
  4. Use strict mode in CI: Fail fast on any issue
  5. Run pre-deploy before releases: Catch security issues early
  6. Customize for your needs: Create custom gates for your workflow