mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
chore(ci): add action to label issues
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
name: 🐛 Bug Report
|
||||
description: Report a reproducible bug or regression.
|
||||
type: bug
|
||||
labels: ['status: unconfirmed', bug]
|
||||
labels: [triage]
|
||||
title: 'Bug: '
|
||||
body:
|
||||
- type: markdown
|
||||
@@ -33,9 +33,11 @@ body:
|
||||
- HTML (@videojs/html)
|
||||
- React (@videojs/react)
|
||||
- Utils (@videojs/utils)
|
||||
- HTML Example
|
||||
- React Example
|
||||
- Next.js Example
|
||||
- Website
|
||||
- Example / Demo Apps (html-demo, react-demo, next-demo)
|
||||
- Other/unknown (please mention in description)
|
||||
- Other (please mention in description)
|
||||
- type: textarea
|
||||
id: environment
|
||||
validations:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: 💎 Feature Request
|
||||
description: Request a new feature or enhancement
|
||||
type: enhancement
|
||||
labels: []
|
||||
labels: [triage]
|
||||
title: 'Feature Request: '
|
||||
body:
|
||||
- type: markdown
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: 📄 Docs Feedback
|
||||
description: Report a discrepancy in or an improvement to the docs.
|
||||
labels: [documentation]
|
||||
labels: [triage, docs]
|
||||
title: 'Docs: '
|
||||
body:
|
||||
- type: markdown
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
import core from '@actions/core';
|
||||
import github from '@actions/github';
|
||||
|
||||
// eslint-disable-next-line node/prefer-global/process
|
||||
const GH_TOKEN = process.env.GITHUB_TOKEN;
|
||||
|
||||
const pkgLabel = {
|
||||
'Core (@videojs/core)': 'pkg:core',
|
||||
'Icons (@videojs/icons)': 'pkg:icons',
|
||||
'HTML (@videojs/html)': 'pkg:html',
|
||||
'React (@videojs/react)': 'pkg:react',
|
||||
'Utils (@videojs/utils)': 'pkg:utils',
|
||||
'HTML Example': 'example:html',
|
||||
'React Example': 'example:react',
|
||||
'Next.js Example': 'example:next.js',
|
||||
Website: 'site',
|
||||
};
|
||||
|
||||
const envLabel = {
|
||||
// Browsers
|
||||
chrome: 'browser:chrome',
|
||||
chromium: 'browser:chrome',
|
||||
firefox: 'browser:firefox',
|
||||
safari: 'browser:safari',
|
||||
edge: 'browser:edge',
|
||||
msedge: 'browser:edge',
|
||||
// OS
|
||||
macos: 'os:mac',
|
||||
'mac os': 'os:mac',
|
||||
darwin: 'os:mac',
|
||||
windows: 'os:windows',
|
||||
win32: 'os:windows',
|
||||
win10: 'os:windows',
|
||||
linux: 'os:linux',
|
||||
ubuntu: 'os:linux',
|
||||
debian: 'os:linux',
|
||||
android: 'os:android',
|
||||
ios: 'os:ios',
|
||||
iphone: 'os:ios',
|
||||
ipad: 'os:ios',
|
||||
};
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const { issue } = github.context.payload;
|
||||
|
||||
if (!issue || !issue.body) {
|
||||
console.log('No issue body found, skipping.');
|
||||
return;
|
||||
}
|
||||
|
||||
const labels = new Set();
|
||||
|
||||
const pkg = extractSection(issue, '### Which package(s) or projects are affected?');
|
||||
if (pkg) {
|
||||
for (const [option, label] of Object.entries(pkgLabel)) {
|
||||
if (pkg.includes(option)) {
|
||||
labels.add(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const env = extractSection(issue, '### Browser/OS/Node environment');
|
||||
if (env) {
|
||||
const envText = env.toLowerCase();
|
||||
for (const [keyword, label] of Object.entries(envLabel)) {
|
||||
if (envText.includes(keyword)) {
|
||||
labels.add(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (labels.size === 0) {
|
||||
console.log('No matching labels found.');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Matched labels: ${Array.from(labels).join(', ')}`);
|
||||
|
||||
// eslint-disable-next-line node/prefer-global/process
|
||||
if (process.env.DRY_RUN === 'true') {
|
||||
console.log('⚠️ DRY RUN: Skipping API call.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GH_TOKEN) {
|
||||
throw new Error('GITHUB_TOKEN is not set');
|
||||
}
|
||||
|
||||
const octokit = github.getOctokit(GH_TOKEN);
|
||||
|
||||
await octokit.rest.issues.addLabels({
|
||||
owner: github.context.repo.owner,
|
||||
repo: github.context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
labels: Array.from(labels),
|
||||
});
|
||||
} catch (error) {
|
||||
core.setFailed(`Action failed with error: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} issue
|
||||
* @param {string} header
|
||||
*/
|
||||
function extractSection(issue, header) {
|
||||
const escapedHeader = header.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
const regex = new RegExp(`${escapedHeader}\\r?\\n([\\s\\S]*?)(?=\\r?\\n###|$)`, 'i');
|
||||
const match = issue.body.match(regex);
|
||||
return match ? match[1].trim() : null;
|
||||
};
|
||||
|
||||
run();
|
||||
@@ -0,0 +1,32 @@
|
||||
name: Label Issue
|
||||
on:
|
||||
issues:
|
||||
types: [opened, edited]
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
label:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v5
|
||||
with:
|
||||
node-version: 22
|
||||
cache: pnpm
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: Run
|
||||
run: node .github/scripts/label-issue.js
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
Reference in New Issue
Block a user