-
Notifications
You must be signed in to change notification settings - Fork 36
192 lines (171 loc) ยท 8.96 KB
/
greetings.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: Greet, Celebrate, and Encourage
on:
issues:
types:
- opened
- assigned
pull_request:
types:
- opened
pull_request_target:
types:
- closed
jobs:
greet:
name: Greet, Celebrate, and Encourage
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Check User Contributions
id: check_contributions
uses: actions/github-script@v7
with:
script: |
const user = context.payload.sender.login;
const [userIssues, userPulls] = await Promise.all([
github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
creator: user,
state: 'all'
}),
github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
creator: user
})
]);
const totalContributions = userIssues.data.length + userPulls.data.length;
console.log(`User: ${user}, Issues: ${userIssues.length}, PRs: ${userPulls.length}, Total: ${totalContributions}`);
core.setOutput('isFirstTime', totalContributions === 1);
core.setOutput('totalContributions', totalContributions);
- name: Post Personalized Greeting
if: ${{ github.event.action == 'opened' }}
uses: actions/github-script@v7
with:
script: |
const user = context.payload.sender.login;
const isIssue = !!context.payload.issue;
const isPR = !!context.payload.pull_request;
const isFirstTime = '${{ steps.check_contributions.outputs.isFirstTime }}' === 'true';
const totalContributions = parseInt('${{ steps.check_contributions.outputs.totalContributions }}');
let message = '';
if (isFirstTime) {
message = `๐ Welcome aboard, @${user}! ๐
We're excited to see your **first contribution** to **Notpad**! ๐
Every great project starts with contributors like you. ๐ก
Take a moment to check out our [CONTRIBUTING.md](https://github.com/Muhammed-Rahif/Notpad/blob/main/CONTRIBUTING.md) for tips and guidelines.
Feel free to explore, experiment, and engage with the community.
Your journey in open source starts here โ happy coding! ๐ฅ๏ธ`;
}
if (isIssue) {
message += `
๐ Hi @${user}! Thank you for taking the time to report an issue in **Notpad**.
Weโll dive into it shortly. ๐ต๏ธโโ๏ธ๐ง
While you're here, why not add a โญ to the repo? [Click here to star](https://github.com/Muhammed-Rahif/Notpad/stargazers).
Your support helps us grow this project and reach more awesome contributors like you! ๐`;
}
if (isPR) {
message += `
๐ Woohoo, @${user}! Thanks for opening a pull request to **Notpad**. ๐ ๏ธโจ
Your efforts make this project better with every contribution.
๐ก Before we merge this, donโt forget to check our [CONTRIBUTING.md](https://github.com/Muhammed-Rahif/Notpad/blob/main/CONTRIBUTING.md) for a smoother process.
Together, weโre building something incredible โ keep up the amazing work! ๐ช
(Psst... have you starred the repo yet? โญ)`;
}
if (totalContributions === 5) {
message += `
๐ High five, @${user}! โ Youโve just hit a major milestone โ **5 contributions** to **Notpad**!
Contributors like you make this project shine brighter every day. ๐
Your dedication inspires us, and we canโt wait to see what you come up with next.
A big thank you from the entire **Notpad** team โ we deeply appreciate your support. ๐
Letโs keep building and making open source awesome together! ๐`;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue?.number || context.payload.pull_request?.number,
body: message
});
- name: Assign User Guidance
if: ${{ github.event.action == 'assigned' }}
uses: actions/github-script@v7
with:
script: |
const assignee = context.payload.assignee.login;
const issueNumber = context.payload.issue.number;
// Fetch issues and pull requests created by the assignee
const [issues, pulls] = await Promise.all([
github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
}),
github.paginate(github.rest.pulls.list, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
}),
]);
// Filter to count only issues and pull requests created by the assignee
const assigneeIssues = issues.filter(issue => issue.user.login === assignee);
const assigneePulls = pulls.filter(pr => pr.user.login === assignee);
const totalContributions = assigneeIssues.length + assigneePulls.length;
// Log total contributions for debugging
// Compose the message based on contribution count
let message = '';
if (totalContributions < 3) {
message = `๐ ๏ธ **Heads up, @${assignee}!**
You've been assigned an issue in **Notpad** โ ready to make your mark? ๐
Since you're relatively new here, we highly recommend checking out our [CONTRIBUTING.md](https://github.com/Muhammed-Rahif/Notpad/blob/main/CONTRIBUTING.md).
Itโs packed with helpful tips, guidelines, and best practices to ensure a smooth contribution experience.
Weโre excited to see what youโll bring to the table โ happy coding! ๐ปโจ`;
} else {
message = `๐ Hi @${assignee}! You've been assigned an issue in **Notpad**.
Your contributions so far have been awesome, and we can't wait to see what you'll do next! ๐
Remember to check out our [CONTRIBUTING.md](https://github.com/Muhammed-Rahif/Notpad/blob/main/CONTRIBUTING.md) for any guidelines or tips.
Let's build something great together! ๐ก`;
}
// Post the comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: message
});
- name: Assign User Guidance
if: ${{ github.event.action == 'assigned' && steps.check_contributions.outputs.totalContributions < 3 }}
uses: actions/github-script@v7
with:
script: |
const assignee = context.payload.assignee.login;
const issueNumber = context.payload.issue.number;
const message = `๐ ๏ธ **Heads up, @${assignee}!**
You've been assigned an issue in **Notpad** โ ready to make your mark? ๐
Since you're relatively new here, we highly recommend checking out our [CONTRIBUTING.md](https://github.com/Muhammed-Rahif/Notpad/blob/main/CONTRIBUTING.md).
Itโs packed with helpful tips, guidelines, and best practices to ensure a smooth contribution experience.
Weโre excited to see what youโll bring to the table โ happy coding! ๐ปโจ`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: message
});
- name: Thank Contributor When PR is Merged
if: ${{ github.event.action == 'closed' && github.event.pull_request.merged == true }}
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const message = `๐ Congratulations, @${pr.user.login}! Your pull request has been successfully merged. ๐ฅณ๐
Youโve just made **Notpad** better, and we couldnโt be more thankful. ๐
Your contribution is now part of the project, helping users and contributors around the world. ๐
Weโre excited to see what else you have in store for us โ the best is yet to come! ๐ก
Cheers to you and the amazing world of open source! ๐ปโจ`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: message
});