diff --git a/.github/workflows/first-pr-merged.yml b/.github/workflows/first-pr-merged.yml index e6c2d30..ef45395 100644 --- a/.github/workflows/first-pr-merged.yml +++ b/.github/workflows/first-pr-merged.yml @@ -18,10 +18,10 @@ jobs: script: | // Sleep for 3 seconds to ensure the API reflects the PR merge await new Promise(resolve => setTimeout(resolve, 3000)); - + const { owner, repo } = context.repo; const creator = context.payload.pull_request.user.login; - + // Fetch all merged PRs by this user const response = await github.rest.pulls.list({ owner, @@ -29,18 +29,61 @@ jobs: state: 'closed', creator: creator }); - + // Filter to ensure we only count merged PRs const mergedPrs = response.data.filter(pr => pr.merged_at !== null); - - // If this is their first successfully merged PR - if (mergedPrs.length === 1) { - const message = ` - Congratulations @${creator}! 🎊 Your first contribution has been merged! πŸš€ - - 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! + + // Check if the user has starred the repo + let hasStarred = false; + try { + await github.rest.activity.checkRepoIsStarredByAuthenticatedUser({ + owner, + repo + }); + hasStarred = true; + } catch (error) { + // 404 means the user hasn't starred the repo + hasStarred = false; + } + + // Determine the case and generate appropriate message + let message; + + // CASE 1: First merged PR + Already starred + if (mergedPrs.length === 1 && hasStarred) { + message = ` + 🎊 **Welcome, @${creator}!** Your first contribution has been merged! πŸš€ + + Thank you so much for your support and for giving us a ⭐ star! It truly means a lot and helps other developers discover our project. We're excited to have you as part of our community! `; - + } + // CASE 2: First merged PR + Hasn't starred + else if (mergedPrs.length === 1 && !hasStarred) { + message = ` + 🎊 **Welcome, @${creator}!** Your first contribution has been merged! πŸš€ + + 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! + `; + } + // CASE 3: Multiple merged PRs + Already starred + else if (mergedPrs.length > 1 && hasStarred) { + message = ` + ✨ **Thank you, @${creator}!** Another great contribution merged! πŸš€ + + We truly appreciate your continued support and the ⭐ star you gave us. Your contributions are making a real difference! + `; + } + // CASE 4: Multiple merged PRs + Hasn't starred + else if (mergedPrs.length > 1 && !hasStarred) { + message = ` + ✨ **Thank you, @${creator}!** Another great contribution merged! πŸš€ + + You've been a fantastic contributor! If you haven't already, please consider giving us a ⭐ **star on GitHub**β€”it helps the project grow and lets other developers know about it! + `; + } + + // Post the comment if a message was generated + if (message) { await github.rest.issues.createComment({ owner, repo,