Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,99 @@ npm run build
npm run cli -- --config compliance.yml --token ghp_xxx
```

### Adding a New Compliance Check

To add a new compliance check to the project, follow these steps:

1. **Create the check class** in `src/checks/`:
```typescript
// src/checks/your-check.ts
import { BaseCheck, type CheckContext, type CheckResult } from './base';

export class YourCheck extends BaseCheck {
readonly name = 'your-check-name';
readonly description = 'Description of what your check validates';

shouldRun(context: CheckContext): boolean {
// Determine if this check should run for the repository
const config = this.getRepoConfig(context, 'your_config_key');
return config !== undefined;
}

async check(context: CheckContext): Promise<CheckResult> {
// Implement your validation logic
const { repository } = context;
const config = this.getRepoConfig(context, 'your_config_key');

// Perform checks and return result
if (/* check passes */) {
return this.createCompliantResult('Check passed successfully');
}

return this.createNonCompliantResult('Check failed: reason');
}

async fix(context: CheckContext): Promise<CheckResult> {
// Optional: Implement auto-fix logic
if (context.dryRun) {
return this.check(context);
}

// Apply fixes using context.client
// Return result with fixed: true if successful
}
}
```

2. **Register the check** in `src/runner/check-registry.ts`:
```typescript
import { YourCheck } from '../checks/your-check';

const checkRegistry: CheckRegistry = {
// ... existing checks
'your-check-name': YourCheck,
};
```

3. **Define configuration types** in `src/config/types.ts`:
```typescript
export interface YourCheckConfig {
// Define your configuration structure
}

export interface ComplianceDefaults {
Copy link

@cubic-dev-ai cubic-dev-ai bot Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect type name in docs: use Defaults (not ComplianceDefaults) to match src/config/types.ts and ComplianceConfig.defaults.

Prompt for AI agents
Address the following comment on README.md at line 302:

<comment>Incorrect type name in docs: use Defaults (not ComplianceDefaults) to match src/config/types.ts and ComplianceConfig.defaults.</comment>

<file context>
@@ -239,6 +239,99 @@ npm run build
+     // Define your configuration structure
+   }
+
+   export interface ComplianceDefaults {
+     // ... existing configs
+     your_config_key?: YourCheckConfig;
</file context>
Suggested change
export interface ComplianceDefaults {
export interface Defaults {
Fix with Cubic

// ... existing configs
your_config_key?: YourCheckConfig;
}
```

4. **Update the JSON Schema** in `compliance-schema.json`:
Copy link

@cubic-dev-ai cubic-dev-ai bot Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarify JSON Schema update: also add the new key under rules.apply properties, not just defaults, since additionalProperties is false in both sections.

Prompt for AI agents
Address the following comment on README.md at line 308:

<comment>Clarify JSON Schema update: also add the new key under rules.apply properties, not just defaults, since additionalProperties is false in both sections.</comment>

<file context>
@@ -239,6 +239,99 @@ npm run build
+   }
+   ```
+
+4. **Update the JSON Schema** in `compliance-schema.json`:
+   - Add your check configuration to the `defaults` properties
+   - Ensure proper validation rules are defined
</file context>
Fix with Cubic

- Add your check configuration to the `defaults` properties
- Ensure proper validation rules are defined

5. **Add tests** for your check in `src/checks/__tests__/your-check.test.ts`:
```typescript
import { YourCheck } from '../your-check';

describe('YourCheck', () => {
it('should detect non-compliance', async () => {
// Test non-compliant scenarios
});

it('should pass for compliant repositories', async () => {
// Test compliant scenarios
});

it('should fix issues when not in dry-run mode', async () => {
// Test fix functionality if implemented
});
});
```

6. **Update documentation**:
- Add your check to the "Available Checks" table in this README
- Include configuration examples in the sample YAML

For more details see [DEVELOPMENT.md](./DEVELOPMENT.md).

---
Expand Down
Loading