A reusable GitHub Action that automatically checks Pull Request size and adds appropriate labels.
- Automatically calculates total lines changed (additions + deletions)
- Adds size-based labels:
small,medium,large,extra-large - Automatically creates labels if they don't exist in the repository
- Removes old labels when size changes
- Comments on large PRs suggesting split (optional)
- Configurable with custom thresholds
Create a .github/workflows/pr-size-check.yml file in your repository:
name: PR Size Check
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
check-pr-size:
runs-on: ubuntu-latest
name: Check PR Size
steps:
- name: Check PR Size
uses: automationDojo/github-custom-action-examples@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}name: PR Size Check
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
check-pr-size:
runs-on: ubuntu-latest
name: Check PR Size
steps:
- name: Check PR Size
uses: automationDojo/github-custom-action-examples@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
small-threshold: 100 # PRs up to 100 lines = small
medium-threshold: 300 # PRs up to 300 lines = medium
large-threshold: 600 # PRs up to 600 lines = large
comment-on-large: true # Comment on large PRs| Input | Description | Required | Default |
|---|---|---|---|
github-token |
GitHub token for API calls | Yes | - |
small-threshold |
Maximum lines changed for a small PR | No | 100 |
medium-threshold |
Maximum lines changed for a medium PR | No | 300 |
large-threshold |
Maximum lines changed for a large PR | No | 600 |
comment-on-large |
Whether to comment on large PRs | No | true |
| Output | Description |
|---|---|
size-label |
Label applied to the PR (small, medium, large, extra-large) |
lines-changed |
Total number of lines changed |
- name: Check PR Size
id: pr-size
uses: automationDojo/github-custom-action-examples@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Display PR Size
run: |
echo "PR Size: ${{ steps.pr-size.outputs.size-label }}"
echo "Lines Changed: ${{ steps.pr-size.outputs.lines-changed }}"The action automatically creates the following labels:
| Label | Color | Description |
|---|---|---|
small |
Green | Small PRs, easy to review |
medium |
Yellow | Medium-sized PRs |
large |
Orange | Large PRs, consider splitting |
extra-large |
Red | Very large PRs, splitting recommended |
- The action is triggered on pull request events
- Calculates total lines changed (additions + deletions)
- Determines size based on configured thresholds
- Removes old size labels
- Adds the appropriate new label
- If the PR is large or extra-large, adds a comment suggesting split
- Node.js 20 or higher
- npm
npm install
npm run buildThe action uses @vercel/ncc to compile the code and dependencies into a single file. This eliminates the need to commit node_modules.
npm run buildThis creates a dist/index.js file that includes all dependencies bundled together.
github-custom-action-examples/
├── action.yml # Action metadata (points to dist/index.js)
├── index.js # Main logic (source)
├── dist/
│ └── index.js # Bundled code with dependencies (commit this!)
├── package.json # Dependencies
├── README.md # Documentation
└── .github/
└── workflows/
├── release.yml # Semantic Release workflow
├── pr-size-check.yml # Local usage example
└── pr-size-check-external.yml # External usage example
This project uses Semantic Release for automated versioning and releases.
Follow the Conventional Commits specification:
feat:- A new feature (triggers minor version bump)fix:- A bug fix (triggers patch version bump)docs:- Documentation changeschore:- Maintenance tasksBREAKING CHANGE:- Breaking changes (triggers major version bump)
Examples:
feat: add support for custom label colors
fix: resolve issue with label removal
docs: update README with new examples
chore: update dependencies- Push commits to
mainbranch using conventional commit format - Semantic Release analyzes commits and determines version bump
- Automatically generates CHANGELOG.md
- Creates a GitHub release with release notes
- Updates version in package.json
Contributions are welcome! Please:
- Fork the repository
- Create a branch for your feature
- Commit your changes using conventional commit format
- Open a Pull Request
MIT
AutomationDojo