検索クエリを使わずに抽出 #8
Workflow file for this run
This file contains hidden or 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: Weekly Pages Update Digest | |
| on: | |
| push: | |
| branches: | |
| - feature/add-notification | |
| schedule: | |
| # 毎週月曜日の朝 9:00 (JST) | |
| - cron: '0 0 * * 1' | |
| workflow_dispatch: | |
| jobs: | |
| digest-notification: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Collect Merged PRs for src/pages | |
| id: collect-prs | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # 基準となる日付を取得 (例: 7日前) | |
| SINCE_DATE=$(date -d "7 days ago" +%Y-%m-%dT%H:%M:%SZ) | |
| echo "Target since: $SINCE_DATE" | |
| # 1. 検索クエリを使わず、直近のマージ済みPRを多めに取得 (100件) | |
| # 2. jq で「指定の日付以降」かつ「src/pages/ を含む」ものを抽出 | |
| PR_DATA=$(gh pr list --base main --state merged --json number,title,url,mergedAt,files --limit 100 \ | |
| | jq -r --arg since "$SINCE_DATE" ' | |
| .[] | select(.mergedAt >= $since) | |
| | select(.files[].path | startswith("src/pages/")) | |
| | {number, title, url}' \ | |
| | jq -s 'unique_by(.number)') | |
| COUNT=$(echo "$PR_DATA" | jq '. | length') | |
| echo "Found $COUNT matching PRs." | |
| if [ "$COUNT" -gt 0 ]; then | |
| # Slack用メッセージ生成 | |
| PR_LIST=$(echo "$PR_DATA" | jq -r '.[] | "• <\(.url)|#\(.number)>: \(.title)"') | |
| { | |
| echo "PR_MESSAGE<<EOF" | |
| echo "$PR_LIST" | |
| echo "EOF" | |
| } >> $GITHUB_ENV | |
| fi | |
| echo "count=$COUNT" >> $GITHUB_OUTPUT | |
| - name: Send Slack Notification | |
| uses: rtCamp/action-slack-notify@v2 | |
| env: | |
| SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_CE }} | |
| SLACK_CHANNEL: 'notify-update' | |
| SLACK_USERNAME: 'Weekly Pages Digest' | |
| SLACK_COLOR: ${{ steps.collect-prs.outputs.count > 0 && '#36a64f' || '#cccccc' }} | |
| SLACK_TITLE: 'Weekly Update: src/pages/' | |
| SLACK_MESSAGE: | | |
| ${{ steps.collect-prs.outputs.count > 0 | |
| && format('先週、src/pages/ に以下の変更がマージされました:\n\n{0}', env.PR_MESSAGE) | |
| || '先週、src/pages/ 配下の変更はありませんでした。' }} |