Daily Auto Close Inactive Tickets #23
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 file is part of PixelFlasher https://github.com/badabing2005/PixelFlasher | |
# | |
# Copyright (C) 2024 Badabing2005 | |
# SPDX-License-Identifier: AGPL-3.0-or-later | |
# | |
# This program is free software: you can redistribute it and/or modify it under | |
# the terms of the GNU Affero General Public License as published by the Free | |
# Software Foundation, either version 3 of the License, or (at your option) any | |
# later version. | |
# | |
# This program is distributed in the hope that it will be useful, but WITHOUT | |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License | |
# for more details. | |
# | |
# You should have received a copy of the GNU Affero General Public License | |
# along with this program. If not, see <https://www.gnu.org/licenses/>. | |
# | |
# Also add information on how to contact you by electronic and paper mail. | |
# | |
# If your software can interact with users remotely through a computer network, | |
# you should also make sure that it provides a way for users to get its source. | |
# For example, if your program is a web application, its interface could | |
# display a "Source" link that leads users to an archive of the code. There are | |
# many ways you could offer source, and different solutions will be better for | |
# different programs; see section 13 for the specific requirements. | |
# | |
# You should also get your employer (if you work as a programmer) or school, if | |
# any, to sign a "copyright disclaimer" for the program, if necessary. For more | |
# information on this, and how to apply and follow the GNU AGPL, see | |
# <https://www.gnu.org/licenses/>. | |
name: Daily Auto Close Inactive Tickets | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs every day at midnight UTC | |
workflow_dispatch: | |
jobs: | |
close_tickets: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Git | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
shell: bash | |
- name: Calculate date threshold | |
id: calculate_date | |
run: | | |
date_threshold=$(date -u -d '7 days ago' +%s) | |
echo "date_threshold=$date_threshold" >> $GITHUB_ENV | |
echo "Debug: Date threshold: $date_threshold" | |
shell: bash | |
- name: List all open issues with tag 'need more info' | |
id: list_open_issues_with_tag | |
run: | | |
echo "Getting all open issues with tag: 'need more info' ..." | |
open_issues_with_tag_json=$(curl -s -H 'Accept: application/vnd.github.v3+json' -H "Authorization: Bearer ${{ secrets.REPO_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/issues?labels=need%20more%20info&state=open") | |
echo "Debug: All Open Issues with Tag (need more info): $open_issues_with_tag_json" | |
filtered_issue_numbers=$(jq --arg threshold "${{ env.date_threshold }}" '.[] | select((.updated_at | strptime("%Y-%m-%dT%H:%M:%SZ") | mktime) < ($threshold | tonumber)) | .number' <<< "$open_issues_with_tag_json") | |
echo "Debug: Filtered Issue Numbers: $filtered_issue_numbers" | |
echo "filtered_issue_numbers=$filtered_issue_numbers" >> $GITHUB_ENV | |
shell: bash | |
- name: Iterate and close filtered issues | |
run: | | |
closed_issues="" | |
for issue_number in ${{ env.filtered_issue_numbers }}; do | |
echo "Adding a comment to issue $issue_number" | |
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.REPO_TOKEN }}" -d '{"body": "This issue was automatically closed by Github bot, due to inactivity."}' "https://api.github.com/repos/${{ github.repository }}/issues/$issue_number/comments" | |
echo "Closing issue $issue_number" | |
curl -X PATCH -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.REPO_TOKEN }}" -d '{"state": "closed"}' "https://api.github.com/repos/${{ github.repository }}/issues/$issue_number" | |
closed_issues="$closed_issues $issue_number" | |
done | |
echo "Debug: Closed Issues: $closed_issues" | |
shell: bash |