Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: reconstruct issue and label in GitHub. #648

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature-request.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Feature Request
title: "[FEATURE REQUEST] "
labels: ["feature request"]
labels: ["feature request","enhancement"]
description: "Propose a new feature or improvement that you believe will help enhance the project."
# assignees: []

Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/remove-unused-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Remove Unused Labels
on:
workflow_dispatch: # 手动触发

jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: read
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Fetch All Issues and PRs
id: fetch_issues_prs
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issues = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
per_page: 100
});

const labelsInUse = new Set();
issues.forEach(issue => {
issue.labels.forEach(label => {
labelsInUse.add(label.name);
});
});

return JSON.stringify(Array.from(labelsInUse));
result-encoding: string

- name: Fetch All Labels
id: fetch_labels
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labels = await github.paginate(github.rest.issues.listLabelsForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});

return JSON.stringify(labels.map(label => label.name));
result-encoding: string

- name: Remove Unused Labels
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labelsInUse = new Set(JSON.parse(process.env.LABELS_IN_USE));
const allLabels = JSON.parse(process.env.ALL_LABELS);

const unusedLabels = allLabels.filter(label => !labelsInUse.has(label));

for (const label of unusedLabels) {
await github.rest.issues.deleteLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label
});
console.log(`Deleted label: ${label}`);
}
env:
LABELS_IN_USE: ${{ steps.fetch_issues_prs.outputs.result }}
ALL_LABELS: ${{ steps.fetch_labels.outputs.result }}
74 changes: 74 additions & 0 deletions .github/workflows/reopen-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Reopen and Update Stale Issues

on:
workflow_dispatch: # 手动触发

jobs:
reopen_stale_issues:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Fetch Closed Issues with lifecycle/stale Label
id: fetch_issues
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issues = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
labels: 'lifecycle/stale',
per_page: 100
});

const issueNumbers = issues.map(issue => issue.number);
console.log(`Fetched issues: ${issueNumbers}`);
return issueNumbers;

- name: Set issue numbers
id: set_issue_numbers
run: echo "ISSUE_NUMBERS=${{ steps.fetch_issues.outputs.result }}" >> $GITHUB_ENV

- name: Reopen Issues
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueNumbers = JSON.parse(process.env.ISSUE_NUMBERS);

for (const issue_number of issueNumbers) {
// Reopen the issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(issue_number, 10),
state: 'open'
});
console.log(`Reopened issue #${issue_number}`);
}

# Remove label in specifical issue
- name: Remove lifecycle/stale Label
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueNumbers = JSON.parse(process.env.ISSUE_NUMBERS);

for (const issue_number of issueNumbers) {
// Remove the lifecycle/stale label
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(issue_number, 10),
name: 'lifecycle/stale'
});
console.log(`Removed label 'lifecycle/stale' from issue #${issue_number}`);
}
48 changes: 0 additions & 48 deletions .github/workflows/stale.yml

This file was deleted.

Loading