How danger/golang works
Main components
a. Command-Line Interface (CLI) – Represented largely by the cmd/danger-go directory (including its main.go, runner components, and internal tests). This is the entry point for user commands (local, pr, ci).
b. API Layer – The api.go, along with its tests (api_test.go, api_internal_test.go), indicates an interface that abstracts Danger functionalities.
c. Danger JS Bridge – The danger-js directory holds types and integration specifics for Danger JS, handling cross-language interactions and type definitions (for commits, GitHub, GitLab, etc.).
d. CI/CD Configuration – The .github directory and the build/ci directory are key for configuring Continuous Integration workflows (with GitHub Actions and potential CI scripts such as dangerfile.go in build/ci).
e. Core Types and Shared Logic – The types.go file and other integral modules that provide the fundamental data structures and shared logic.
Relationships and interactions between components
• The CLI (from cmd/danger-go) accepts user commands which may invoke different behaviors based on the mode (local, pr, or ci).
• The CLI uses the API layer (api.go) to implement its logic. This API, in turn, communicates with Danger JS, leveraging its types and possibly calling underlying Node-based logic if required.
• The Danger JS bridge (under danger-js) provides types and interfaces to align with the existing Danger JS ecosystem. Its role is to “translate” or map the Go logic to Danger JS concepts.
• When integrated into CI (as configured in .github/workflows/main.yml or in build/ci), the CI scripts execute the tool, which then uses its API and Danger JS interface to gather data (e.g., pull request details, commit statistics) and output results accordingly.
• External integrations such as GitHub and GitLab (as seen by the types in danger-js) illustrate that the system can pull metadata for checks.
Architectural patterns and design principles
• Modularization: The logic is clearly separated into different packages (cmd, build/ci, danger-js) to isolate concerns between command execution, CI configuration, and cross-language integration.
• Wrapping and abstraction: The tool provides a wrapper around Danger JS functionality, abstracted behind a Go API.
• Test-driven and CI integrated: Notice the included tests (api_test.go, main_internal_test.go) and CI configurations that ensure the system is robust within automated pipelines.
• Rectangles for executable components.
• Rounded rectangles for configuration components.