Daily Auto Close Inactive Tickets #278
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
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 |