Skip to content

Commit 7f4af99

Browse files
authored
Update first-pr-merged.yml
1 parent 035567c commit 7f4af99

1 file changed

Lines changed: 33 additions & 40 deletions

File tree

.github/workflows/first-pr-merged.yml

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,60 @@ on:
66

77
jobs:
88
welcome-on-merge:
9-
# Only run if the PR was actually merged, not just closed
109
if: github.event.pull_request.merged == true
1110
runs-on: ubuntu-latest
1211
permissions:
1312
pull-requests: write
13+
issues: write
14+
1415
steps:
1516
- name: Thank contributor and ask for star
1617
uses: actions/github-script@v7
1718
with:
1819
script: |
19-
// Sleep for 3 seconds to ensure the API reflects the PR merge
2020
await new Promise(resolve => setTimeout(resolve, 3000));
2121
2222
const { owner, repo } = context.repo;
2323
const creator = context.payload.pull_request.user.login;
24+
const currentPrNumber = context.payload.pull_request.number;
2425
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, {
2727
owner,
2828
repo,
2929
state: 'closed',
30-
creator: creator
30+
per_page: 100
3131
});
3232
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+
);
3537
36-
// Determine the case and generate appropriate message
3738
let message;
3839
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');
6258
}
6359
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

Comments
 (0)