-
Notifications
You must be signed in to change notification settings - Fork 3
66 lines (54 loc) · 1.92 KB
/
check-open-prs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Check Open PRs and Notify Slack
on:
schedule:
# 매 1시간마다 실행
- cron: '0 * * * *'
workflow_dispatch: # 수동 실행을 위한 트리거
inputs:
force_notify:
description: "Force Slack notification"
jobs:
notify_open_prs:
runs-on: ubuntu-latest
steps:
# 1. GitHub 리포지토리 체크아웃
- name: Checkout repository
uses: actions/checkout@v3
# 2. PR 데이터 수집
- name: Fetch Open PRs with Reviewers
id: fetch_prs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Fetching open PRs with reviewers..."
# gh CLI를 사용해 PR 목록 가져오기
prs=$(gh pr list --json number,title,url,reviewRequests --jq '.[] | select(.reviewRequests | length > 0)')
if [ -z "$prs" ]; then
echo "No PRs with reviewers found."
echo "prs_output=" > $GITHUB_ENV
exit 0
fi
echo "Found PRs: $prs"
echo "prs_output=$prs" >> $GITHUB_ENV
# 3. Slack 알림 전송
- name: Notify Slack
if: env.prs_output != ''
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
PRS_OUTPUT: ${{ env.prs_output }}
run: |
echo "Preparing Slack notification..."
if [ -z "$PRS_OUTPUT" ]; then
echo "No PRs to notify about."
exit 0
fi
# Slack 메시지 작성
message=":warning: *Open Pull Requests with Reviewers:*"
echo "$PRS_OUTPUT" | jq -c '.[]' | while read -r pr; do
title=$(echo $pr | jq -r '.title')
url=$(echo $pr | jq -r '.url')
reviewers=$(echo $pr | jq -r '.reviewRequests | map(.login) | join(", ")')
message+="\n- <$url|$title> (Reviewers: $reviewers)"
done
# Slack 메시지 전송
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"$message\"}" $SLACK_WEBHOOK_URL