|
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($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 | | - user: contributor |
45 | | - }); |
46 | | - |
47 | | - const repoFullName = `${owner}/${repo}`; |
48 | | - const hasStarred = result.user.starredRepositories.nodes.some( |
49 | | - starredRepo => starredRepo.nameWithOwner === repoFullName |
50 | | - ); |
51 | | - |
52 | | - console.log(`Has ${contributor} starred ${repoFullName}? ${hasStarred}`); |
53 | | - |
54 | | - if (!hasStarred) { |
55 | | - // Check if we've already sent a reminder on this PR |
56 | | - const comments = await github.rest.issues.listComments({ |
57 | | - owner: owner, |
58 | | - repo: repo, |
59 | | - issue_number: prNumber |
60 | | - }); |
61 | | - |
62 | | - const existingReminder = comments.data.find(comment => |
63 | | - comment.user.type === 'Bot' && |
64 | | - comment.body.includes('awesome contributor! 🌟') |
65 | | - ); |
66 | | - |
67 | | - if (!existingReminder) { |
68 | | - const message = `Dear @${contributor} |
69 | | -
|
70 | | - 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! |
71 | | -
|
72 | | - I think our repo's feeling a little lonely without your ⭐️ Can you help us out? 🤗 |
73 | | -
|
74 | | - > **Star the repo by clicking the ⭐ button at the top of this page!**`; |
75 | | -
|
76 | | - await github.rest.issues.createComment({ |
77 | | - owner: owner, |
78 | | - repo: repo, |
79 | | - issue_number: prNumber, |
80 | | - body: message |
81 | | - }); |
82 | | - |
83 | | - console.log(`✅ Sent star reminder to ${contributor}`); |
84 | | - } else { |
85 | | - console.log(`ℹ️ Star reminder already sent to ${contributor} on this PR`); |
86 | | - } |
87 | | - } else { |
88 | | - console.log(`⭐ ${contributor} has already starred the repository - no reminder needed!`); |
89 | | - } |
90 | | - } catch (error) { |
91 | | - console.log(`❌ Error checking star status: ${error.message}`); |
92 | | - |
93 | | - // If we can't determine star status, we'll skip sending the reminder |
94 | | - // to avoid spamming users who might have already starred |
95 | | - console.log(`⚠️ Skipping reminder due to API error`); |
96 | | - } |
0 commit comments