|
| 1 | +# Agent Context: GitHub Copier |
| 2 | + |
| 3 | +Webhook service: PR merged → match files → transform paths → copy to target repos. |
| 4 | + |
| 5 | +## File Map |
| 6 | + |
| 7 | +``` |
| 8 | +app.go # entrypoint, HTTP server |
| 9 | +services/ |
| 10 | + webhook_handler_new.go # HandleWebhookWithContainer() |
| 11 | + workflow_processor.go # ProcessWorkflow() - core logic |
| 12 | + pattern_matcher.go # MatchFile(pattern, path) bool |
| 13 | + github_auth.go # ConfigurePermissions() error |
| 14 | + github_read.go # GetFilesChangedInPr(), RetrieveFileContents() |
| 15 | + github_write_to_target.go # AddFilesToTargetRepoBranch() |
| 16 | + github_write_to_source.go # UpdateDeprecationFile() |
| 17 | + file_state_service.go # tracks upload/deprecate queues |
| 18 | + main_config_loader.go # LoadConfig() with $ref support |
| 19 | + service_container.go # DI container |
| 20 | +types/ |
| 21 | + config.go # Workflow, Transformation, SourcePattern structs |
| 22 | + types.go # ChangedFile, UploadKey, UploadFileContent |
| 23 | +configs/environment.go # Config struct, LoadEnvironment() |
| 24 | +tests/utils.go # test helpers, httpmock setup |
| 25 | +``` |
| 26 | + |
| 27 | +## Key Types |
| 28 | + |
| 29 | +```go |
| 30 | +// types/config.go |
| 31 | +type PatternType string // "prefix" | "glob" | "regex" |
| 32 | +type TransformationType string // "move" | "copy" | "glob" | "regex" |
| 33 | + |
| 34 | +type Workflow struct { |
| 35 | + Name string |
| 36 | + Source SourceConfig // Repo, Branch, Patterns []SourcePattern |
| 37 | + Destination DestinationConfig // Repo, Branch |
| 38 | + Transformations []Transformation // Type, From, To, Pattern, Replacement |
| 39 | + Commit CommitConfig // Strategy, Message, PRTitle, AutoMerge |
| 40 | +} |
| 41 | + |
| 42 | +// types/types.go |
| 43 | +type ChangedFile struct { Path, Status string } // Status: "ADDED"|"MODIFIED"|"DELETED" |
| 44 | +type UploadKey struct { RepoName, BranchPath string } |
| 45 | +``` |
| 46 | + |
| 47 | +## Global State (⚠️ mutable) |
| 48 | + |
| 49 | +```go |
| 50 | +// services/github_write_to_target.go |
| 51 | +var FilesToUpload map[UploadKey]UploadFileContent |
| 52 | +// services/github_auth.go |
| 53 | +var InstallationAccessToken string |
| 54 | +var OrgTokens map[string]string |
| 55 | +``` |
| 56 | + |
| 57 | +## Config Example |
| 58 | + |
| 59 | +```yaml |
| 60 | +workflows: |
| 61 | + - name: "sync-docs" |
| 62 | + source: { repo: "org/src", branch: "main", patterns: [{type: glob, pattern: "docs/**"}] } |
| 63 | + destination: { repo: "org/dest", branch: "main" } |
| 64 | + transformations: [{ type: move, from: "docs/", to: "public/" }] |
| 65 | + commit: { strategy: pr, message: "Sync" } # strategy: direct|pr |
| 66 | +``` |
| 67 | +
|
| 68 | +## Test Commands |
| 69 | +
|
| 70 | +```bash |
| 71 | +go test ./... # all |
| 72 | +go test ./services/... -run TestWorkflow -v # specific |
| 73 | +``` |
| 74 | + |
| 75 | +## Edit Patterns |
| 76 | + |
| 77 | +| Task | Files to modify | |
| 78 | +|------|-----------------| |
| 79 | +| New transformation | `types/config.go` (TransformationType) → `workflow_processor.go` (processFileForWorkflow) | |
| 80 | +| New pattern type | `types/config.go` (PatternType) → `pattern_matcher.go` | |
| 81 | +| New config field | `types/config.go` (struct) → consumers in `workflow_processor.go` | |
| 82 | +| Webhook logic | `webhook_handler_new.go` | |
| 83 | + |
| 84 | +## Conventions |
| 85 | + |
| 86 | +- Return `error`, never `log.Fatal` |
| 87 | +- Wrap errors: `fmt.Errorf("context: %w", err)` |
| 88 | +- Nil-check GitHub API responses before dereference |
| 89 | +- Tests use `httpmock`; see `tests/utils.go` |
| 90 | +- **Changelog**: Update `CHANGELOG.md` for all notable changes (follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)) |
0 commit comments