Close old issues #41
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
# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time. | |
# | |
# You can adjust the behavior by modifying this file. | |
# For more information, see: | |
# https://github.com/actions/stale | |
name: Close old issues | |
on: | |
schedule: | |
- cron: "0 0 * * *" # 매일 자정에 실행 | |
jobs: | |
close-issues: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Close old issues | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const now = new Date(); | |
const sevenDaysAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000); | |
const { data: openIssues } = await github.rest.issues.listForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open', | |
labels: "검토 중" | |
}); | |
for (const issue of openIssues) { | |
if (new Date(issue.created_at) < sevenDaysAgo) { | |
await github.rest.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue.number, | |
label: [ | |
'검토 완료' | |
], | |
state: 'closed', | |
state_reason: 'completed' | |
}); | |
await github.rest.repos.createDispatchEvent({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
event_type: "issue_close", | |
client_payload: { | |
issue_number: issue.number, | |
closed_at : new Date().toISOString(), | |
} | |
}); | |
} | |
} |