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: Auto Close Issue when all tasks are completed | |
on: | |
issue_comment: | |
types: [created, edited] | |
issues: | |
types: [opened, edited] | |
jobs: | |
check-tasks-and-close-issue: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Check if all tasks are completed and close issue | |
run: | | |
ISSUE_BODY="${{ github.event.issue.body }}" | |
CHECKBOX_TOTAL=$(echo "$ISSUE_BODY" | grep -o "\- \[\( \)\|\(x\)\]" | wc -l) | |
CHECKBOX_COMPLETED=$(echo "$ISSUE_BODY" | grep -o "\- \[x\]" | wc -l) | |
if [ "$CHECKBOX_TOTAL" -ne "0" ] && [ "$CHECKBOX_TOTAL" -eq "$CHECKBOX_COMPLETED" ]; then | |
echo "All tasks are completed. Closing issue." | |
echo "Issue Number: ${{ github.event.issue.number }}" | |
echo "Issue Body: ${{ github.event.issue.body }}" | |
gh issue close "#${{ github.event.issue.number }}" | |
elif [ "$CHECKBOX_TOTAL" -eq "0" ]; then | |
echo "No tasks found. Skipping." | |
else | |
echo "Not all tasks are completed. Skipping." | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |