From 00a3c86af35c0b1af013d125e3ecea35d72d71c8 Mon Sep 17 00:00:00 2001 From: Geonhyuk Seo Date: Tue, 19 Nov 2024 17:45:08 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Setting(.github/workflows):=20gi?= =?UTF-8?q?thub=20action=EC=9D=84=20=ED=86=B5=ED=95=B4=20=EC=97=B4?= =?UTF-8?q?=EB=A6=B0=20PR=EC=97=90=20=EB=8C=80=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EC=9E=90=EB=8F=99=EC=9C=BC=EB=A1=9C=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=EC=9D=84=20=EB=B3=B4=EB=82=B4=EC=A3=BC=EA=B2=8C=EB=81=94=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ISSUES CLOSED: #80 --- .github/workflows/check-open-prs.yml | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/check-open-prs.yml diff --git a/.github/workflows/check-open-prs.yml b/.github/workflows/check-open-prs.yml new file mode 100644 index 00000000..2d107a2c --- /dev/null +++ b/.github/workflows/check-open-prs.yml @@ -0,0 +1,60 @@ +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.G_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 }}' + + 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 -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