|
| 1 | +name: Star Reminder for Contributors |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + star-reminder: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + pull-requests: write |
| 12 | + contents: read |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Check star status and send reminder |
| 16 | + uses: actions/github-script@v7 |
| 17 | + with: |
| 18 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 19 | + script: | |
| 20 | + const { owner, repo } = context.repo; |
| 21 | + const contributor = context.payload.pull_request.user.login; |
| 22 | + const prNumber = context.payload.pull_request.number; |
| 23 | +
|
| 24 | + console.log(`Checking star status for contributor: ${contributor}`); |
| 25 | +
|
| 26 | + // Use GraphQL to check if user starred the repo |
| 27 | + const query = ` |
| 28 | + query($owner: String!, $repo: String!, $user: String!) { |
| 29 | + user(login: $user) { |
| 30 | + starredRepositories(first: 100, orderBy: {field: STARRED_AT, direction: DESC}) { |
| 31 | + nodes { |
| 32 | + nameWithOwner |
| 33 | + } |
| 34 | + pageInfo { |
| 35 | + hasNextPage |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + `; |
| 41 | +
|
| 42 | + try { |
| 43 | + const result = await github.graphql(query, { |
| 44 | + owner: owner, |
| 45 | + repo: repo, |
| 46 | + user: contributor |
| 47 | + }); |
| 48 | + |
| 49 | + const repoFullName = `${owner}/${repo}`; |
| 50 | + const hasStarred = result.user.starredRepositories.nodes.some( |
| 51 | + starredRepo => starredRepo.nameWithOwner === repoFullName |
| 52 | + ); |
| 53 | + |
| 54 | + console.log(`Has ${contributor} starred ${repoFullName}? ${hasStarred}`); |
| 55 | + |
| 56 | + if (!hasStarred) { |
| 57 | + // Check if we've already sent a reminder on this PR |
| 58 | + const comments = await github.rest.issues.listComments({ |
| 59 | + owner: owner, |
| 60 | + repo: repo, |
| 61 | + issue_number: prNumber |
| 62 | + }); |
| 63 | + |
| 64 | + const existingReminder = comments.data.find(comment => |
| 65 | + comment.user.type === 'Bot' && |
| 66 | + comment.body.includes('awesome contributor! 🌟') |
| 67 | + ); |
| 68 | + |
| 69 | + if (!existingReminder) { |
| 70 | + const message = `Dear @${contributor} |
| 71 | +
|
| 72 | + awesome contributor! 🌟 We noticed you contributed to #DevDisplay but forgot to star the repo. It's like making an amazing sandwich and forgetting to take a bite! |
| 73 | +
|
| 74 | + I think our repo's feeling a little lonely without your ⭐️ Can you help us out? 🤗 |
| 75 | +
|
| 76 | + > **Star the repo by clicking the ⭐ button at the top of this page!**`; |
| 77 | +
|
| 78 | + await github.rest.issues.createComment({ |
| 79 | + owner: owner, |
| 80 | + repo: repo, |
| 81 | + issue_number: prNumber, |
| 82 | + body: message |
| 83 | + }); |
| 84 | + |
| 85 | + console.log(`✅ Sent star reminder to ${contributor}`); |
| 86 | + } else { |
| 87 | + console.log(`ℹ️ Star reminder already sent to ${contributor} on this PR`); |
| 88 | + } |
| 89 | + } else { |
| 90 | + console.log(`⭐ ${contributor} has already starred the repository - no reminder needed!`); |
| 91 | + } |
| 92 | + } catch (error) { |
| 93 | + console.log(`❌ Error checking star status: ${error.message}`); |
| 94 | + |
| 95 | + // If we can't determine star status, we'll skip sending the reminder |
| 96 | + // to avoid spamming users who might have already starred |
| 97 | + console.log(`⚠️ Skipping reminder due to API error`); |
| 98 | + } |
0 commit comments