|
| 1 | +# Contributing to ghscope |
| 2 | + |
| 3 | +Thanks for wanting to contribute. Here's what you need to know. |
| 4 | + |
| 5 | +## Getting started |
| 6 | + |
| 7 | +```bash |
| 8 | +git clone https://github.com/phlx0/ghscope |
| 9 | +cd ghscope |
| 10 | +go build . # produces ./ghscope |
| 11 | +go test ./... # run tests |
| 12 | +``` |
| 13 | + |
| 14 | +A `GITHUB_TOKEN` with `public_repo` read scope speeds things up a lot — without it you're rate-limited to 60 req/h. Set it in your shell or run `./ghscope setup` after building. |
| 15 | + |
| 16 | +## Project layout |
| 17 | + |
| 18 | +``` |
| 19 | +main.go entry point, cobra commands |
| 20 | +internal/ |
| 21 | + api/ thin GitHub API wrappers, each with disk-cache support |
| 22 | + analysis/ pure computation on top of the API data |
| 23 | + ui/ Bubble Tea model, tab views, setup wizard |
| 24 | + cache/ SHA256-keyed JSON file cache (~/.cache/ghscope) |
| 25 | + config/ ~/.config/ghscope/config.json |
| 26 | + geo/ IP → country resolution for stargazers |
| 27 | +``` |
| 28 | + |
| 29 | +The layering matters: `api` never imports `analysis`, `analysis` never imports `ui`. Keep it that way. |
| 30 | + |
| 31 | +## Adding a new analysis tab |
| 32 | + |
| 33 | +1. Add an API call in `internal/api/` — always cache the response with a sensible TTL. |
| 34 | +2. Compute the stat in `internal/analysis/` — export the type from `types.go`, add the module constant to `ModuleOrder`. |
| 35 | +3. Wire the goroutine in `analysis/run.go` — call `done(ModuleXxx, err)` at the end. |
| 36 | +4. Add `internal/ui/tab_xxx.go` with a `renderXxx(s *analysis.RepoSummary, w, h int) string` function. |
| 37 | +5. Register the tab name in `ui/model.go` and add a `case "Xxx":` in the view switch. |
| 38 | + |
| 39 | +## Style |
| 40 | + |
| 41 | +- No comments except where the *why* isn't obvious from the code |
| 42 | +- Unexported helpers are fine; don't export something just because it might be useful later |
| 43 | +- Tests live next to the code they test (`foo_test.go` in the same package) |
| 44 | +- Commit messages: lowercase imperative, no period — `add trending signal to overview` |
| 45 | + |
| 46 | +## Running the demo locally |
| 47 | + |
| 48 | +Install [VHS](https://github.com/charmbracelet/vhs), then: |
| 49 | + |
| 50 | +```bash |
| 51 | +make demo |
| 52 | +``` |
| 53 | + |
| 54 | +This writes `demo/demo.gif`. |
| 55 | + |
| 56 | +## Pull requests |
| 57 | + |
| 58 | +- Keep PRs focused — one thing at a time |
| 59 | +- If you're adding a new API call, note the approximate call cost in the PR description |
| 60 | +- Existing tests must pass; new analysis code should have at least one test |
| 61 | + |
| 62 | +## Questions |
| 63 | + |
| 64 | +Open a discussion or an issue — both work. |
0 commit comments