From 26e0aabe72ed15ee71051630b495e150a96b9a1b Mon Sep 17 00:00:00 2001 From: Lee-Wonho <65912229+asuan99@users.noreply.github.com> Date: Sun, 10 Nov 2024 22:30:30 +0900 Subject: [PATCH] [Create] auto close old issues --- .github/workflows/stale.yml | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/stale.yml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..bca592c --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,39 @@ +# 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', + }); + + 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, + state: 'closed', + state_reason: 'not_planned' + }); + } + }