name: Auto Label PRs and Issues
on:
pull_request:
types: [opened, synchronize, reopened]
issues:
types: [opened, edited]
workflow_dispatch:
permissions:
contents: read
issues: write
pull-requests: write
jobs:
auto-label:
name: Auto Label
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
with:
fetch-depth: 0
# Label PRs based on changed files
- name: Label PRs by file changes
if: github.event_name == 'pull_request'
uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v5
with:
configuration-path: .github/labeler.yml
repo-token: ${{ secrets.GITHUB_TOKEN }}
sync-labels: true
# Label based on PR size
- name: Label PR size
if: github.event_name == 'pull_request'
uses: pascalgn/size-label-action@f8edde36b3be04b4f65dcfead05dc8691b374348 # v0.5.5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
sizes: |
{
"0": "tiny",
"10": "xs",
"30": "s",
"100": "m",
"500": "l",
"1000": "xl",
"2000": "xxl"
}
# Auto-label issues based on content
- name: Label issues by content
if: github.event_name == 'issues'
uses: github/issue-labeler@c1b0f9f52a63158c4adc09425e858e87b32e9685 # v3.4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/issue-labeler.yml
include-title: true
include-body: true
enable-versioned-regex: 1
sync-labels: 0
# Label for first-time contributors
- name: Label first-time contributor
if: github.event_name == 'pull_request'
uses: actions/first-interaction@1c4688942c71f71d4f5502a26ea67c331730fa4d # v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
pr-message: |
👋 Thanks for your first contribution to this project!
We appreciate you taking the time to contribute. Your PR will be reviewed soon.
Please make sure:
- [ ] You've read our contributing guidelines
- [ ] Tests pass locally
- [ ] Code follows our style guide
Welcome to the community! 🎉
issue-message: |
👋 Thanks for opening your first issue!
We appreciate you taking the time to report this. Someone will look into it soon.
Please make sure you've provided all the necessary information to help us understand and reproduce the issue.
# Auto-assign reviewers for PRs
- name: Auto-assign reviewers
if: github.event_name == 'pull_request'
uses: kentaro-m/auto-assign-action@f4648c0a9fdb753479e9e75fc251f507ce17bb7e # v2.0.0
with:
configuration-path: .github/auto_assign.yml
dependency-label:
name: Label Dependencies
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && contains(github.head_ref, 'dependabot')
steps:
- name: Add dependency labels
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
with:
script: |
const { owner, repo, number } = context.issue;
const prTitle = context.payload.pull_request.title.toLowerCase();
const labels = [];
if (prTitle.includes('deps:')) {
labels.push('dependencies');
}
if (prTitle.includes('deps-dev:')) {
labels.push('dependencies', 'dev-dependencies');
}
if (prTitle.includes('security')) {
labels.push('security');
}
if (prTitle.includes('@types/')) {
labels.push('typescript');
}
if (prTitle.includes('eslint') || prTitle.includes('prettier')) {
labels.push('tooling');
}
if (prTitle.includes('vitest') || prTitle.includes('test')) {
labels.push('testing');
}
if (prTitle.includes('@azure/') || prTitle.includes('mssql')) {
labels.push('azure', 'database');
}
if (labels.length > 0) {
await github.rest.issues.addLabels({
owner,
repo,
issue_number: number,
labels
});
}