Skip to content

Commit 5d7930b

Browse files
committed
ci: check prs
1 parent e1adcc7 commit 5d7930b

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: PR Check πŸ””
2+
3+
on:
4+
schedule:
5+
# 맀일 μ˜€μ „ 10μ‹œ, μ˜€ν›„ 6μ‹œ (KST κΈ°μ€€, UTCλ‘œλŠ” 1μ‹œ, 9μ‹œ)
6+
- cron: "0 1,9 * * *"
7+
workflow_dispatch:
8+
pull_request:
9+
10+
jobs:
11+
check-all-prs:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
issues: write # PR λŒ“κΈ€ μž‘μ„± κΆŒν•œ
16+
pull-requests: write # PR 정보 읽기 κΆŒν•œ
17+
18+
steps:
19+
- name: Get all open PRs
20+
id: get-prs
21+
run: |
22+
echo "πŸ“‹ Open PR λͺ©λ‘ 쑰회 쀑..."
23+
prs=$(gh pr list \
24+
--repo ${{ github.repository }} \
25+
--state open \
26+
--json number,labels \
27+
--limit 100)
28+
29+
echo "prs=$prs" >> $GITHUB_OUTPUT
30+
echo "Open PR 수: $(echo $prs | jq 'length')"
31+
env:
32+
GH_TOKEN: ${{ github.token }}
33+
34+
- name: Check Week settings for all PRs
35+
run: |
36+
prs='${{ steps.get-prs.outputs.prs }}'
37+
WORKER_URL="https://dalestudy.daleseo.workers.dev"
38+
repo_owner="${{ github.repository_owner }}"
39+
repo_name="${{ github.event.repository.name }}"
40+
41+
echo "$prs" | jq -c '.[]' | while read -r pr; do
42+
pr_number=$(echo $pr | jq -r '.number')
43+
labels=$(echo $pr | jq -r '.labels[].name' | tr '\n' ',')
44+
45+
# maintenance 라벨이 있으면 μŠ€ν‚΅
46+
if echo "$labels" | grep -q "maintenance"; then
47+
echo "⏭️ PR #$pr_number: maintenance 라벨 - μŠ€ν‚΅"
48+
continue
49+
fi
50+
51+
echo ""
52+
echo "πŸ” PR #$pr_number 검사 쀑..."
53+
54+
# GitHub App으둜 Week μ„€μ • 확인
55+
response=$(curl -s -X POST https://dalestudy.daleseo.workers.dev \
56+
-H "Content-Type: application/json" \
57+
-d "{\"pr_number\": $pr_number, \"repo_owner\": \"$repo_owner\", \"repo_name\": \"$repo_name\"}")
58+
59+
week=$(echo $response | jq -r '.week')
60+
project_found=$(echo $response | jq -r '.project_found')
61+
62+
echo " Week: $week"
63+
echo " Project found: $project_found"
64+
65+
# Week 섀정이 μ—†μœΌλ©΄ λŒ“κΈ€ μž‘μ„±
66+
if [ "$week" = "null" ] || [ -z "$week" ]; then
67+
echo " ⚠️ Week μ„€μ • λˆ„λ½ - λŒ“κΈ€ μž‘μ„± μ‹œλ„"
68+
69+
# GitHub App으둜 λŒ“κΈ€ μž‘μ„± (jq둜 μ•ˆμ „ν•˜κ²Œ JSON 생성)
70+
comment_body="## ⚠️ Week 섀정이 λˆ„λ½λ˜μ—ˆμŠ΅λ‹ˆλ‹€"$'\n\n'"ν”„λ‘œμ νŠΈμ—μ„œ Weekλ₯Ό μ„€μ •ν•΄μ£Όμ„Έμš”!"$'\n\n'"### μ„€μ • 방법"$'\n'"1. PR 우츑의 \`Projects\` μ„Ήμ…˜μ—μ„œ \`λ¦¬νŠΈμ½”λ“œ μŠ€ν„°λ””\` μ˜† λ“œλ‘­λ‹€μš΄(β–Ό) 클릭"$'\n'"2. ν˜„μž¬ μ£Όμ°¨λ₯Ό μ„ νƒν•΄μ£Όμ„Έμš” (예: \`Week 14(current)\` λ˜λŠ” \`Week 14\`)"$'\n\n'"πŸ“š [μžμ„Έν•œ κ°€μ΄λ“œ 보기](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C#pr-%EC%9E%91%EC%84%B1%EB%B2%95)"$'\n\n'"---"$'\n'"πŸ€– 이 λŒ“κΈ€μ€ GitHub App을 톡해 μžλ™μœΌλ‘œ μž‘μ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€."
71+
72+
comment_response=$(jq -n \
73+
--arg pr_num "$pr_number" \
74+
--arg owner "$repo_owner" \
75+
--arg repo "$repo_name" \
76+
--arg body "$comment_body" \
77+
'{pr_number: ($pr_num | tonumber), repo_owner: $owner, repo_name: $repo, comment_body: $body}' | \
78+
curl -s -X POST "$WORKER_URL/comment" \
79+
-H "Content-Type: application/json" \
80+
-d @-)
81+
82+
if echo "$comment_response" | jq -e '.success' > /dev/null 2>&1; then
83+
echo " βœ… λŒ“κΈ€ μž‘μ„± μ™„λ£Œ"
84+
else
85+
echo " ❌ λŒ“κΈ€ μž‘μ„± μ‹€νŒ¨: $comment_response"
86+
fi
87+
else
88+
echo " βœ… Week μ„€μ • 정상: $week"
89+
fi
90+
done
91+
env:
92+
GH_TOKEN: ${{ github.token }}
93+
94+
- name: Summary
95+
run: |
96+
echo "## 🎯 Week μ„€μ • 체크 μ™„λ£Œ" >> $GITHUB_STEP_SUMMARY
97+
echo "" >> $GITHUB_STEP_SUMMARY
98+
echo "λͺ¨λ“  Open PR의 Week 섀정을 ν™•μΈν–ˆμŠ΅λ‹ˆλ‹€." >> $GITHUB_STEP_SUMMARY
99+
echo "" >> $GITHUB_STEP_SUMMARY
100+
echo "- Week 섀정이 μ—†λŠ” PR에 μžλ™μœΌλ‘œ λŒ“κΈ€μ„ μž‘μ„±ν–ˆμŠ΅λ‹ˆλ‹€." >> $GITHUB_STEP_SUMMARY
101+
echo "- λ‹€μŒ 체크: $(date -u -d '+1 hour' +'%Y-%m-%d %H:00 UTC')" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
Β (0)