Update issue-management.yml (#4830)
* Update issue-management.yml * Update issue-management.yml
This commit is contained in:
parent
8ac4d07d6b
commit
748252febc
93
.github/workflows/issue-management.yml
vendored
93
.github/workflows/issue-management.yml
vendored
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user