diff --git a/.github/workflows/d-day-labeler.yml b/.github/workflows/d-day-labeler.yml new file mode 100644 index 000000000..355664e3d --- /dev/null +++ b/.github/workflows/d-day-labeler.yml @@ -0,0 +1,100 @@ +name: Update D-n Labels + +on: + schedule: + - cron: '0 0 * * *' # UTC 00:00 = KST 09:00 + +permissions: + contents: read + pull-requests: write + +jobs: + d-day-labeler: + runs-on: ubuntu-latest + + steps: + # Step A: 업데이트 전 상태 스냅샷 + - name: Snapshot BEFORE d-day update + id: before + uses: actions/github-script@v7 + with: + script: | + const pulls = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: "open", + base: "dev" + }); + + const before = {}; + for (const pr of pulls.data) { + const d = pr.labels.find(l => /^D-\d+$/.test(l.name)); + if (d) before[pr.number] = d.name; + } + + return before; + + # Step B: D-n 라벨 업데이트 + - name: Update D-n Labels + uses: naver/d-day-labeler@latest + with: + token: ${{ secrets.GITHUB_TOKEN }} + + # Step C: 업데이트 후 상태 + diff 판단 + - name: Detect D-2→D-1 / D-1→D-0 + id: detect + uses: actions/github-script@v7 + with: + script: | + const before = JSON.parse(`${{ steps.before.outputs.result }}`); + + const pulls = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: "open", + base: "dev" + }); + + const notify = []; + + for (const pr of pulls.data) { + const afterLabel = pr.labels.find(l => /^D-\d+$/.test(l.name)); + if (!afterLabel) continue; + + const after = afterLabel.name; + const prev = before[pr.number]; + + if ( + (prev === "D-2" && after === "D-1") || + (prev === "D-1" && after === "D-0") + ) { + notify.push({ + number: pr.number, + title: pr.title, + url: pr.html_url, + prefix: after === "D-0" ? "🚨 [D-0]" : "⏳ [D-1]" + }); + } + } + + return notify; + + # Discord 알림 + - name: Send Discord notification + if: ${{ steps.detect.outputs.result != '[]' }} + env: + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_PR_REMINDER_WEBHOOK_URL }} + run: | + content=$(echo '${{ steps.detect.outputs.result }}' | jq -r ' + .[] | + (.prefix + " PR #" + (.number|tostring) + ": " + .title) + "\n" + .url + "\n" + ') + + jq -n \ + --arg title "⏰ 마감 임박 PR 알림" \ + --arg body "$content" \ + '{content: ($title + "\n\n" + $body)}' \ + | curl -X POST \ + -H "Content-Type: application/json" \ + -d @- \ + "$DISCORD_WEBHOOK_URL" diff --git a/.github/workflows/simple-labeler.yml b/.github/workflows/simple-labeler.yml new file mode 100644 index 000000000..524c74494 --- /dev/null +++ b/.github/workflows/simple-labeler.yml @@ -0,0 +1,21 @@ +name: Simple Labeler + +on: + pull_request: + types: [opened, ready_for_review] + branches: + - dev + +permissions: + pull-requests: write + +jobs: + simple-labeler: + runs-on: [ubuntu-latest] + steps: + - name: Label to PR + uses: naver/simple-labeler@latest + with: + token: ${{ secrets.GITHUB_TOKEN }} + labels: "D-4" + duplicate: "D-*"