Skip to content

refactor(Header/TOC/BackToTop): Use css for responsive. #73

refactor(Header/TOC/BackToTop): Use css for responsive.

refactor(Header/TOC/BackToTop): Use css for responsive. #73

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@v4
- 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 = {
'main': 'f66a0a', // Orange
'common-components': '1f77b4', // Blue
'posts': '8c564b', // Brown
'service': '2ca02c', // Green
'styles': '9467bd', // Purple
'content': 'ffdd57', // Yellow
'types': 'd62728', // Red
};
const labels = new Set();
prFiles.data.forEach(file => {
if (file.filename.startsWith('src/app')) {
labels.add('main');
}
if (file.filename.startsWith('src/components/posts')) {
labels.add('posts');
}
if (file.filename.startsWith('src/components/common')) {
labels.add('common-components');
}
if (file.filename.startsWith('src/services')) {
labels.add('services');
}
if (file.filename.endsWith('.css')) {
labels.add('styles');
}
if (file.filename.startsWith('posts')) {
labels.add('content');
}
if (file.filename.startsWith('src/types.d.ts') || file.filename.endsWith('.d.ts')) {
labels.add('types');
}
});
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)
});
}