Skip to content

Repository files navigation

PR Size Checker

A reusable GitHub Action that automatically checks Pull Request size and adds appropriate labels.

Features

  • 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

Usage

Basic Setup

Create a .github/workflows/pr-size-check.yml file in your repository:

name: PR Size Checkon:
pull_request:
types: [opened, synchronize, reopened]jobs:
check-pr-size:
runs-on: ubuntu-latestname: Check PR Sizesteps:
- name: Check PR Sizeuses: automationDojo/github-custom-action-examples@mainwith:
github-token: ${{ secrets.GITHUB_TOKEN }}

Advanced Configuration

name: PR Size Checkon:
pull_request:
types: [opened, synchronize, reopened]jobs:
check-pr-size:
runs-on: ubuntu-latestname: Check PR Sizesteps:
- name: Check PR Sizeuses: automationDojo/github-custom-action-examples@mainwith:
github-token: ${{ secrets.GITHUB_TOKEN }}small-threshold: 100# PRs up to 100 lines = smallmedium-threshold: 300# PRs up to 300 lines = mediumlarge-threshold: 600# PRs up to 600 lines = largecomment-on-large: true # Comment on large PRs

Inputs

InputDescriptionRequiredDefault
github-tokenGitHub token for API callsYes-
small-thresholdMaximum lines changed for a small PRNo100
medium-thresholdMaximum lines changed for a medium PRNo300
large-thresholdMaximum lines changed for a large PRNo600
comment-on-largeWhether to comment on large PRsNotrue

Outputs

OutputDescription
size-labelLabel applied to the PR (small, medium, large, extra-large)
lines-changedTotal number of lines changed

Example Usage with Outputs

- name: Check PR Sizeid: pr-sizeuses: automationDojo/github-custom-action-examples@mainwith:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Display PR Sizerun: | echo "PR Size: ${{ steps.pr-size.outputs.size-label }}" echo "Lines Changed: ${{ steps.pr-size.outputs.lines-changed }}"

Labels Created

The action automatically creates the following labels:

LabelColorDescription
smallGreenSmall PRs, easy to review
mediumYellowMedium-sized PRs
largeOrangeLarge PRs, consider splitting
extra-largeRedVery large PRs, splitting recommended

How It Works

  1. The action is triggered on pull request events
  2. Calculates total lines changed (additions + deletions)
  3. Determines size based on configured thresholds
  4. Removes old size labels
  5. Adds the appropriate new label
  6. If the PR is large or extra-large, adds a comment suggesting split

Local Development

Prerequisites

  • Node.js 20 or higher
  • npm

Setup

npm install
npm run build

Building

The action uses @vercel/ncc to compile the code and dependencies into a single file. This eliminates the need to commit node_modules.

npm run build

This creates a dist/index.js file that includes all dependencies bundled together.

File Structure

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

Releases and Versioning

This project uses Semantic Release for automated versioning and releases.

Commit Message Format

Follow the Conventional Commits specification:

  • feat: - A new feature (triggers minor version bump)
  • fix: - A bug fix (triggers patch version bump)
  • docs: - Documentation changes
  • chore: - Maintenance tasks
  • BREAKING 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

How It Works

  1. Push commits to main branch using conventional commit format
  2. Semantic Release analyzes commits and determines version bump
  3. Automatically generates CHANGELOG.md
  4. Creates a GitHub release with release notes
  5. Updates version in package.json

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a branch for your feature
  3. Commit your changes using conventional commit format
  4. Open a Pull Request

License

MIT

Author

AutomationDojo

Useful Links

About

Examples of custom GitHub Actions

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages