|
6 | 6 |
|
7 | 7 | jobs: |
8 | 8 | welcome-on-merge: |
9 | | - # Only run if the PR was actually merged, not just closed |
10 | 9 | if: github.event.pull_request.merged == true |
11 | 10 | runs-on: ubuntu-latest |
12 | 11 | permissions: |
13 | 12 | pull-requests: write |
| 13 | + issues: write |
| 14 | + |
14 | 15 | steps: |
15 | 16 | - name: Thank contributor and ask for star |
16 | 17 | uses: actions/github-script@v7 |
17 | 18 | with: |
18 | 19 | script: | |
19 | | - // Sleep for 3 seconds to ensure the API reflects the PR merge |
20 | 20 | await new Promise(resolve => setTimeout(resolve, 3000)); |
21 | 21 |
|
22 | 22 | const { owner, repo } = context.repo; |
23 | 23 | const creator = context.payload.pull_request.user.login; |
| 24 | + const currentPrNumber = context.payload.pull_request.number; |
24 | 25 |
|
25 | | - // Fetch all merged PRs by this user |
26 | | - const response = await github.rest.pulls.list({ |
| 26 | + const prs = await github.paginate(github.rest.pulls.list, { |
27 | 27 | owner, |
28 | 28 | repo, |
29 | 29 | state: 'closed', |
30 | | - creator: creator |
| 30 | + per_page: 100 |
31 | 31 | }); |
32 | 32 |
|
33 | | - // Filter to ensure we only count merged PRs |
34 | | - const mergedPrs = response.data.filter(pr => pr.merged_at !== null); |
| 33 | + const mergedPrsByUser = prs.filter(pr => |
| 34 | + pr.user.login === creator && |
| 35 | + pr.merged_at !== null |
| 36 | + ); |
35 | 37 |
|
36 | | - // Determine the case and generate appropriate message |
37 | 38 | let message; |
38 | 39 |
|
39 | | - if (mergedPrs.length <= 1) { |
40 | | - message = ` |
41 | | - 🎊 **Welcome, @${creator}!** Your first contribution has been merged! 🚀 |
42 | | - |
43 | | - Thank you for helping improve the project! If you find this tool useful, please consider giving us a ⭐ **star on GitHub**—it helps more developers find our work and motivates us to keep improving! |
44 | | - `; |
45 | | - } |
46 | | - // CASE 2: First merged PR + Hasn't starred |
47 | | - else if (mergedPrs.length <= 3) { |
48 | | - message = ` |
49 | | - ✨ **Thank you, @${creator}!** Another great contribution merged! 🚀 |
50 | | - |
51 | | - We truly appreciate your continued support! If you find this tool useful, please consider giving us a ⭐ **star on GitHub**—it helps more developers find our work and motivates us to keep improving! |
52 | | - `; |
53 | | - } |
54 | | -
|
55 | | - // CASE 4: Multiple merged PRs + Hasn't starred |
56 | | - else if (mergedPrs.length > 3) { |
57 | | - message = ` |
58 | | - ✨ **Thank you, @${creator}!** Another great contribution merged! 🚀 |
59 | | - |
60 | | - You've been a fantastic contributor! We truly appreciate your continued support. |
61 | | - `; |
| 40 | + if (mergedPrsByUser.length === 1) { |
| 41 | + message = [ |
| 42 | + `🎊 **Welcome, @${creator}!** Your first contribution has been merged! 🚀`, |
| 43 | + ``, |
| 44 | + `Thank you for helping improve the project! If you find this tool useful, please consider giving us a ⭐ **star on GitHub**—it helps more developers find our work and motivates us to keep improving!` |
| 45 | + ].join('\n'); |
| 46 | + } else if (mergedPrsByUser.length <= 3) { |
| 47 | + message = [ |
| 48 | + `✨ **Thank you, @${creator}!** Another great contribution merged! 🚀`, |
| 49 | + ``, |
| 50 | + `We truly appreciate your continued support! If you find this tool useful, please consider giving us a ⭐ **star on GitHub**—it helps more developers find our work and motivates us to keep improving!` |
| 51 | + ].join('\n'); |
| 52 | + } else { |
| 53 | + message = [ |
| 54 | + `✨ **Thank you, @${creator}!** Another great contribution merged! 🚀`, |
| 55 | + ``, |
| 56 | + `You've been a fantastic contributor! We truly appreciate your continued support.` |
| 57 | + ].join('\n'); |
62 | 58 | } |
63 | 59 |
|
64 | | - // Post the comment if a message was generated |
65 | | - if (message) { |
66 | | - await github.rest.issues.createComment({ |
67 | | - owner, |
68 | | - repo, |
69 | | - issue_number: context.payload.pull_request.number, |
70 | | - body: message |
71 | | - }); |
72 | | - } |
| 60 | + await github.rest.issues.createComment({ |
| 61 | + owner, |
| 62 | + repo, |
| 63 | + issue_number: currentPrNumber, |
| 64 | + body: message |
| 65 | + }); |
0 commit comments