tech-hub-skills 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/bin/cli.js +241 -0
- package/bin/copilot.js +182 -0
- package/bin/postinstall.js +42 -0
- package/package.json +46 -0
- package/tech_hub_skills/roles/ai-engineer/skills/01-prompt-engineering/README.md +252 -0
- package/tech_hub_skills/roles/ai-engineer/skills/02-rag-pipeline/README.md +448 -0
- package/tech_hub_skills/roles/ai-engineer/skills/03-agent-orchestration/README.md +599 -0
- package/tech_hub_skills/roles/ai-engineer/skills/04-llm-guardrails/README.md +735 -0
- package/tech_hub_skills/roles/ai-engineer/skills/05-vector-embeddings/README.md +711 -0
- package/tech_hub_skills/roles/ai-engineer/skills/06-llm-evaluation/README.md +777 -0
- package/tech_hub_skills/roles/azure/skills/01-infrastructure-fundamentals/README.md +264 -0
- package/tech_hub_skills/roles/azure/skills/02-data-factory/README.md +264 -0
- package/tech_hub_skills/roles/azure/skills/03-synapse-analytics/README.md +264 -0
- package/tech_hub_skills/roles/azure/skills/04-databricks/README.md +264 -0
- package/tech_hub_skills/roles/azure/skills/05-functions/README.md +264 -0
- package/tech_hub_skills/roles/azure/skills/06-kubernetes-service/README.md +264 -0
- package/tech_hub_skills/roles/azure/skills/07-openai-service/README.md +264 -0
- package/tech_hub_skills/roles/azure/skills/08-machine-learning/README.md +264 -0
- package/tech_hub_skills/roles/azure/skills/09-storage-adls/README.md +264 -0
- package/tech_hub_skills/roles/azure/skills/10-networking/README.md +264 -0
- package/tech_hub_skills/roles/azure/skills/11-sql-cosmos/README.md +264 -0
- package/tech_hub_skills/roles/azure/skills/12-event-hubs/README.md +264 -0
- package/tech_hub_skills/roles/code-review/skills/01-automated-code-review/README.md +394 -0
- package/tech_hub_skills/roles/code-review/skills/02-pr-review-workflow/README.md +427 -0
- package/tech_hub_skills/roles/code-review/skills/03-code-quality-gates/README.md +518 -0
- package/tech_hub_skills/roles/code-review/skills/04-reviewer-assignment/README.md +504 -0
- package/tech_hub_skills/roles/code-review/skills/05-review-analytics/README.md +540 -0
- package/tech_hub_skills/roles/data-engineer/skills/01-lakehouse-architecture/README.md +550 -0
- package/tech_hub_skills/roles/data-engineer/skills/02-etl-pipeline/README.md +580 -0
- package/tech_hub_skills/roles/data-engineer/skills/03-data-quality/README.md +579 -0
- package/tech_hub_skills/roles/data-engineer/skills/04-streaming-pipelines/README.md +608 -0
- package/tech_hub_skills/roles/data-engineer/skills/05-performance-optimization/README.md +547 -0
- package/tech_hub_skills/roles/data-governance/skills/01-data-catalog/README.md +112 -0
- package/tech_hub_skills/roles/data-governance/skills/02-data-lineage/README.md +129 -0
- package/tech_hub_skills/roles/data-governance/skills/03-data-quality-framework/README.md +182 -0
- package/tech_hub_skills/roles/data-governance/skills/04-access-control/README.md +39 -0
- package/tech_hub_skills/roles/data-governance/skills/05-master-data-management/README.md +40 -0
- package/tech_hub_skills/roles/data-governance/skills/06-compliance-privacy/README.md +46 -0
- package/tech_hub_skills/roles/data-scientist/skills/01-eda-automation/README.md +230 -0
- package/tech_hub_skills/roles/data-scientist/skills/02-statistical-modeling/README.md +264 -0
- package/tech_hub_skills/roles/data-scientist/skills/03-feature-engineering/README.md +264 -0
- package/tech_hub_skills/roles/data-scientist/skills/04-predictive-modeling/README.md +264 -0
- package/tech_hub_skills/roles/data-scientist/skills/05-customer-analytics/README.md +264 -0
- package/tech_hub_skills/roles/data-scientist/skills/06-campaign-analysis/README.md +264 -0
- package/tech_hub_skills/roles/data-scientist/skills/07-experimentation/README.md +264 -0
- package/tech_hub_skills/roles/data-scientist/skills/08-data-visualization/README.md +264 -0
- package/tech_hub_skills/roles/devops/skills/01-cicd-pipeline/README.md +264 -0
- package/tech_hub_skills/roles/devops/skills/02-container-orchestration/README.md +264 -0
- package/tech_hub_skills/roles/devops/skills/03-infrastructure-as-code/README.md +264 -0
- package/tech_hub_skills/roles/devops/skills/04-gitops/README.md +264 -0
- package/tech_hub_skills/roles/devops/skills/05-environment-management/README.md +264 -0
- package/tech_hub_skills/roles/devops/skills/06-automated-testing/README.md +264 -0
- package/tech_hub_skills/roles/devops/skills/07-release-management/README.md +264 -0
- package/tech_hub_skills/roles/devops/skills/08-monitoring-alerting/README.md +264 -0
- package/tech_hub_skills/roles/devops/skills/09-devsecops/README.md +265 -0
- package/tech_hub_skills/roles/finops/skills/01-cost-visibility/README.md +264 -0
- package/tech_hub_skills/roles/finops/skills/02-resource-tagging/README.md +264 -0
- package/tech_hub_skills/roles/finops/skills/03-budget-management/README.md +264 -0
- package/tech_hub_skills/roles/finops/skills/04-reserved-instances/README.md +264 -0
- package/tech_hub_skills/roles/finops/skills/05-spot-optimization/README.md +264 -0
- package/tech_hub_skills/roles/finops/skills/06-storage-tiering/README.md +264 -0
- package/tech_hub_skills/roles/finops/skills/07-compute-rightsizing/README.md +264 -0
- package/tech_hub_skills/roles/finops/skills/08-chargeback/README.md +264 -0
- package/tech_hub_skills/roles/ml-engineer/skills/01-mlops-pipeline/README.md +566 -0
- package/tech_hub_skills/roles/ml-engineer/skills/02-feature-engineering/README.md +655 -0
- package/tech_hub_skills/roles/ml-engineer/skills/03-model-training/README.md +704 -0
- package/tech_hub_skills/roles/ml-engineer/skills/04-model-serving/README.md +845 -0
- package/tech_hub_skills/roles/ml-engineer/skills/05-model-monitoring/README.md +874 -0
- package/tech_hub_skills/roles/mlops/skills/01-ml-pipeline-orchestration/README.md +264 -0
- package/tech_hub_skills/roles/mlops/skills/02-experiment-tracking/README.md +264 -0
- package/tech_hub_skills/roles/mlops/skills/03-model-registry/README.md +264 -0
- package/tech_hub_skills/roles/mlops/skills/04-feature-store/README.md +264 -0
- package/tech_hub_skills/roles/mlops/skills/05-model-deployment/README.md +264 -0
- package/tech_hub_skills/roles/mlops/skills/06-model-observability/README.md +264 -0
- package/tech_hub_skills/roles/mlops/skills/07-data-versioning/README.md +264 -0
- package/tech_hub_skills/roles/mlops/skills/08-ab-testing/README.md +264 -0
- package/tech_hub_skills/roles/mlops/skills/09-automated-retraining/README.md +264 -0
- package/tech_hub_skills/roles/platform-engineer/skills/01-internal-developer-platform/README.md +153 -0
- package/tech_hub_skills/roles/platform-engineer/skills/02-self-service-infrastructure/README.md +57 -0
- package/tech_hub_skills/roles/platform-engineer/skills/03-slo-sli-management/README.md +59 -0
- package/tech_hub_skills/roles/platform-engineer/skills/04-developer-experience/README.md +57 -0
- package/tech_hub_skills/roles/platform-engineer/skills/05-incident-management/README.md +73 -0
- package/tech_hub_skills/roles/platform-engineer/skills/06-capacity-management/README.md +59 -0
- package/tech_hub_skills/roles/product-designer/skills/01-requirements-discovery/README.md +407 -0
- package/tech_hub_skills/roles/product-designer/skills/02-user-research/README.md +382 -0
- package/tech_hub_skills/roles/product-designer/skills/03-brainstorming-ideation/README.md +437 -0
- package/tech_hub_skills/roles/product-designer/skills/04-ux-design/README.md +496 -0
- package/tech_hub_skills/roles/product-designer/skills/05-product-market-fit/README.md +376 -0
- package/tech_hub_skills/roles/product-designer/skills/06-stakeholder-management/README.md +412 -0
- package/tech_hub_skills/roles/security-architect/skills/01-pii-detection/README.md +319 -0
- package/tech_hub_skills/roles/security-architect/skills/02-threat-modeling/README.md +264 -0
- package/tech_hub_skills/roles/security-architect/skills/03-infrastructure-security/README.md +264 -0
- package/tech_hub_skills/roles/security-architect/skills/04-iam/README.md +264 -0
- package/tech_hub_skills/roles/security-architect/skills/05-application-security/README.md +264 -0
- package/tech_hub_skills/roles/security-architect/skills/06-secrets-management/README.md +264 -0
- package/tech_hub_skills/roles/security-architect/skills/07-security-monitoring/README.md +264 -0
- package/tech_hub_skills/roles/system-design/skills/01-architecture-patterns/README.md +337 -0
- package/tech_hub_skills/roles/system-design/skills/02-requirements-engineering/README.md +264 -0
- package/tech_hub_skills/roles/system-design/skills/03-scalability/README.md +264 -0
- package/tech_hub_skills/roles/system-design/skills/04-high-availability/README.md +264 -0
- package/tech_hub_skills/roles/system-design/skills/05-cost-optimization-design/README.md +264 -0
- package/tech_hub_skills/roles/system-design/skills/06-api-design/README.md +264 -0
- package/tech_hub_skills/roles/system-design/skills/07-observability-architecture/README.md +264 -0
- package/tech_hub_skills/roles/system-design/skills/08-process-automation/PROCESS_TEMPLATE.md +336 -0
- package/tech_hub_skills/roles/system-design/skills/08-process-automation/README.md +521 -0
- package/tech_hub_skills/skills/README.md +336 -0
- package/tech_hub_skills/skills/ai-engineer.md +104 -0
- package/tech_hub_skills/skills/azure.md +149 -0
- package/tech_hub_skills/skills/code-review.md +399 -0
- package/tech_hub_skills/skills/compliance-automation.md +747 -0
- package/tech_hub_skills/skills/data-engineer.md +113 -0
- package/tech_hub_skills/skills/data-governance.md +102 -0
- package/tech_hub_skills/skills/data-scientist.md +123 -0
- package/tech_hub_skills/skills/devops.md +160 -0
- package/tech_hub_skills/skills/docker.md +160 -0
- package/tech_hub_skills/skills/enterprise-dashboard.md +613 -0
- package/tech_hub_skills/skills/finops.md +184 -0
- package/tech_hub_skills/skills/ml-engineer.md +115 -0
- package/tech_hub_skills/skills/mlops.md +187 -0
- package/tech_hub_skills/skills/optimization-advisor.md +329 -0
- package/tech_hub_skills/skills/orchestrator.md +497 -0
- package/tech_hub_skills/skills/platform-engineer.md +102 -0
- package/tech_hub_skills/skills/process-automation.md +226 -0
- package/tech_hub_skills/skills/process-changelog.md +184 -0
- package/tech_hub_skills/skills/process-documentation.md +484 -0
- package/tech_hub_skills/skills/process-kanban.md +324 -0
- package/tech_hub_skills/skills/process-versioning.md +214 -0
- package/tech_hub_skills/skills/product-designer.md +104 -0
- package/tech_hub_skills/skills/project-starter.md +443 -0
- package/tech_hub_skills/skills/security-architect.md +135 -0
- package/tech_hub_skills/skills/system-design.md +126 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
# cr-01: Automated Code Review
|
|
2
|
+
|
|
3
|
+
AI-powered automated code analysis for consistent quality enforcement.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Automated code review integrates static analysis, security scanning, and AI-powered suggestions to catch issues before human review. This reduces review burden and ensures consistent quality standards.
|
|
8
|
+
|
|
9
|
+
## Capabilities
|
|
10
|
+
|
|
11
|
+
### Static Analysis
|
|
12
|
+
- **Linting**: ESLint, Pylint, RuboCop, golangci-lint
|
|
13
|
+
- **Formatting**: Prettier, Black, gofmt
|
|
14
|
+
- **Type checking**: TypeScript, mypy, Pyright
|
|
15
|
+
- **Complexity**: Cyclomatic, cognitive complexity metrics
|
|
16
|
+
|
|
17
|
+
### Security Scanning
|
|
18
|
+
- **SAST**: SonarQube, Semgrep, CodeQL
|
|
19
|
+
- **Dependency scanning**: Snyk, Dependabot, npm audit
|
|
20
|
+
- **Secret detection**: GitLeaks, TruffleHog
|
|
21
|
+
- **Container scanning**: Trivy, Grype
|
|
22
|
+
|
|
23
|
+
### AI-Powered Analysis
|
|
24
|
+
- Code suggestions and improvements
|
|
25
|
+
- Bug prediction and detection
|
|
26
|
+
- Performance anti-pattern identification
|
|
27
|
+
- Documentation gap detection
|
|
28
|
+
|
|
29
|
+
## Implementation
|
|
30
|
+
|
|
31
|
+
### GitHub Actions Workflow
|
|
32
|
+
|
|
33
|
+
```yaml
|
|
34
|
+
name: Automated Code Review
|
|
35
|
+
on:
|
|
36
|
+
pull_request:
|
|
37
|
+
types: [opened, synchronize, reopened]
|
|
38
|
+
|
|
39
|
+
permissions:
|
|
40
|
+
contents: read
|
|
41
|
+
pull-requests: write
|
|
42
|
+
security-events: write
|
|
43
|
+
|
|
44
|
+
jobs:
|
|
45
|
+
lint:
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
steps:
|
|
48
|
+
- uses: actions/checkout@v4
|
|
49
|
+
|
|
50
|
+
- name: Setup Node.js
|
|
51
|
+
uses: actions/setup-node@v4
|
|
52
|
+
with:
|
|
53
|
+
node-version: '20'
|
|
54
|
+
cache: 'npm'
|
|
55
|
+
|
|
56
|
+
- name: Install dependencies
|
|
57
|
+
run: npm ci
|
|
58
|
+
|
|
59
|
+
- name: Run ESLint
|
|
60
|
+
run: |
|
|
61
|
+
npx eslint . --format=json --output-file=eslint-report.json || true
|
|
62
|
+
|
|
63
|
+
- name: Annotate PR with ESLint results
|
|
64
|
+
uses: ataylorme/eslint-annotate-action@v2
|
|
65
|
+
with:
|
|
66
|
+
report-json: "eslint-report.json"
|
|
67
|
+
|
|
68
|
+
security:
|
|
69
|
+
runs-on: ubuntu-latest
|
|
70
|
+
steps:
|
|
71
|
+
- uses: actions/checkout@v4
|
|
72
|
+
|
|
73
|
+
- name: Run Semgrep
|
|
74
|
+
uses: returntocorp/semgrep-action@v1
|
|
75
|
+
with:
|
|
76
|
+
config: p/security-audit p/secrets
|
|
77
|
+
|
|
78
|
+
- name: Run Snyk
|
|
79
|
+
uses: snyk/actions/node@master
|
|
80
|
+
continue-on-error: true
|
|
81
|
+
env:
|
|
82
|
+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
|
83
|
+
|
|
84
|
+
- name: Upload SARIF
|
|
85
|
+
uses: github/codeql-action/upload-sarif@v2
|
|
86
|
+
with:
|
|
87
|
+
sarif_file: snyk.sarif
|
|
88
|
+
|
|
89
|
+
complexity:
|
|
90
|
+
runs-on: ubuntu-latest
|
|
91
|
+
steps:
|
|
92
|
+
- uses: actions/checkout@v4
|
|
93
|
+
|
|
94
|
+
- name: Check complexity
|
|
95
|
+
run: |
|
|
96
|
+
npx complexity-report --format json --output complexity.json src/
|
|
97
|
+
|
|
98
|
+
- name: Comment complexity report
|
|
99
|
+
uses: actions/github-script@v7
|
|
100
|
+
with:
|
|
101
|
+
script: |
|
|
102
|
+
const fs = require('fs');
|
|
103
|
+
const report = JSON.parse(fs.readFileSync('complexity.json'));
|
|
104
|
+
const high = report.filter(f => f.complexity > 15);
|
|
105
|
+
if (high.length > 0) {
|
|
106
|
+
const body = '## Complexity Warning\n\n' +
|
|
107
|
+
high.map(f => `- \`${f.file}\`: ${f.complexity}`).join('\n');
|
|
108
|
+
github.rest.issues.createComment({
|
|
109
|
+
issue_number: context.issue.number,
|
|
110
|
+
owner: context.repo.owner,
|
|
111
|
+
repo: context.repo.repo,
|
|
112
|
+
body
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Azure DevOps Pipeline
|
|
118
|
+
|
|
119
|
+
```yaml
|
|
120
|
+
trigger: none
|
|
121
|
+
pr:
|
|
122
|
+
branches:
|
|
123
|
+
include:
|
|
124
|
+
- main
|
|
125
|
+
- develop
|
|
126
|
+
|
|
127
|
+
pool:
|
|
128
|
+
vmImage: 'ubuntu-latest'
|
|
129
|
+
|
|
130
|
+
stages:
|
|
131
|
+
- stage: AutomatedReview
|
|
132
|
+
displayName: 'Automated Code Review'
|
|
133
|
+
jobs:
|
|
134
|
+
- job: StaticAnalysis
|
|
135
|
+
displayName: 'Static Analysis'
|
|
136
|
+
steps:
|
|
137
|
+
- task: NodeTool@0
|
|
138
|
+
inputs:
|
|
139
|
+
versionSpec: '20.x'
|
|
140
|
+
|
|
141
|
+
- script: npm ci
|
|
142
|
+
displayName: 'Install dependencies'
|
|
143
|
+
|
|
144
|
+
- script: |
|
|
145
|
+
npx eslint . --format stylish --output-file $(Build.ArtifactStagingDirectory)/eslint.txt
|
|
146
|
+
displayName: 'Run ESLint'
|
|
147
|
+
continueOnError: true
|
|
148
|
+
|
|
149
|
+
- task: PublishBuildArtifacts@1
|
|
150
|
+
inputs:
|
|
151
|
+
pathToPublish: '$(Build.ArtifactStagingDirectory)'
|
|
152
|
+
artifactName: 'code-review'
|
|
153
|
+
|
|
154
|
+
- job: SecurityScan
|
|
155
|
+
displayName: 'Security Scanning'
|
|
156
|
+
steps:
|
|
157
|
+
- task: SonarQubePrepare@5
|
|
158
|
+
inputs:
|
|
159
|
+
SonarQube: 'SonarQube-Connection'
|
|
160
|
+
scannerMode: 'CLI'
|
|
161
|
+
configMode: 'manual'
|
|
162
|
+
cliProjectKey: '$(Build.Repository.Name)'
|
|
163
|
+
|
|
164
|
+
- task: SonarQubeAnalyze@5
|
|
165
|
+
|
|
166
|
+
- task: SonarQubePublish@5
|
|
167
|
+
inputs:
|
|
168
|
+
pollingTimeoutSec: '300'
|
|
169
|
+
|
|
170
|
+
- task: sonar-buildbreaker@8
|
|
171
|
+
inputs:
|
|
172
|
+
SonarQube: 'SonarQube-Connection'
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Python Analysis Script
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
#!/usr/bin/env python3
|
|
179
|
+
"""Automated code review analyzer."""
|
|
180
|
+
|
|
181
|
+
import json
|
|
182
|
+
import subprocess
|
|
183
|
+
from dataclasses import dataclass
|
|
184
|
+
from pathlib import Path
|
|
185
|
+
from typing import List, Dict, Any
|
|
186
|
+
|
|
187
|
+
@dataclass
|
|
188
|
+
class ReviewFinding:
|
|
189
|
+
"""Represents a code review finding."""
|
|
190
|
+
file: str
|
|
191
|
+
line: int
|
|
192
|
+
severity: str # critical, high, medium, low, info
|
|
193
|
+
category: str # security, quality, performance, style
|
|
194
|
+
message: str
|
|
195
|
+
rule: str
|
|
196
|
+
suggestion: str = ""
|
|
197
|
+
|
|
198
|
+
class AutomatedReviewer:
|
|
199
|
+
"""Enterprise automated code reviewer."""
|
|
200
|
+
|
|
201
|
+
def __init__(self, project_path: str = "."):
|
|
202
|
+
self.project_path = Path(project_path)
|
|
203
|
+
self.findings: List[ReviewFinding] = []
|
|
204
|
+
|
|
205
|
+
def run_eslint(self) -> List[ReviewFinding]:
|
|
206
|
+
"""Run ESLint for JavaScript/TypeScript."""
|
|
207
|
+
result = subprocess.run(
|
|
208
|
+
["npx", "eslint", ".", "--format=json"],
|
|
209
|
+
capture_output=True,
|
|
210
|
+
text=True,
|
|
211
|
+
cwd=self.project_path
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
findings = []
|
|
215
|
+
if result.stdout:
|
|
216
|
+
data = json.loads(result.stdout)
|
|
217
|
+
for file_result in data:
|
|
218
|
+
for msg in file_result.get("messages", []):
|
|
219
|
+
findings.append(ReviewFinding(
|
|
220
|
+
file=file_result["filePath"],
|
|
221
|
+
line=msg.get("line", 0),
|
|
222
|
+
severity=self._map_severity(msg.get("severity", 1)),
|
|
223
|
+
category="style" if "style" in msg.get("ruleId", "") else "quality",
|
|
224
|
+
message=msg.get("message", ""),
|
|
225
|
+
rule=msg.get("ruleId", ""),
|
|
226
|
+
suggestion=msg.get("fix", {}).get("text", "") if msg.get("fix") else ""
|
|
227
|
+
))
|
|
228
|
+
return findings
|
|
229
|
+
|
|
230
|
+
def run_semgrep(self) -> List[ReviewFinding]:
|
|
231
|
+
"""Run Semgrep for security analysis."""
|
|
232
|
+
result = subprocess.run(
|
|
233
|
+
["semgrep", "--config=auto", "--json", "."],
|
|
234
|
+
capture_output=True,
|
|
235
|
+
text=True,
|
|
236
|
+
cwd=self.project_path
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
findings = []
|
|
240
|
+
if result.stdout:
|
|
241
|
+
data = json.loads(result.stdout)
|
|
242
|
+
for finding in data.get("results", []):
|
|
243
|
+
findings.append(ReviewFinding(
|
|
244
|
+
file=finding["path"],
|
|
245
|
+
line=finding["start"]["line"],
|
|
246
|
+
severity=finding.get("extra", {}).get("severity", "medium"),
|
|
247
|
+
category="security",
|
|
248
|
+
message=finding["extra"].get("message", ""),
|
|
249
|
+
rule=finding["check_id"],
|
|
250
|
+
suggestion=finding.get("extra", {}).get("fix", "")
|
|
251
|
+
))
|
|
252
|
+
return findings
|
|
253
|
+
|
|
254
|
+
def run_complexity_check(self) -> List[ReviewFinding]:
|
|
255
|
+
"""Check code complexity."""
|
|
256
|
+
# Implementation depends on language
|
|
257
|
+
# This is a placeholder for complexity analysis
|
|
258
|
+
return []
|
|
259
|
+
|
|
260
|
+
def _map_severity(self, eslint_severity: int) -> str:
|
|
261
|
+
"""Map ESLint severity to standard levels."""
|
|
262
|
+
return {1: "low", 2: "medium"}.get(eslint_severity, "info")
|
|
263
|
+
|
|
264
|
+
def run_all_checks(self) -> Dict[str, Any]:
|
|
265
|
+
"""Run all automated checks."""
|
|
266
|
+
self.findings.extend(self.run_eslint())
|
|
267
|
+
self.findings.extend(self.run_semgrep())
|
|
268
|
+
self.findings.extend(self.run_complexity_check())
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
"total_findings": len(self.findings),
|
|
272
|
+
"by_severity": self._count_by_severity(),
|
|
273
|
+
"by_category": self._count_by_category(),
|
|
274
|
+
"blocking": self._get_blocking_issues(),
|
|
275
|
+
"findings": [f.__dict__ for f in self.findings]
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
def _count_by_severity(self) -> Dict[str, int]:
|
|
279
|
+
"""Count findings by severity."""
|
|
280
|
+
counts = {"critical": 0, "high": 0, "medium": 0, "low": 0, "info": 0}
|
|
281
|
+
for f in self.findings:
|
|
282
|
+
counts[f.severity] = counts.get(f.severity, 0) + 1
|
|
283
|
+
return counts
|
|
284
|
+
|
|
285
|
+
def _count_by_category(self) -> Dict[str, int]:
|
|
286
|
+
"""Count findings by category."""
|
|
287
|
+
counts = {}
|
|
288
|
+
for f in self.findings:
|
|
289
|
+
counts[f.category] = counts.get(f.category, 0) + 1
|
|
290
|
+
return counts
|
|
291
|
+
|
|
292
|
+
def _get_blocking_issues(self) -> List[Dict]:
|
|
293
|
+
"""Get issues that should block merge."""
|
|
294
|
+
blocking = [f for f in self.findings
|
|
295
|
+
if f.severity in ("critical", "high") or f.category == "security"]
|
|
296
|
+
return [f.__dict__ for f in blocking]
|
|
297
|
+
|
|
298
|
+
def generate_pr_comment(self) -> str:
|
|
299
|
+
"""Generate a PR comment with findings."""
|
|
300
|
+
counts = self._count_by_severity()
|
|
301
|
+
blocking = self._get_blocking_issues()
|
|
302
|
+
|
|
303
|
+
comment = "## Automated Code Review Results\n\n"
|
|
304
|
+
|
|
305
|
+
if blocking:
|
|
306
|
+
comment += "### Blocking Issues\n"
|
|
307
|
+
for issue in blocking[:10]: # Limit to 10
|
|
308
|
+
comment += f"- **{issue['severity'].upper()}** [{issue['rule']}] "
|
|
309
|
+
comment += f"`{issue['file']}:{issue['line']}` - {issue['message']}\n"
|
|
310
|
+
comment += "\n"
|
|
311
|
+
|
|
312
|
+
comment += "### Summary\n"
|
|
313
|
+
comment += f"- Critical: {counts['critical']}\n"
|
|
314
|
+
comment += f"- High: {counts['high']}\n"
|
|
315
|
+
comment += f"- Medium: {counts['medium']}\n"
|
|
316
|
+
comment += f"- Low: {counts['low']}\n"
|
|
317
|
+
|
|
318
|
+
if not blocking:
|
|
319
|
+
comment += "\n All automated checks passed.\n"
|
|
320
|
+
else:
|
|
321
|
+
comment += "\n Please address blocking issues before merge.\n"
|
|
322
|
+
|
|
323
|
+
return comment
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
if __name__ == "__main__":
|
|
327
|
+
reviewer = AutomatedReviewer()
|
|
328
|
+
results = reviewer.run_all_checks()
|
|
329
|
+
print(json.dumps(results, indent=2))
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Configuration
|
|
333
|
+
|
|
334
|
+
### ESLint Configuration (.eslintrc.json)
|
|
335
|
+
```json
|
|
336
|
+
{
|
|
337
|
+
"extends": [
|
|
338
|
+
"eslint:recommended",
|
|
339
|
+
"plugin:@typescript-eslint/recommended",
|
|
340
|
+
"plugin:security/recommended"
|
|
341
|
+
],
|
|
342
|
+
"plugins": ["security", "@typescript-eslint"],
|
|
343
|
+
"rules": {
|
|
344
|
+
"complexity": ["error", 15],
|
|
345
|
+
"max-depth": ["error", 4],
|
|
346
|
+
"max-lines-per-function": ["error", 100],
|
|
347
|
+
"no-eval": "error",
|
|
348
|
+
"security/detect-eval-with-expression": "error",
|
|
349
|
+
"security/detect-non-literal-regexp": "warn"
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Semgrep Configuration (.semgrep.yml)
|
|
355
|
+
```yaml
|
|
356
|
+
rules:
|
|
357
|
+
- id: hardcoded-secret
|
|
358
|
+
patterns:
|
|
359
|
+
- pattern-regex: (password|secret|key|token)\s*=\s*["'][^"']+["']
|
|
360
|
+
message: "Potential hardcoded secret detected"
|
|
361
|
+
severity: ERROR
|
|
362
|
+
languages: [python, javascript, typescript]
|
|
363
|
+
|
|
364
|
+
- id: sql-injection
|
|
365
|
+
patterns:
|
|
366
|
+
- pattern: $QUERY = "..." + $INPUT + "..."
|
|
367
|
+
- pattern: f"SELECT ... {$INPUT} ..."
|
|
368
|
+
message: "Potential SQL injection vulnerability"
|
|
369
|
+
severity: ERROR
|
|
370
|
+
languages: [python, javascript]
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## Metrics
|
|
374
|
+
|
|
375
|
+
| Metric | Target | Description |
|
|
376
|
+
|--------|--------|-------------|
|
|
377
|
+
| False positive rate | < 10% | Minimize noise |
|
|
378
|
+
| Detection rate | > 90% | Catch real issues |
|
|
379
|
+
| Scan time | < 5 min | Fast feedback |
|
|
380
|
+
| Coverage | 100% changed files | Review all changes |
|
|
381
|
+
|
|
382
|
+
## Connections
|
|
383
|
+
|
|
384
|
+
- **Inputs from**: Developer push, PR creation
|
|
385
|
+
- **Outputs to**: PR comments, quality gates (cr-03)
|
|
386
|
+
- **Integrates with**: Security Architect (sa-05), DevOps (do-09)
|
|
387
|
+
|
|
388
|
+
## Best Practices
|
|
389
|
+
|
|
390
|
+
1. Run automated checks on every push, not just PRs
|
|
391
|
+
2. Fix tool configuration issues quickly to maintain trust
|
|
392
|
+
3. Suppress false positives with inline comments, not config
|
|
393
|
+
4. Review and update rules quarterly
|
|
394
|
+
5. Track false positive rate and tune accordingly
|