|
| 1 | +# Add GitHub Copilot Code Review Custom Instructions |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +This PR adds layered custom instructions for GitHub Copilot Code Review, enabling automated, context-aware code reviews based on file paths and domains. |
| 6 | + |
| 7 | +## How It Works |
| 8 | + |
| 9 | +``` |
| 10 | + ┌─────────────────────────────────────┐ |
| 11 | + │ copilot-instructions.md (global) │ |
| 12 | + │ • Review priorities │ |
| 13 | + │ • General principles │ |
| 14 | + │ • Always applies to all files │ |
| 15 | + └──────────────────┬──────────────────┘ |
| 16 | + │ |
| 17 | + ┌────────────────────────────┼────────────────────────────┐ |
| 18 | + │ │ │ |
| 19 | + ▼ ▼ ▼ |
| 20 | +┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐ |
| 21 | +│ nestjs.instructions │ │ security.instructions│ │ testing.instructions│ |
| 22 | +│ ─────────────────── │ │ ─────────────────── │ │ ─────────────────── │ |
| 23 | +│ applyTo: src/**/*.ts│ │ applyTo: src/auth/**│ │ applyTo: **/*.spec.ts│ |
| 24 | +│ │ │ *.guard.ts │ │ **/*.e2e-* │ |
| 25 | +│ • DI patterns │ │ *.strategy │ │ │ |
| 26 | +│ • Thin controllers │ │ │ │ • Test isolation │ |
| 27 | +│ • DTO validation │ │ • OWASP principles │ │ • Cleanup in after │ |
| 28 | +└─────────────────────┘ │ • JWT security │ │ • Edge cases │ |
| 29 | + │ • Input sanitization │ └─────────────────────┘ |
| 30 | + └─────────────────────┘ |
| 31 | + │ |
| 32 | + ▼ |
| 33 | + ┌─────────────────────┐ |
| 34 | + │ database.instructions│ |
| 35 | + │ ─────────────────── │ |
| 36 | + │ applyTo: *.entity.ts│ |
| 37 | + │ *.service │ |
| 38 | + │ │ |
| 39 | + │ • N+1 prevention │ |
| 40 | + │ • Query safety │ |
| 41 | + │ • Transactions │ |
| 42 | + └─────────────────────┘ |
| 43 | +``` |
| 44 | + |
| 45 | +## Layer Combination Examples |
| 46 | + |
| 47 | +| File Changed | Instructions Applied | |
| 48 | +|--------------|---------------------| |
| 49 | +| `src/auth/auth.service.ts` | global + nestjs + security + database | |
| 50 | +| `src/targets/target.entity.ts` | global + nestjs + database | |
| 51 | +| `src/test/users/login.e2e-spec.ts` | global + testing | |
| 52 | +| `src/users/users.controller.ts` | global + nestjs | |
| 53 | + |
| 54 | +## File Structure |
| 55 | + |
| 56 | +``` |
| 57 | +.github/ |
| 58 | +├── copilot-instructions.md # Global rules (all PRs) |
| 59 | +└── instructions/ |
| 60 | + ├── nestjs.instructions.md # NestJS patterns |
| 61 | + ├── security.instructions.md # Auth & OWASP |
| 62 | + ├── database.instructions.md # TypeORM & queries |
| 63 | + └── testing.instructions.md # Test quality |
| 64 | +``` |
| 65 | + |
| 66 | +## Key Design Decisions |
| 67 | + |
| 68 | +- **Short files (<1000 chars each)**: Copilot only reads first 4,000 characters per file |
| 69 | +- **Imperative bullet points**: More effective than narrative paragraphs |
| 70 | +- **Priority system**: CRITICAL / IMPORTANT / SUGGESTION |
| 71 | +- **Code examples**: Show correct vs incorrect patterns |
| 72 | +- **No external links**: Copilot doesn't follow them |
| 73 | + |
| 74 | +## References |
| 75 | + |
| 76 | +- [GitHub Blog: Mastering Instruction Files](https://github.blog/ai-and-ml/unlocking-the-full-power-of-copilot-code-review-master-your-instructions-files/) |
| 77 | +- [Official Tutorial](https://docs.github.com/en/copilot/tutorials/use-custom-instructions) |
| 78 | +- [Community Examples](https://github.com/github/awesome-copilot) |
0 commit comments