How electron/cation works
Project Type and Purpose
• This is a Node.js/TypeScript GitHub App (bot) that listens to GitHub events (pull requests and issue comments) and enforces four PR‐governance rules:
• Semantic version labeling
• Minimum PR open time enforcement
• API review state management
• Deprecation‐review checklist enforcement
• It runs as a GitHub App (see app.json) and is tested with Vitest in the spec/ folder.
High‐Level File Structure and Architectural Patterns
• src/ – entry point (index.ts) plus four rule modules (24-hour-rule.ts, add-triage-labels.ts, api-review-state.ts, deprecation-review-state.ts, enforce-semver-labels.ts) and shared utility code (utils/, constants.ts, enums.ts).
• spec/ – unit tests and fixtures for each rule module.
• .github/workflows/ – CI pipelines for linting and testing.
• app.json – GitHub App manifest.
• No database: all state is managed via GitHub labels, checks, and comments.
Main Components and Their Interactions
a. GitHub (External Service)
• Generates webhook events: pull_request.opened, pull_request.edited, pull_request_review, issue_comment, etc.
• Provides REST/Checks API to read/write labels, comments, and check‐run statuses.
b. GitHub App Server (Node.js/TypeScript)
• index.ts initializes the Probot (or similar) framework and registers event handlers.
• Dispatcher module routes each incoming event to one or more rule‐enforcement modules.
c. Rule Modules (in src/)
• Semver enforcement (enforce-semver-labels.ts) – adds pending Check, ensures a semver label is present.
• PR open‐time (24-hour-rule.ts) – enforces minimum open time based on label.
• API review (api-review-state.ts) – adds and updates api-review labels/checks based on reviews or skip labels.
• Deprecation review (deprecation-review-state.ts) – posts a checklist comment, watches off‐checkboxes.
• Triage labels (add-triage-labels.ts) – initial “needs triage” labeling on new PRs.
d. Shared Utilities (src/utils/)
• GitHub API wrapper (env-util.ts, label-utils.ts, log-util.ts, check-utils.ts).
• Constants and enums define label names, time thresholds, check names.
Architectural Patterns and Principles
• Event‐Driven: each GitHub webhook triggers a cascade of handlers.
• Single‐Responsibility: one module per rule, orchestrated by a central dispatcher.
• Shared Utilities: avoid duplication of GitHub API calls, label/name constants.
• Stateless: no external DB—state lives in GitHub (labels, comments, checks).