Skip to content

Commit

Permalink
Update auto-close-issue.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
srlee056 authored Jan 31, 2024
1 parent aee1fe4 commit 445f5d6
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions .github/workflows/auto-close-issue.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Auto Close Issue when all tasks are completed

on:
issue_comment:
types: [created, edited]
issues:
types: [opened, edited]

Expand All @@ -21,16 +19,24 @@ jobs:
REPO="${{ github.repository }}"
GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}"
# API를 사용하여 이슈를 닫음
curl -L -X PATCH \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$OWNER/$REPO/issues/$ISSUE_NUMBER" \
-d '{"state":"closed"}'
# GitHub API를 사용하여 이슈의 내용 가져오기
BODY=$(curl -s \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$OWNER/$REPO/issues/$ISSUE_NUMBER" | jq -r '.body')
# 체크리스트 항목 확인
TOTAL_TASKS=$(echo "$BODY" | grep -o -E '\- \[ \]' | wc -l)
COMPLETED_TASKS=$(echo "$BODY" | grep -o -E '\- \[x\]' | wc -l)
# 모든 작업이 완료되었는지 확인
if [ "$TOTAL_TASKS" == "$COMPLETED_TASKS" ] && [ "$TOTAL_TASKS" -ne "0" ]; then
# API를 사용하여 이슈를 닫음
curl -s -X PATCH \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$OWNER/$REPO/issues/$ISSUE_NUMBER" \
-d '{"state":"closed"}'
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


0 comments on commit 445f5d6

Please sign in to comment.