|
| 1 | +# Contributing to github-code-search |
| 2 | + |
| 3 | +Thank you for taking the time to contribute! This document describes how to set up a development environment, run tests, and submit changes. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- [Bun](https://bun.sh) ≥ 1.0 |
| 8 | +- A GitHub personal access token with `repo` scope (for integration testing) |
| 9 | + |
| 10 | +## Development setup |
| 11 | + |
| 12 | +```bash |
| 13 | +git clone https://github.com/fulll/github-code-search |
| 14 | +cd github-code-search |
| 15 | +bun install |
| 16 | +``` |
| 17 | + |
| 18 | +## Project structure |
| 19 | + |
| 20 | +``` |
| 21 | +github-code-search.ts # CLI entry point (Commander subcommands: query, upgrade) |
| 22 | +build.ts # Build script (compiles the standalone binary) |
| 23 | +src/ |
| 24 | + types.ts # Shared TypeScript types |
| 25 | + api.ts # GitHub REST API client |
| 26 | + aggregate.ts # Result grouping and filtering logic |
| 27 | + aggregate.test.ts # Unit tests for aggregate.ts |
| 28 | + render.ts # Façade: re-exports sub-modules + TUI renderGroups/renderHelpOverlay |
| 29 | + render.test.ts # Unit tests for render.ts (rows, filter, selection, rendering) |
| 30 | + render/ |
| 31 | + highlight.ts # Syntax highlighting (language detection, token rules, highlightFragment) |
| 32 | + highlight.test.ts # Unit tests for highlight.ts (per-language tokenizer coverage) |
| 33 | + filter.ts # Filter helpers (FilterStats, buildFilterStats) |
| 34 | + rows.ts # Row navigation (buildRows, rowTerminalLines, isCursorVisible) |
| 35 | + summary.ts # Stats labels (buildSummary, buildSummaryFull, buildSelectionSummary) |
| 36 | + selection.ts # Selection mutations (applySelectAll, applySelectNone) |
| 37 | + output.ts # Text (markdown) and JSON output formatters |
| 38 | + output.test.ts # Unit tests for output.ts |
| 39 | + tui.ts # Interactive keyboard-driven UI (navigation, filter mode, help overlay) |
| 40 | + upgrade.ts # Auto-upgrade logic (fetch latest release, replace binary) |
| 41 | + upgrade.test.ts # Unit tests for upgrade.ts |
| 42 | +dist/ # Compiled binary (git-ignored) |
| 43 | +``` |
| 44 | + |
| 45 | +## Running tests |
| 46 | + |
| 47 | +```bash |
| 48 | +bun test |
| 49 | +``` |
| 50 | + |
| 51 | +Tests are co-located with their source files and cover the pure functions in `aggregate.ts`, `output.ts`, `render.ts`, `render/highlight.ts`, and `upgrade.ts`. |
| 52 | + |
| 53 | +## Building a self-contained binary |
| 54 | + |
| 55 | +Build for the current platform: |
| 56 | + |
| 57 | +```bash |
| 58 | +bun run build.ts |
| 59 | +# → produces dist/github-code-search (or dist/github-code-search.exe on Windows) |
| 60 | +``` |
| 61 | + |
| 62 | +Cross-compile for a specific target: |
| 63 | + |
| 64 | +```bash |
| 65 | +bun run build.ts --target=bun-linux-x64 |
| 66 | +bun run build.ts --target=bun-linux-x64-baseline |
| 67 | +bun run build.ts --target=bun-linux-arm64 |
| 68 | +bun run build.ts --target=bun-darwin-x64 |
| 69 | +bun run build.ts --target=bun-darwin-arm64 |
| 70 | +bun run build.ts --target=bun-windows-x64 |
| 71 | +``` |
| 72 | + |
| 73 | +The build script automatically injects the git commit SHA, target OS, and architecture into the binary. Running `github-code-search --version` will show: |
| 74 | + |
| 75 | +``` |
| 76 | +1.2.3 (a1b2c3d · darwin/arm64) |
| 77 | +``` |
| 78 | + |
| 79 | +Compiled binaries require no runtime dependencies and can be distributed as a single file. |
| 80 | + |
| 81 | +## Code style |
| 82 | + |
| 83 | +- TypeScript throughout. |
| 84 | +- Pure functions wherever possible (makes unit testing straightforward). |
| 85 | +- Side-effectful code (CLI parsing, API calls, TTY interaction) is isolated in `github-code-search`, `src/api.ts`, and `src/tui.ts`. |
| 86 | +- No linter is configured yet; keep diffs small and consistent with the surrounding code. |
| 87 | + |
| 88 | +## Submitting a pull request |
| 89 | + |
| 90 | +1. Fork the repository and create a branch: `git checkout -b my-feature`. |
| 91 | +2. Make your changes, add or update tests. |
| 92 | +3. Ensure `bun test` passes. |
| 93 | +4. Open a pull request against `main` with a clear description of the motivation and changes. |
| 94 | + |
| 95 | +## Reporting bugs |
| 96 | + |
| 97 | +Please open an issue and include: |
| 98 | + |
| 99 | +- The exact command you ran (with `GITHUB_TOKEN` redacted). |
| 100 | +- The output you observed vs. what you expected. |
| 101 | +- The full `github-code-search --version` output (contains commit SHA, OS, and architecture). |
| 102 | +- Your Bun version (`bun --version`) if running from source. |
0 commit comments