|
| 1 | +name: Monthly PR Report |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run on the first day of every month at 9:00 UTC |
| 6 | + - cron: '0 9 1 * *' |
| 7 | + workflow_dispatch: # Allow manual triggering |
| 8 | + |
| 9 | +permissions: |
| 10 | + issues: write |
| 11 | + pull-requests: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + report-prs: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Generate PR Report |
| 18 | + uses: actions/github-script@v7 |
| 19 | + with: |
| 20 | + script: | |
| 21 | + const issueNumber = 999; // TODO: Update this with the actual issue number |
| 22 | + |
| 23 | + // Fetch all open pull requests |
| 24 | + const { data: allPRs } = await github.rest.pulls.list({ |
| 25 | + owner: context.repo.owner, |
| 26 | + repo: context.repo.repo, |
| 27 | + state: 'open', |
| 28 | + per_page: 100 |
| 29 | + }); |
| 30 | + |
| 31 | + // Filter out PRs with SSC_propose_deferred label |
| 32 | + const prs = allPRs.filter(pr => |
| 33 | + !pr.labels.some(label => label.name === 'SSC_propose_deferred') |
| 34 | + ); |
| 35 | + |
| 36 | + // Group PRs by label |
| 37 | + const prsByLabel = new Map(); |
| 38 | + const nolabel = []; |
| 39 | + |
| 40 | + for (const pr of prs) { |
| 41 | + if (pr.labels.length === 0) { |
| 42 | + nolabel.push(pr); |
| 43 | + } else { |
| 44 | + for (const label of pr.labels) { |
| 45 | + // Skip the excluded label if it somehow wasn't filtered |
| 46 | + if (label.name === 'SSC_propose_deferred') continue; |
| 47 | + |
| 48 | + if (!prsByLabel.has(label.name)) { |
| 49 | + prsByLabel.set(label.name, []); |
| 50 | + } |
| 51 | + prsByLabel.get(label.name).push(pr); |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + // Sort labels alphabetically |
| 57 | + const sortedLabels = Array.from(prsByLabel.keys()).sort(); |
| 58 | + |
| 59 | + // Build the report |
| 60 | + let report = `Dear SSC members, here are the JEPs that require your attention this month:\n\n`; |
| 61 | + report += `## Monthly PR Report\n\n`; |
| 62 | + report += `Report generated on: ${new Date().toUTCString()}\n\n`; |
| 63 | + report += `**Total open PRs (excluding SSC_propose_deferred): ${prs.length}**\n\n`; |
| 64 | + report += `---\n\n`; |
| 65 | + |
| 66 | + // Add PRs grouped by label |
| 67 | + for (const label of sortedLabels) { |
| 68 | + const labelPRs = prsByLabel.get(label); |
| 69 | + report += `### 🏷️ ${label} (${labelPRs.length})\n\n`; |
| 70 | + |
| 71 | + for (const pr of labelPRs) { |
| 72 | + const age = Math.floor((Date.now() - new Date(pr.created_at)) / (1000 * 60 * 60 * 24)); |
| 73 | + report += `- #${pr.number} - ${pr.title} (@${pr.user.login}, ${age} days old)\n`; |
| 74 | + } |
| 75 | + report += `\n`; |
| 76 | + } |
| 77 | + |
| 78 | + // Add PRs without labels |
| 79 | + if (nolabel.length > 0) { |
| 80 | + report += `### 🔖 No Label (${nolabel.length})\n\n`; |
| 81 | + for (const pr of nolabel) { |
| 82 | + const age = Math.floor((Date.now() - new Date(pr.created_at)) / (1000 * 60 * 60 * 24)); |
| 83 | + report += `- #${pr.number} - ${pr.title} (@${pr.user.login}, ${age} days old)\n`; |
| 84 | + } |
| 85 | + report += `\n`; |
| 86 | + } |
| 87 | + |
| 88 | + // Post the report as a comment |
| 89 | + await github.rest.issues.createComment({ |
| 90 | + owner: context.repo.owner, |
| 91 | + repo: context.repo.repo, |
| 92 | + issue_number: issueNumber, |
| 93 | + body: report |
| 94 | + }); |
| 95 | + |
| 96 | + core.info(`Report posted to issue #${issueNumber}`); |
0 commit comments