From 748252febcb94a3ad6ac2689d9007ba16879695a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=AA=E7=94=B1=E7=9A=84=E4=B8=96=E7=95=8C=E4=BA=BA?= <3196812536@qq.com> Date: Tue, 15 Apr 2025 09:59:37 +0800 Subject: [PATCH] Update issue-management.yml (#4830) * Update issue-management.yml * Update issue-management.yml --- .github/workflows/issue-management.yml | 93 ++++++++------------------ 1 file changed, 28 insertions(+), 65 deletions(-) diff --git a/.github/workflows/issue-management.yml b/.github/workflows/issue-management.yml index 4fb5a8c3..4f178a81 100644 --- a/.github/workflows/issue-management.yml +++ b/.github/workflows/issue-management.yml @@ -1,76 +1,39 @@ -name: Stale Issue Management +name: "Stale Issue Management" + on: schedule: - - cron: '0 0 */3 * *' + - cron: "0 0 * * *" workflow_dispatch: +env: + daysBeforeStale: 30 # Number of days of inactivity before marking as stale + daysBeforeClose: 30 # Number of days to wait after marking as stale before closing + jobs: - process-stale-issues: + stale: + if: github.repository_owner == 'CherryHQ' runs-on: ubuntu-latest permissions: + actions: write # Workaround for https://github.com/actions/stale/issues/1090 issues: write - pull-requests: write + # Completely disable stalling for PRs + pull-requests: none + contents: none steps: - - name: Process stale issues - uses: actions/github-script@v6 + - name: Close inactive issues + uses: actions/stale@v9 with: - script: | - const { Octokit } = require('@octokit/rest') - const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }) + repo-token: ${{ secrets.GITHUB_TOKEN }} + days-before-stale: ${{ env.daysBeforeStale }} + days-before-close: ${{ env.daysBeforeClose }} + stale-issue-label: "inactive" + stale-issue-message: | + This issue has been inactive for a prolonged period and will be closed automatically in ${{ env.daysBeforeClose }} days. + 该问题已长时间处于闲置状态,${{ env.daysBeforeClose }} 天后将自动关闭。 + exempt-issue-labels: "pending, Dev Team, enhancement" + days-before-pr-stale: -1 # Completely disable stalling for PRs + days-before-pr-close: -1 # Completely disable closing for PRs - const EXEMPTION_LABEL = 'pending' - const STALE_LABEL = 'inactive' - const DAYS_TO_STALE = 30 - const DAYS_TO_CLOSE = 60 - - const issues = await octokit.paginate(octokit.rest.issues.listForRepo, { - owner: context.repo.owner, - repo: context.repo.repo, - state: 'open', - }) - - const now = new Date() - - for (const issue of issues) { - if (issue.pull_request || issue.labels.some(l => l.name === EXEMPTION_LABEL)) { - continue - } - - const lastUpdated = new Date(issue.updated_at) - const daysInactive = Math.floor((now - lastUpdated) / (1000 * 3600 * 24)) - - if (daysInactive > DAYS_TO_CLOSE) { - await octokit.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue.number, - body: `⏰ 该 issue 因 ${DAYS_TO_CLOSE} 天无更新已自动关闭,如需跟进可重新打开` - }) - - await octokit.rest.issues.update({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue.number, - state: 'closed' - }) - continue - } - - if (daysInactive > DAYS_TO_STALE) { - if (!issue.labels.some(l => l.name === STALE_LABEL)) { - await octokit.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue.number, - labels: [STALE_LABEL] - }) - - await octokit.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue.number, - body: `⚠️ 该 issue 已 ${DAYS_TO_STALE} 天无更新,将保持跟踪。如果 ${DAYS_TO_CLOSE - DAYS_TO_STALE} 天内无更新会被自动关闭` - }) - } - } - } + # Temporary to reduce the huge issues number + operations-per-run: 100 + debug-only: false