Thank you for your interest in contributing to Git Spark. This guide helps you get set up quickly and understand the conventions that keep the codebase consistent.
- Quick Start
- Architecture Overview
- Development Workflow
- Code Conventions
- Adding New Features
- Good First Issues
git clone https://github.com/MarkHazleton/git-spark.git
cd git-spark
npm install
npm run build
npm testRun against the repo itself to see a live report:
node bin/git-spark.js html --days=30 --output=./reportsGit Spark uses a strict three-layer pipeline. Changes must respect layer boundaries:
src/cli/ ← Argument parsing, option validation, user interaction
src/core/ ← Data collection and metric calculation (no I/O)
src/output/ ← Format-specific serialization (HTML, JSON, CSV, MD, Console)
src/utils/ ← Shared utilities (Git commands, logging, validation)
src/types/ ← TypeScript type definitions (no logic)
| File | Purpose |
|---|---|
| src/cli/commands.ts | CLI entry — Commander.js commands and option wiring |
| src/core/collector.ts | Spawns git log to collect raw commit data |
| src/core/analyzer.ts | Calculates all metrics from raw commit data |
| src/output/html.ts | Generates the interactive HTML report |
| src/output/html-utils.ts | HTML escaping and shared rendering helpers |
| src/utils/git.ts | All Git command execution (always via spawn()) |
| src/utils/validation.ts | Input validation for CLI options |
| src/types/index.ts | Central type definitions |
CLI options
↓
Collector (git log → raw commits)
↓
Analyzer (commits → AnalysisReport)
↓
Exporter (AnalysisReport → HTML / JSON / CSV / MD)
npm run prebuild # Generates src/version.ts from package.json (run before anything)
npm run build # TypeScript → dist/
npm test # Jest with ts-jest
npm run test:coverage # With coverage report
npm run lint # ESLintAlways run
npm run prebuildbeforenpm test— version detection depends on it.
Husky runs npm test before every commit. All tests must pass. Coverage thresholds are enforced:
| Metric | Threshold |
|---|---|
| Branches | ≥ 75% |
| Functions | ≥ 87% |
| Lines | ≥ 86% |
| Statements | ≥ 85% |
Follow Conventional Commits:
feat: add branch comparison option
fix: handle empty repository in analyzer
docs: update README quick start section
test: add edge case coverage for file filtering
refactor: extract CSS generation to html-styles module
chore: bump dependencies
ci: upgrade CodeQL to v4
- Strict mode is on: no
anywithout explicit comment, no unused locals - All imports use
.jsextension (ESM bundler resolution mode):import { escapeHtml } from './html-utils.js'; // ✅ import { escapeHtml } from './html-utils'; // ❌
- Use
child_process.spawn()with argument arrays for all Git commands — never template strings.
| Threshold | Action |
|---|---|
| > 500 lines | SHOULD refactor into sub-modules |
| > 1000 lines | MUST refactor before merging |
Every new piece of user-derived content in HTML templates must be escaped:
// ✅ Safe
`<td>${escapeHtml(author.name)}</td>`
// ❌ Unsafe — XSS risk
`<td>${author.name}</td>`When adding inline <script> blocks, update the SHA-256 hash in generateHTML().
Git Spark never claims to measure things it cannot. If you add a metric:
- Verify the data exists in
git logoutput (author, date, files, message only) - Use honest naming:
commitTimePattern≠workingHours - Include a
limitationssection:
limitations: {
dataSource: 'git-commits-only',
estimationMethod: 'commit message pattern analysis',
knownLimitations: ['Cannot detect actual code review participation'],
recommendedApproach: 'Supplement with platform API data (GitHub/GitLab)'
}- Add
.option()insrc/cli/commands.ts - Add field to
GitSparkOptionsinsrc/types/index.ts - Add validation in
src/utils/validation.ts - Wire into
executeAnalysis()insrc/cli/commands.ts - Add test in
test/cli-commands.test.ts
- Define interface addition in
src/types/author.ts - Calculate in
src/core/analyzer.ts→calculateDetailedAuthorMetrics() - Add
limitationsdocumentation - Render in
src/output/html.ts→ Author Profile Cards section (update CSP hash) - Add test with known commit data
- Create
src/output/<format>.tsimplementing anexport(report, outputPath)function - Register in
src/cli/commands.tsformat switch - Export from
src/index.ts - Add test in
test/<format>-exporter.test.ts
Look for issues labeled good first issue on GitHub.
Typical entry points for new contributors:
- Console output improvements (
src/output/console.ts) — less security-sensitive than HTML - Markdown report additions (
src/output/markdown.ts) — straightforward templating - Utility functions (
src/utils/) — isolated, well-tested, low risk - Test coverage — add test cases for edge cases flagged in coverage reports
- Documentation — README improvements, JSDoc additions to public API
Open a GitHub Discussion or file an issue.