test_issue2 #76
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: | |
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 | |
id: check-tasks | |
run: | | |
ISSUE_NUMBER="${{ github.event.issue.number }}" | |
OWNER="${{ github.repository_owner }}" | |
REPO="${{ github.repository }}" | |
GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" | |
# 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"}' | |
sleep 5 # GitHub API가 상태 변경을 반영하는 데 시간이 필요할 수 있음 | |
# 이슈의 최신 상태 가져오기 | |
ISSUE_STATE=$(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 '.state') | |
# 이슈 상태 출력 | |
echo "Issue #$ISSUE_NUMBER is now $ISSUE_STATE." | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |