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:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 */3 * *'
|
- cron: "0 0 * * *"
|
||||||
workflow_dispatch:
|
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:
|
jobs:
|
||||||
process-stale-issues:
|
stale:
|
||||||
|
if: github.repository_owner == 'CherryHQ'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
|
actions: write # Workaround for https://github.com/actions/stale/issues/1090
|
||||||
issues: write
|
issues: write
|
||||||
pull-requests: write
|
# Completely disable stalling for PRs
|
||||||
|
pull-requests: none
|
||||||
|
contents: none
|
||||||
steps:
|
steps:
|
||||||
- name: Process stale issues
|
- name: Close inactive issues
|
||||||
uses: actions/github-script@v6
|
uses: actions/stale@v9
|
||||||
with:
|
with:
|
||||||
script: |
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
const { Octokit } = require('@octokit/rest')
|
days-before-stale: ${{ env.daysBeforeStale }}
|
||||||
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN })
|
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'
|
# Temporary to reduce the huge issues number
|
||||||
const STALE_LABEL = 'inactive'
|
operations-per-run: 100
|
||||||
const DAYS_TO_STALE = 30
|
debug-only: false
|
||||||
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} 天内无更新会被自动关闭`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user