-
Notifications
You must be signed in to change notification settings - Fork 0
docs: add instructions for adding new compliance checks in README #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
| // ... existing configs | ||
| your_config_key?: YourCheckConfig; | ||
| } | ||
| ``` | ||
|
|
||
| 4. **Update the JSON Schema** in `compliance-schema.json`: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| - 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). | ||
|
|
||
| --- | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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