From a937f77d0928250a35682b0f5c9629b0020a29d5 Mon Sep 17 00:00:00 2001 From: Siddheya Kulkarni <115717746+Asymtode712@users.noreply.github.com> Date: Sat, 25 May 2024 00:16:31 +0530 Subject: [PATCH 1/2] Create close-old-issue.yml --- .github/workflows/close-old-issue.yml | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/close-old-issue.yml diff --git a/.github/workflows/close-old-issue.yml b/.github/workflows/close-old-issue.yml new file mode 100644 index 0000000..2984191 --- /dev/null +++ b/.github/workflows/close-old-issue.yml @@ -0,0 +1,37 @@ +name: Close Old Issues +on: + schedule: + - cron: "0 0 * * *" + +jobs: + close-issues: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Close Old Issues + run: | + open_issues=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/issues?state=open" \ + | jq -r '.[] | .number') + for issue in $open_issues; do + # Get the last updated timestamp of the issue + last_updated=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/issues/$issue" \ + | jq -r '.updated_at') + days_since_update=$(( ( $(date +%s) - $(date -d "$last_updated" +%s) ) / 86400 )) + if [ $days_since_update -gt 30 ]; then + curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{"state":"closed"}' \ + "https://api.github.com/repos/${{ github.repository }}/issues/$issue" + + # Add a comment explaining when the issue will be closed + curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{"body":"This issue has been automatically closed because it has been inactive for more than 30 days. If you believe this is still relevant, feel free to reopen it or create a new one. Thank you!"}' \ + "https://api.github.com/repos/${{ github.repository }}/issues/$issue/comments" + fi + done From bb4b325f9d5dfbe52b21d6dd3ae9791ecfc01231 Mon Sep 17 00:00:00 2001 From: Siddheya Kulkarni <115717746+Asymtode712@users.noreply.github.com> Date: Mon, 27 May 2024 16:06:36 +0530 Subject: [PATCH 2/2] Update close-old-issue.yml --- .github/workflows/close-old-issue.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/close-old-issue.yml b/.github/workflows/close-old-issue.yml index 2984191..ac913ef 100644 --- a/.github/workflows/close-old-issue.yml +++ b/.github/workflows/close-old-issue.yml @@ -22,7 +22,7 @@ jobs: "https://api.github.com/repos/${{ github.repository }}/issues/$issue" \ | jq -r '.updated_at') days_since_update=$(( ( $(date +%s) - $(date -d "$last_updated" +%s) ) / 86400 )) - if [ $days_since_update -gt 30 ]; then + if [ $days_since_update -gt 180 ]; then curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Accept: application/vnd.github.v3+json" \ -d '{"state":"closed"}' \ @@ -31,7 +31,7 @@ jobs: # Add a comment explaining when the issue will be closed curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Accept: application/vnd.github.v3+json" \ - -d '{"body":"This issue has been automatically closed because it has been inactive for more than 30 days. If you believe this is still relevant, feel free to reopen it or create a new one. Thank you!"}' \ + -d '{"body":"This issue has been automatically closed because it has been inactive for more than 6 months. If you believe this is still relevant, feel free to reopen it or create a new one. Thank you!"}' \ "https://api.github.com/repos/${{ github.repository }}/issues/$issue/comments" fi done