Skip to content

Commit a103c39

Browse files
committed
feat: pr size checker
1 parent 8d18b2a commit a103c39

7 files changed

Lines changed: 437 additions & 2 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: PR Size Check (External Usage Example)
2+
3+
# This is an example of how others would use your action
4+
# after publishing it to GitHub Marketplace
5+
6+
on:
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
10+
jobs:
11+
check-pr-size:
12+
runs-on: ubuntu-latest
13+
name: Check PR Size
14+
steps:
15+
- name: Check PR Size
16+
uses: automationDojo/github-custom-action-examples@main
17+
with:
18+
github-token: ${{ secrets.GITHUB_TOKEN }}
19+
small-threshold: 100
20+
medium-threshold: 300
21+
large-threshold: 600
22+
comment-on-large: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: PR Size Check
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
check-pr-size:
9+
runs-on: ubuntu-latest
10+
name: Check PR Size
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Check PR Size
16+
uses: ./
17+
with:
18+
github-token: ${{ secrets.GITHUB_TOKEN }}
19+
small-threshold: 100
20+
medium-threshold: 300
21+
large-threshold: 600
22+
comment-on-large: true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
*.log
3+
.DS_Store

README.md

Lines changed: 161 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,161 @@
1-
# github-custom-action-examples
2-
Examples of custom GitHub Actions
1+
# PR Size Checker
2+
3+
A reusable GitHub Action that automatically checks Pull Request size and adds appropriate labels.
4+
5+
## Features
6+
7+
- Automatically calculates total lines changed (additions + deletions)
8+
- Adds size-based labels: `small`, `medium`, `large`, `extra-large`
9+
- Automatically creates labels if they don't exist in the repository
10+
- Removes old labels when size changes
11+
- Comments on large PRs suggesting split (optional)
12+
- Configurable with custom thresholds
13+
14+
## Usage
15+
16+
### Basic Setup
17+
18+
Create a `.github/workflows/pr-size-check.yml` file in your repository:
19+
20+
```yaml
21+
name: PR Size Check
22+
23+
on:
24+
pull_request:
25+
types: [opened, synchronize, reopened]
26+
27+
jobs:
28+
check-pr-size:
29+
runs-on: ubuntu-latest
30+
name: Check PR Size
31+
steps:
32+
- name: Check PR Size
33+
uses: automationDojo/github-custom-action-examples@main
34+
with:
35+
github-token: ${{ secrets.GITHUB_TOKEN }}
36+
```
37+
38+
### Advanced Configuration
39+
40+
```yaml
41+
name: PR Size Check
42+
43+
on:
44+
pull_request:
45+
types: [opened, synchronize, reopened]
46+
47+
jobs:
48+
check-pr-size:
49+
runs-on: ubuntu-latest
50+
name: Check PR Size
51+
steps:
52+
- name: Check PR Size
53+
uses: automationDojo/github-custom-action-examples@main
54+
with:
55+
github-token: ${{ secrets.GITHUB_TOKEN }}
56+
small-threshold: 100 # PRs up to 100 lines = small
57+
medium-threshold: 300 # PRs up to 300 lines = medium
58+
large-threshold: 600 # PRs up to 600 lines = large
59+
comment-on-large: true # Comment on large PRs
60+
```
61+
62+
## Inputs
63+
64+
| Input | Description | Required | Default |
65+
|-------|-----------|-------------|---------|
66+
| `github-token` | GitHub token for API calls | Yes | - |
67+
| `small-threshold` | Maximum lines changed for a small PR | No | `100` |
68+
| `medium-threshold` | Maximum lines changed for a medium PR | No | `300` |
69+
| `large-threshold` | Maximum lines changed for a large PR | No | `600` |
70+
| `comment-on-large` | Whether to comment on large PRs | No | `true` |
71+
72+
## Outputs
73+
74+
| Output | Description |
75+
|--------|-----------|
76+
| `size-label` | Label applied to the PR (small, medium, large, extra-large) |
77+
| `lines-changed` | Total number of lines changed |
78+
79+
## Example Usage with Outputs
80+
81+
```yaml
82+
- name: Check PR Size
83+
id: pr-size
84+
uses: automationDojo/github-custom-action-examples@main
85+
with:
86+
github-token: ${{ secrets.GITHUB_TOKEN }}
87+
88+
- name: Display PR Size
89+
run: |
90+
echo "PR Size: ${{ steps.pr-size.outputs.size-label }}"
91+
echo "Lines Changed: ${{ steps.pr-size.outputs.lines-changed }}"
92+
```
93+
94+
## Labels Created
95+
96+
The action automatically creates the following labels:
97+
98+
| Label | Color | Description |
99+
|-------|-----|-----------|
100+
| `small` | Green | Small PRs, easy to review |
101+
| `medium` | Yellow | Medium-sized PRs |
102+
| `large` | Orange | Large PRs, consider splitting |
103+
| `extra-large` | Red | Very large PRs, splitting recommended |
104+
105+
## How It Works
106+
107+
1. The action is triggered on pull request events
108+
2. Calculates total lines changed (additions + deletions)
109+
3. Determines size based on configured thresholds
110+
4. Removes old size labels
111+
5. Adds the appropriate new label
112+
6. If the PR is large or extra-large, adds a comment suggesting split
113+
114+
## Local Development
115+
116+
### Prerequisites
117+
118+
- Node.js 20 or higher
119+
- npm
120+
121+
### Setup
122+
123+
```bash
124+
npm install
125+
```
126+
127+
### File Structure
128+
129+
```
130+
github-custom-action-examples/
131+
├── action.yml # Action metadata
132+
├── index.js # Main logic
133+
├── package.json # Dependencies
134+
├── README.md # Documentation
135+
└── .github/
136+
└── workflows/
137+
├── pr-size-check.yml # Local usage example
138+
└── pr-size-check-external.yml # External usage example
139+
```
140+
141+
## Contributing
142+
143+
Contributions are welcome! Please:
144+
145+
1. Fork the repository
146+
2. Create a branch for your feature
147+
3. Commit your changes
148+
4. Open a Pull Request
149+
150+
## License
151+
152+
MIT
153+
154+
## Author
155+
156+
AutomationDojo
157+
158+
## Useful Links
159+
160+
- [GitHub Actions Documentation](https://docs.github.com/en/actions)
161+
- [Creating a JavaScript Action](https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action)

action.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: 'PR Size Checker'
2+
description: 'Automatically labels PRs based on size and warns if they are too large'
3+
author: 'AutomationDojo'
4+
5+
branding:
6+
icon: 'git-pull-request'
7+
color: 'blue'
8+
9+
inputs:
10+
github-token:
11+
description: 'GitHub token for API calls'
12+
required: true
13+
small-threshold:
14+
description: 'Maximum lines changed for a small PR'
15+
required: false
16+
default: '100'
17+
medium-threshold:
18+
description: 'Maximum lines changed for a medium PR'
19+
required: false
20+
default: '300'
21+
large-threshold:
22+
description: 'Maximum lines changed for a large PR'
23+
required: false
24+
default: '600'
25+
comment-on-large:
26+
description: 'Whether to comment on large PRs'
27+
required: false
28+
default: 'true'
29+
30+
outputs:
31+
size-label:
32+
description: 'The size label applied to the PR (small, medium, large, extra-large)'
33+
lines-changed:
34+
description: 'Total number of lines changed (additions + deletions)'
35+
36+
runs:
37+
using: 'node20'
38+
main: 'index.js'

0 commit comments

Comments
 (0)