forked from Pradeepsingh61/DSA_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
231 lines (197 loc) Β· 8.75 KB
/
hacktoberfest-labeling.yml
File metadata and controls
231 lines (197 loc) Β· 8.75 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: π Hacktoberfest Auto-Labeling
on:
pull_request:
branches: [ main ]
types: [opened, synchronize]
issues:
types: [opened]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
auto-label:
runs-on: ubuntu-latest
steps:
- name: π₯ Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: π Get changed files
if: github.event_name == 'pull_request'
id: changed-files
uses: tj-actions/changed-files@v40
- name: π Add Hacktoberfest labels and welcome contributors
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
try {
// Get changed files
const { data: changedFiles } = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const files = changedFiles.map(file => file.filename);
const labels = ['hacktoberfest'];
console.log(`Processing ${files.length} changed files`);
// Determine contribution type
const hasAlgorithms = files.some(f => f.includes('/algorithms/'));
const hasDataStructures = files.some(f => f.includes('/data_structures/'));
const hasDP = files.some(f => f.includes('/dynamic_programming/'));
const hasProjects = files.some(f => f.includes('/projects/'));
const hasDocumentation = files.some(f => f.includes('README') || f.includes('.md'));
const hasNewLanguage = files.some(f =>
!f.startsWith('C/') &&
!f.startsWith('CPP/') &&
!f.startsWith('Java/') &&
!f.startsWith('Python/') &&
/\.(c|cpp|java|py|js|ts|go|rs|kt|swift|php|rb|cs|dart|scala)$/.test(f)
);
// Add specific labels
if (hasAlgorithms) labels.push('algorithms');
if (hasDataStructures) labels.push('data-structures');
if (hasDP) labels.push('dynamic-programming');
if (hasProjects) labels.push('projects');
if (hasDocumentation) labels.push('documentation');
if (hasNewLanguage) labels.push('new-language');
// Language-specific labels
const languages = {
'C/': 'lang:c',
'CPP/': 'lang:cpp',
'Java/': 'lang:java',
'Python/': 'lang:python',
'JavaScript/': 'lang:javascript',
'Go/': 'lang:go',
'Rust/': 'lang:rust',
'Kotlin/': 'lang:kotlin',
'Swift/': 'lang:swift',
'PHP/': 'lang:php',
'Ruby/': 'lang:ruby',
'CSharp/': 'lang:csharp',
'Dart/': 'lang:dart',
'Scala/': 'lang:scala'
};
for (const [dir, label] of Object.entries(languages)) {
if (files.some(f => f.startsWith(dir))) {
labels.push(label);
}
}
// Difficulty estimation
const fileCount = files.length;
if (fileCount === 1) labels.push('good first issue');
else if (fileCount <= 3) labels.push('easy');
else if (fileCount <= 7) labels.push('medium');
else labels.push('hard');
// Check if first-time contributor (with error handling)
let isFirstTime = false;
try {
const { data: commits } = await github.rest.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
author: context.payload.pull_request.user.login,
per_page: 5
});
if (commits.length <= 1) {
isFirstTime = true;
labels.push('first-time-contributor');
}
} catch (error) {
console.log('Could not check contributor history:', error.message);
isFirstTime = true;
labels.push('first-time-contributor');
}
// Apply labels
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: labels
});
console.log(`Applied labels: ${labels.join(', ')}`);
// Welcome first-time contributors
if (isFirstTime) {
const welcomeMessage = `π **Welcome to the DSA Code Repository!**
Thank you @${context.payload.pull_request.user.login} for your first contribution!
π **Hacktoberfest 2025**: This PR counts towards Hacktoberfest!
π **Next Steps**:
- Our team will review your PR shortly
- Make sure your code follows our [contribution guidelines](./CONTRIBUTING.md)
- Check our [Hall of Fame](./HALL_OF_FAME.md) to see where you'll be featured!
π **Pro Tips**:
- Add clear comments to your code
- Include time/space complexity analysis
- Test your implementation with sample inputs
Thanks for contributing to open source! π`;
// Check if we already posted a welcome message
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number
});
const existingWelcome = comments.find(comment =>
comment.user.type === 'Bot' && comment.body.includes('Welcome to the DSA Code Repository!')
);
// Only post if we haven't already commented, otherwise update
if (!existingWelcome) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: welcomeMessage
});
console.log('Welcome message posted for first-time contributor');
} else {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingWelcome.id,
body: welcomeMessage
});
console.log('Welcome message updated for first-time contributor');
}
}
} catch (error) {
console.error('Error in labeling workflow:', error);
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['hacktoberfest']
});
} catch (fallbackError) {
console.error('Fallback labeling also failed:', fallbackError);
}
}
- name: π·οΈ Add Hacktoberfest label to issues
if: github.event_name == 'issues'
uses: actions/github-script@v7
with:
script: |
try {
const labels = ['hacktoberfest'];
// Check issue content for categories
const body = context.payload.issue.body?.toLowerCase() || '';
const title = context.payload.issue.title?.toLowerCase() || '';
if (body.includes('algorithm') || title.includes('algorithm')) labels.push('algorithms');
if (body.includes('data structure') || title.includes('data structure')) labels.push('data-structures');
if (body.includes('bug') || title.includes('bug')) labels.push('bug');
if (body.includes('enhancement') || title.includes('enhancement')) labels.push('enhancement');
if (body.includes('documentation') || title.includes('doc')) labels.push('documentation');
if (body.includes('language') || title.includes('language')) labels.push('new-language');
// Add beginner-friendly label for certain keywords
if (body.includes('beginner') || body.includes('first') || body.includes('easy')) {
labels.push('good first issue');
}
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
labels: labels
});
console.log(`Applied issue labels: ${labels.join(', ')}`);
} catch (error) {
console.error('Error labeling issue:', error);
}