Skip to content

Commit

Permalink
Update check-open-prs.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
SeoGeonhyuk authored Nov 19, 2024
1 parent a36ef9c commit 4a27c4c
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions .github/workflows/check-open-prs.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: Check Open PRs and Notify Slack

on:
schedule:
# 매 1시간마다 실행
- cron: '0 * * * *'

workflow_dispatch: # 수동 실행을 위한 트리거
inputs:
force_notify:
Expand All @@ -15,7 +13,6 @@ on:
jobs:
notify_open_prs:
runs-on: ubuntu-latest

steps:
# 1. GitHub 리포지토리 체크아웃
- name: Checkout repository
Expand All @@ -26,42 +23,43 @@ jobs:
id: fetch_prs
run: |
# 모든 열린 PR 가져오기
prs=$(gh pr list --json number,title,url,reviewRequests --jq '.[0]')
prs=$(gh pr list --json number,title,url,reviewRequests --jq '.[] | select(.reviewRequests | length > 0)')
# PR 데이터 출력 (디버깅용)
echo "Found PRs: $prs"
# GITHUB_OUTPUT에 PR 데이터를 저장
echo "prs=$prs" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# 3. Slack 알림 전송
- name: Notify Slack
if: steps.fetch_prs.outputs.prs != '' # 열린 PR이 있을 때만 실행
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # Slack 웹훅 URL
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
echo "Preparing Slack notification..."
prs_json="${{ steps.fetch_prs.outputs.prs }}" # fetch_prs에서 출력된 데이터 사용
# JSON 데이터를 변수에 저장
prs_json='${{ steps.fetch_prs.outputs.prs }}'
# PR 데이터가 비어 있는지 확인
if [ -z "$prs_json" ]; then
echo "No PRs to notify about."
exit 0
fi
# Slack 메시지 작성
message=":rotating_light: *Review가 필요한 Pull Requests 목록*\n\n"
# PR 데이터 파싱 및 메시지 작성
echo "$prs_json" | jq -r '"🔹 *<\(.url)|\(.title)>*\n" +
" • 리뷰어: \(.reviewRequests[].login | join(", "))\n\n"' | while read -r line; do
echo "$prs_json" | jq -r '.[] | "🔹 *<\(.url)|\(.title)>*\n" +
" • 리뷰어: \(.reviewRequests | map(.login) | join(", "))\n\n"' | while read -r line; do
message+="$line"
done
# Slack 메시지 푸터 추가
message+=$'\n\n':point_right: 리뷰를 부탁드립니다!"
message+=$'\n\n'" :point_right: 리뷰를 부탁드립니다!"
# Slack 메시지 확인 (디버깅)
echo "Message to Slack: $message"
Expand All @@ -71,14 +69,3 @@ jobs:
-H 'Content-type: application/json' \
--data "{\"text\":\"$message\", \"mrkdwn\": true}" \
"$SLACK_WEBHOOK_URL"
# Slack 메시지 확인 (디버깅)
echo "Message to Slack: $message"
# Slack 메시지 전송
curl -X POST \
-H 'Content-type: application/json' \
--data "{\"text\":\"$message\", \"mrkdwn\": true}" \
$SLACK_WEBHOOK_URL

0 comments on commit 4a27c4c

Please sign in to comment.