Skip to content

build(deps-dev): bump @cloudflare/vitest-pool-workers from 0.5.29 to 0.5.31 #59

build(deps-dev): bump @cloudflare/vitest-pool-workers from 0.5.29 to 0.5.31

build(deps-dev): bump @cloudflare/vitest-pool-workers from 0.5.29 to 0.5.31 #59

name: Auto-label PR based on file paths
on:
pull_request:
types: [opened, synchronize]
jobs:
label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Label PR based on changes
uses: actions/github-script@v7
with:
script: |
const prFiles = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const labelsToColor = {
routes: 'f66a0a', // Orange
test: 'd62728', // Red
types: '1f77b4', // Blue
lib: '1f77b4', // Blue
config: '8c564b', // Brown
dependency: '2ca02c', // Green
db: '9467bd', // Purple
middleware: 'ff7f0e', // Orange for middleware
};
const labels = new Set();
prFiles.data.forEach(file => {
if (file.filename.startsWith('src/routes')) {
labels.add('routes');
}
if (file.filename.endsWith('.test.ts')) {
labels.add('test');
}
if (file.filename.startsWith('src/types') || file.filename.endsWith('.d.ts')) {
labels.add('types');
}
if (file.filename.startsWith('src/lib')) {
labels.add('lib');
}
if (file.filename.includes('.config.') || file.filename.endsWith('.toml') || file.filename.includes('.dev.')) {
labels.add('config');
}
if (file.filename === 'package.json' || file.filename === 'yarn.lock' || file.filename.startsWith('.pnp.')) {
labels.add('dependency');
}
if (file.filename.startsWith('db/') || file.filename.startsWith('src/db')) {
labels.add('db');
}
if (file.filename.startsWith('src/middleware')) {
labels.add('middleware');
}
});
if (labels.size > 0) {
for (const label of labels) {
try {
// Check if the label exists
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label
});
} catch (error) {
// If label doesn't exist, create it with the specified color
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label,
color: labelsToColor[label] || 'b0b0b0', // Use default gray if no color specified
});
}
}
// Add labels to the PR
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: Array.from(labels)
});
}