|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is **danger-go**, a Go implementation of the popular Danger tool that runs automation rules during PR reviews. It's a wrapper around Danger JS that allows writing Dangerfiles in Go instead of JavaScript. |
| 8 | + |
| 9 | +The project consists of: |
| 10 | + |
| 11 | +- A Go library for writing Danger rules (`api.go`, `types.go`) |
| 12 | +- A command-line tool (`cmd/danger-go/`) that wraps Danger JS |
| 13 | +- Type definitions for various platforms (GitHub, GitLab) in `danger-js/` directory |
| 14 | +- Platform-specific types in separate files (`types_*.go`) |
| 15 | + |
| 16 | +## Architecture |
| 17 | + |
| 18 | +### Core Components |
| 19 | + |
| 20 | +1. **API Layer** (`api.go`): Main public API with the `T` struct providing methods: |
| 21 | + - `Message()` - Add informational messages |
| 22 | + - `Warn()` - Add warnings that don't fail the build |
| 23 | + - `Fail()` - Add failures that fail the build |
| 24 | + - `Markdown()` - Add raw markdown to comments |
| 25 | + |
| 26 | +2. **Types** (`types.go`): Core data structures like `Results`, `Violation`, `GitHubResults` |
| 27 | + |
| 28 | +3. **Danger JS Bridge** (`danger-js/`): Integration layer that: |
| 29 | + - Calls the `danger` (JS) binary to get DSL data |
| 30 | + - Processes commands (`ci`, `local`, `pr`) by wrapping Danger JS |
| 31 | + - Contains platform-specific type definitions |
| 32 | + |
| 33 | +4. **CLI Tool** (`cmd/danger-go/`): Command-line interface supporting: |
| 34 | + - `ci` - Run on CI/CD |
| 35 | + - `local` - Run locally for git hooks |
| 36 | + - `pr` - Test against existing GitHub PR |
| 37 | + - `runner` - Internal command for processing DSL via STDIN |
| 38 | + |
| 39 | +## Development Commands |
| 40 | + |
| 41 | +### Building and Testing |
| 42 | + |
| 43 | +```bash |
| 44 | +# Run tests |
| 45 | +go test -v ./... |
| 46 | + |
| 47 | +# Build the CLI tool |
| 48 | +go build -o danger-go cmd/danger-go/main.go |
| 49 | + |
| 50 | +# Install the CLI tool globally |
| 51 | +go install github.com/danger/golang/cmd/danger-go@latest |
| 52 | +``` |
| 53 | + |
| 54 | +### Running Danger Locally |
| 55 | + |
| 56 | +```bash |
| 57 | +# Install dependencies first |
| 58 | +npm install -g danger |
| 59 | +go install github.com/danger/golang/cmd/danger-go@latest |
| 60 | + |
| 61 | +# Run danger in CI mode (from build/ci directory) |
| 62 | +cd build/ci && danger-go ci |
| 63 | + |
| 64 | +# Run locally for testing |
| 65 | +danger-go local |
| 66 | + |
| 67 | +# Test against a specific PR |
| 68 | +danger-go pr https://github.com/owner/repo/pull/123 |
| 69 | +``` |
| 70 | + |
| 71 | +### Development Workflow |
| 72 | + |
| 73 | +The project follows standard Go conventions: |
| 74 | + |
| 75 | +- Use `go fmt` for formatting |
| 76 | +- Run `go vet` for static analysis |
| 77 | +- Follow [Effective Go](https://go.dev/doc/effective_go) guidelines |
| 78 | +- Write table-driven tests where appropriate |
| 79 | +- Use conventional commit messages |
| 80 | + |
| 81 | +## Dangerfile Structure |
| 82 | + |
| 83 | +Dangerfiles are Go programs that must: |
| 84 | + |
| 85 | +1. Be in a separate directory (e.g., `build/ci/`) |
| 86 | +2. Have a `Run(d *danger.T, pr danger.DSL)` function |
| 87 | +3. Import `github.com/danger/golang` |
| 88 | +4. Have their own go.mod file |
| 89 | + |
| 90 | +Example Dangerfile setup: |
| 91 | + |
| 92 | +```bash |
| 93 | +mkdir build/ci |
| 94 | +cd build/ci |
| 95 | +go mod init dangerfile |
| 96 | +go get github.com/danger/golang |
| 97 | +``` |
| 98 | + |
| 99 | +## Key Dependencies |
| 100 | + |
| 101 | +- **Go 1.24+** required |
| 102 | +- **Danger JS** must be installed globally (`npm install -g danger`) |
| 103 | +- **github.com/stretchr/testify** for testing |
| 104 | + |
| 105 | +## CI/CD Integration |
| 106 | + |
| 107 | +The project uses GitHub Actions (`.github/workflows/test.yml`) which: |
| 108 | + |
| 109 | +- Installs Go 1.24+ |
| 110 | +- Installs Node.js and Danger JS |
| 111 | +- Runs both Go tests and danger-go CI checks |
| 112 | +- Requires `GITHUB_TOKEN` for GitHub API access |
| 113 | + |
| 114 | +## Testing |
| 115 | + |
| 116 | +- Use `go test -v ./...` to run all tests |
| 117 | +- Tests are in `*_test.go` files |
| 118 | +- Internal tests in `api_internal_test.go` test unexported functions |
| 119 | +- Follow table-driven test patterns where applicable |
0 commit comments