Reopen and Update Stale Issues #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Reopen and Update Stale Issues | |
on: | |
workflow_dispatch: # 手动触发 | |
jobs: | |
reopen_stale_issues: | |
runs-on: ubuntu-latest | |
permissions: | |
issues: write | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Fetch Closed Issues with lifecycle/stale Label | |
id: fetch_issues | |
uses: actions/[email protected] | |
with: | |
github-token: ${{ secrets.BOT_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 | |
}); | |
return { issue_numbers: issues.map(issue => issue.number).join(',') }; | |
result-encoding: string | |
- name: Reopen and Remove Label | |
uses: actions/[email protected] | |
with: | |
github-token: ${{ secrets.BOT_GITHUB_TOKEN }} | |
script: | | |
const issueNumbers = process.env.ISSUE_NUMBERS.split(','); | |
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 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}`); | |
} | |
env: | |
ISSUE_NUMBERS: ${{ steps.fetch_issues.outputs.result }} |