Check Open PRs and Notify Slack #5
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: 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 | |
run: | | |
# 모든 열린 PR 가져오기 | |
prs=$(gh pr list --json number,title,url,reviewRequests --jq '.[] | select(.reviewRequests | length > 0)') | |
echo "Found PRs: $prs" | |
# JSON 데이터를 Action output으로 저장 | |
echo "::set-output name=prs::$prs" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub 기본 제공 토큰 | |
# 3. Slack 알림 전송 | |
- name: Notify Slack | |
if: steps.fetch_prs.outputs.prs != '' # 열린 PR이 있을 때만 실행 | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # Slack 웹훅 URL | |
run: | | |
echo "Preparing Slack notification..." | |
prs_json='${{ steps.fetch_prs.outputs.prs }}' | |
# prs_json 값 확인 | |
echo "Debug: prs_json = $prs_json" | |
if [ -z "$prs_json" ]; then | |
echo "No PRs to notify about." | |
exit 0 | |
fi | |
# Slack 메시지 작성 | |
message=":warning: *Open Pull Requests with Reviewers:*" | |
echo $prs_json | jq -r '.[] | "- <\(.url)|\(.title)> (Reviewers: \(.reviewRequests | map(.login) | join(", ")))"' | while read -r line; do | |
message+="$line" | |
done | |
# Slack 메시지 확인 | |
echo "Debug: message = $message" | |
# Slack 메시지 전송 | |
curl -v -X POST -H 'Content-type: application/json' --data "{\"text\":\"$message\"}" $SLACK_WEBHOOK_URL |