# actions/labeler architecture

> Architecture diagram of the GitHub repository actions/labeler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/actions/labeler
- Repository: https://github.com/actions/labeler

## Overview

##### Project type and purpose
- This is an open-source GitHub Action, written in TypeScript/JavaScript, called “Pull Request Labeler.”
- Its purpose is to automatically apply and synchronize labels on pull requests based on changed-file globs or branch‐name regexps.

##### File structure
- Top-level configuration and CI/CD
- action.yml    – GitHub Action metadata (inputs, outputs, runs).
- .github/workflows – CI pipelines: build, lint, test, security scans, publish.
- .github/labeler.yml (userland) – runtime configuration of which labels map to which globs/regexps.
- Source code
- src/main.ts      – entry point invoked by action.yml.
- src/get-inputs/  – modules to read inputs (repo token, config path, pr-number).
- src/api/         – wrappers around GitHub API calls (get-changed-files, get-pull-requests, get-content, set-labels).
- src/branch.ts    – logic to match branch names against regexps.
- src/changedFiles.ts – logic to match changed-file paths against glob patterns.
- src/labeler.ts   – core orchestration: for each label, evaluate match objects, call set-labels as needed.
- src/utils.ts     – shared helpers.
- dist/            – transpiled JavaScript distribution (index.js) that is shipped.
- Testing
- __tests__        – Jest tests for each module.
- __mocks__        – custom mocks for @actions/github.
- Build and config
- tsconfig.json, package.json, .eslintrc.js, jest.config.js, .prettierrc.js
- LICENSE, CONTRIBUTING.md, CODE_OF_CONDUCT.md, etc.

##### README for additional insights
- Describes v5 breaking changes and the high-level matching logic (any/all AND/OR).
- Shows the required .github/workflows/labeler.yml and key inputs/outputs.
- Explains recommended permissions and event triggers (pull_request_target vs pull_request).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer CI Pipeline
    subgraph "Developer CI" 
        direction TB
        Lint["Lint (.eslintrc.js)"]:::ci
        Build["Build (tsc -> dist/index.js)"]:::ci
        Test["Test (jest.config.js)"]:::ci
        Publish["Publish Action"]:::ci
        Lint --> Build --> Test --> Publish
    end

    %% Runtime Action Execution
    subgraph "Runtime Action Execution"
        direction TB
        Runner(("GitHub Actions Runner")):::runner
        Workflow["Workflow Definition (.github/workflows/)"]:::workflow
        Metadata["GitHub Action Metadata\naction.yml"]:::metadata
        Dist["Transpiled Distribution\n_dist/index.js"]:::dist
        MainTS["Entry Point\nsrc/main.ts"]:::entry
        InputsSub["Inputs Modules"]:::module
        APISub["API Wrappers"]:::api
        Branch["Branch Matching Logic\nsrc/branch.ts"]:::logic
        Changed["Changed-Files Logic\nsrc/changedFiles.ts"]:::logic
        Labeler["Core Orchestration\nsrc/labeler.ts"]:::orchestration
        Utils["Shared Utilities\nsrc/utils.ts"]:::util
        Config["User Configuration\n.github/labeler.yml"]:::config
        GitHubAPI[(GitHub REST API)]:::external
        Outputs["Action Outputs\nnew-labels, all-labels"]:::outputs

        Runner --> Workflow --> Metadata --> Dist --> MainTS
        MainTS --> InputsSub
        MainTS --> Labeler
        InputsSub --> APISub
        APISub --> GitHubAPI
        MainTS --> Config
        Labeler --> Branch
        Labeler --> Changed
        Labeler --> APISub
        Labeler --> Utils
        Labeler --> SLabels
        SLabels["Set Labels\nsrc/api/set-labels.ts"]:::api --> GitHubAPI
        Labeler --> Outputs
    end

    %% Click Events for component mappings
    click Metadata "https://github.com/actions/labeler/blob/main/action.yml"
    click Workflow "https://github.com/actions/labeler/tree/main/.github/workflows/"
    click Config "https://github.com/actions/labeler/blob/main/.github/labeler.yml"
    click MainTS "https://github.com/actions/labeler/blob/main/src/main.ts"
    click InputsSub "https://github.com/actions/labeler/blob/main/src/get-inputs/index.ts"
    click InputsSub "https://github.com/actions/labeler/blob/main/src/get-inputs/get-pr-numbers.ts"
    click InputsSub "https://github.com/actions/labeler/blob/main/src/get-inputs/get-inputs.ts"
    click APISub "https://github.com/actions/labeler/blob/main/src/api/index.ts"
    click GCFiles "https://github.com/actions/labeler/blob/main/src/api/get-changed-files.ts"
    click GCPR "https://github.com/actions/labeler/blob/main/src/api/get-changed-pull-requests.ts"
    click GCContent "https://github.com/actions/labeler/blob/main/src/api/get-content.ts"
    click GLConfigs "https://github.com/actions/labeler/blob/main/src/api/get-label-configs.ts"
    click SLabels "https://github.com/actions/labeler/blob/main/src/api/set-labels.ts"
    click Types "https://github.com/actions/labeler/blob/main/src/api/types.ts"
    click Branch "https://github.com/actions/labeler/blob/main/src/branch.ts"
    click Changed "https://github.com/actions/labeler/blob/main/src/changedFiles.ts"
    click Labeler "https://github.com/actions/labeler/blob/main/src/labeler.ts"
    click Utils "https://github.com/actions/labeler/blob/main/src/utils.ts"
    click Dist "https://github.com/actions/labeler/blob/main/dist/index.js"

    classDef ci fill:#f9f,stroke:#333,stroke-width:1px
    classDef runner fill:#bbf,stroke:#333,stroke-width:1px
    classDef workflow fill:#bfb,stroke:#333,stroke-width:1px
    classDef metadata fill:#ffb,stroke:#333,stroke-width:1px
    classDef dist fill:#fcf,stroke:#333,stroke-width:1px
    classDef entry fill:#cff,stroke:#333,stroke-width:1px
    classDef module fill:#efe,stroke:#333,stroke-width:1px
    classDef api fill:#fee,stroke:#333,stroke-width:1px
    classDef logic fill:#eef,stroke:#333,stroke-width:1px
    classDef orchestration fill:#ffe,stroke:#333,stroke-width:1px
    classDef util fill:#def,stroke:#333,stroke-width:1px
    classDef config fill:#ffd,stroke:#333,stroke-width:1px
    classDef external fill:#ddd,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef outputs fill:#dfd,stroke:#333,stroke-width:1px
```
