ci: migrate issue types (#492)

[skip ci] [skip netlify]
This commit is contained in:
Typed SIGTERM
2025-08-28 10:20:37 +08:00
committed by GitHub
parent 261c5c5717
commit 283657a92d
6 changed files with 235 additions and 110 deletions
+61
View File
@@ -0,0 +1,61 @@
/* eslint-disable no-console */
import process from 'node:process'
import { Octokit } from '@octokit/rest'
const IssueTypeMapping = {
enhancement: 'Feature',
bug: 'Bug',
}
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
async function migrate(octokit: Octokit, owner: string, repo: string): Promise<void> {
const allIssues = await octokit.paginate(octokit.rest.issues.listForRepo, {
owner,
repo,
state: 'all',
per_page: 100,
})
const issues = allIssues.filter(x => !x.pull_request)
for (const issue of issues) {
const labels: string[] = []
for (const label of issue.labels) {
if (typeof label === 'string')
labels.push(label)
else if (label.name)
labels.push(label.name)
}
const typeLabel = labels.find(label => label in IssueTypeMapping)
if (typeLabel) {
try {
const updatedLabels = labels.filter(x => x !== typeLabel)
await octokit.rest.issues.update({
owner,
repo,
issue_number: issue.number,
labels: updatedLabels,
type: IssueTypeMapping[typeLabel as keyof typeof IssueTypeMapping],
})
console.log(`Updated #${issue.number}`)
await sleep(100)
}
catch (error) {
console.error('Failed to update issue #%d: %o', issue.number, error)
}
}
}
}
(async () => {
const token = process.env.GITHUB_TOKEN
const repository = process.env.GITHUB_REPOSITORY
const [owner, repo] = repository?.split('/') || []
if (!token || !owner || !repo)
throw new Error('Invalid parameters')
await migrate(new Octokit({ auth: token }), owner, repo)
})()
+30
View File
@@ -0,0 +1,30 @@
name: Migrate Issue Types
on:
workflow_dispatch:
jobs:
migrate-issue-types:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24
- name: Install dependencies
run: pnpm ci --ignore-scripts
- name: Run issue type migration
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: pnpm tsx .github/workflows/migrate-issue-types.ts