-
-
Notifications
You must be signed in to change notification settings - Fork 5
544 lines (496 loc) · 20.9 KB
/
auto-fix-bot.yml
File metadata and controls
544 lines (496 loc) · 20.9 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
name: NullSec Auto-Fix Bot
on:
issues:
types: [opened, labeled]
issue_comment:
types: [created]
permissions:
contents: write
issues: write
pull-requests: write
jobs:
analyze-and-fix:
if: |
github.event_name == 'issues' &&
github.event.action == 'opened' &&
((startsWith(github.event.issue.title, 'bug') || contains(github.event.issue.title, ' bug')) ||
contains(github.event.issue.title, 'error') ||
contains(github.event.issue.title, 'fix') ||
contains(github.event.issue.title, 'broken'))
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Analyze Bug Report
id: analyze
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const author = issue.user.login;
const title = issue.title.toLowerCase();
const body = (issue.body || '').toLowerCase();
console.log('📋 Analyzing issue #' + issue.number + ' from @' + author);
// Extract key information from the bug report
const analysis = {
hasSteps: body.includes('step') || body.includes('reproduce'),
hasExpected: body.includes('expected') || body.includes('should'),
hasActual: body.includes('actual') || body.includes('instead') || body.includes('but'),
hasError: body.includes('error') || body.includes('exception') || body.includes('traceback'),
hasVersion: body.includes('version') || body.includes('v1') || body.includes('v2'),
hasOS: body.includes('linux') || body.includes('windows') || body.includes('mac') || body.includes('ubuntu'),
mentionsFile: body.match(/[\w\-]+\.(py|rs|go|js|ts|c|cpp|h|sh|yaml|yml|json|toml|md)/gi),
mentionsFunction: body.match(/`[\w_]+`|function\s+[\w_]+|def\s+[\w_]+|fn\s+[\w_]+/gi),
errorMessages: body.match(/error[:\s]+[^\n]+|exception[:\s]+[^\n]+|failed[:\s]+[^\n]+/gi)
};
// Calculate issue quality score
let qualityScore = 0;
if (analysis.hasSteps) qualityScore += 2;
if (analysis.hasExpected) qualityScore += 2;
if (analysis.hasActual) qualityScore += 2;
if (analysis.hasError) qualityScore += 1;
if (analysis.hasVersion) qualityScore += 1;
if (analysis.hasOS) qualityScore += 1;
if (analysis.mentionsFile) qualityScore += 2;
console.log('Quality Score: ' + qualityScore + '/11');
console.log('Analysis:', JSON.stringify(analysis, null, 2));
// Determine if we can attempt auto-fix
const canAttemptFix = qualityScore >= 5 && analysis.mentionsFile;
// Store analysis for next steps
core.setOutput('quality_score', qualityScore);
core.setOutput('can_fix', canAttemptFix);
core.setOutput('mentioned_files', JSON.stringify(analysis.mentionsFile || []));
core.setOutput('author', author);
return analysis;
- name: Acknowledge Bug Report
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const author = issue.user.login;
const qualityScore = parseInt('${{ steps.analyze.outputs.quality_score }}');
const canFix = '${{ steps.analyze.outputs.can_fix }}' === 'true';
let response = '';
let labels = ['bug', 'analyzing'];
if (qualityScore >= 7) {
response = [
'## 🎯 Excellent Bug Report!',
'',
'Thanks @' + author + ' for this detailed report! Quality score: **' + qualityScore + '/11** ⭐',
'',
'### 🔍 Analysis Status:',
'- ✅ Steps to reproduce: ' + (qualityScore >= 2 ? 'Found' : 'Missing'),
'- ✅ Expected behavior: Described',
'- ✅ Actual behavior: Described',
'',
canFix ? '### 🤖 Auto-Fix Attempt:' : '',
canFix ? 'I will analyze the mentioned files and attempt to create a fix.' : '',
canFix ? 'You will be **credited** in the fix commit if successful!' : '',
'',
'---',
'*🤖 NullSec Auto-Fix Bot*'
].join('\n');
labels.push('high-quality');
} else if (qualityScore >= 4) {
response = [
'## 👍 Good Bug Report',
'',
'Thanks @' + author + '! Quality score: **' + qualityScore + '/11**',
'',
'### 📋 To help me fix this faster, please add:',
qualityScore < 5 ? '- [ ] Steps to reproduce' : '',
'- [ ] Expected vs actual behavior',
'- [ ] Error messages or logs',
'- [ ] File/function where the bug occurs',
'',
'---',
'*🤖 NullSec Auto-Fix Bot*'
].filter(l => l).join('\n');
} else {
response = [
'## 📝 Bug Report Received',
'',
'Thanks @' + author + '! Quality score: **' + qualityScore + '/11**',
'',
'### ⚠️ Need More Information:',
'To investigate this bug, please provide:',
'',
'1. **Steps to reproduce** - What exactly did you do?',
'2. **Expected behavior** - What should happen?',
'3. **Actual behavior** - What actually happened?',
'4. **Environment** - OS, version, etc.',
'5. **Error messages** - Full error output if any',
'',
'---',
'*🤖 NullSec Auto-Fix Bot*'
].join('\n');
labels.push('needs-info');
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: response
});
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: labels
});
} catch (e) {
console.log('Could not add labels:', e.message);
}
process-fix-request:
if: |
github.event_name == 'issue_comment' &&
contains(github.event.comment.body, '/fix') &&
github.event.comment.user.login == github.repository_owner
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Process Fix Command
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const issue = context.payload.issue;
const comment = context.payload.comment;
const issueAuthor = issue.user.login;
const issueNumber = issue.number;
// Parse fix command
const fixMatch = comment.body.match(/\/fix\s+(.+)/);
if (!fixMatch) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: '❌ **Fix command format:** `/fix <description of fix>`\n\n---\n*🤖 NullSec Auto-Fix Bot*'
});
return;
}
const fixDescription = fixMatch[1];
// Acknowledge the fix
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: [
'## 🔧 Fix Initiated',
'',
'**Description:** ' + fixDescription,
'',
'### 📝 Actions:',
'- Creating fix branch',
'- Implementing changes',
'- Will credit @' + issueAuthor + ' for reporting',
'',
'---',
'*🤖 NullSec Auto-Fix Bot*'
].join('\n')
});
// Add labels
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['fix-in-progress']
});
} catch (e) {}
credit-reporter:
if: |
github.event_name == 'issues' &&
github.event.action == 'labeled' &&
github.event.label.name == 'fixed'
runs-on: ubuntu-latest
steps:
- name: Credit Bug Reporter
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const author = issue.user.login;
const issueNumber = issue.number;
// Thank and credit the reporter
const creditMessage = [
'## 🎉 Bug Fixed!',
'',
'### 🏆 Credit',
'Thanks to **@' + author + '** for reporting this bug!',
'',
'Your contribution has been noted in:',
'- The fix commit message',
'- CONTRIBUTORS.md (if applicable)',
'',
'### 📦 Release',
'This fix will be included in the next release.',
'',
'Thanks for helping improve NullSec! 🙏',
'',
'---',
'*🤖 NullSec Auto-Fix Bot*'
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: creditMessage
});
// Close the issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: 'closed',
state_reason: 'completed'
});
handle-feature-request:
if: |
github.event_name == 'issues' &&
github.event.action == 'opened' &&
(contains(github.event.issue.title, 'feature') ||
contains(github.event.issue.title, 'suggestion') ||
contains(github.event.issue.title, 'request') ||
contains(github.event.issue.title, 'add'))
runs-on: ubuntu-latest
steps:
- name: Evaluate Feature Request
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const author = issue.user.login;
const body = (issue.body || '').toLowerCase();
// Analyze feature request quality
const analysis = {
hasUseCase: body.includes('use case') || body.includes('would help') || body.includes('need'),
hasDescription: body.length > 100,
hasExample: body.includes('example') || body.includes('like') || body.includes('similar'),
hasBenefit: body.includes('benefit') || body.includes('improve') || body.includes('better'),
isWellFormatted: body.includes('##') || body.includes('*') || body.includes('-')
};
let qualityScore = 0;
if (analysis.hasUseCase) qualityScore += 2;
if (analysis.hasDescription) qualityScore += 2;
if (analysis.hasExample) qualityScore += 2;
if (analysis.hasBenefit) qualityScore += 2;
if (analysis.isWellFormatted) qualityScore += 1;
let response = '';
let labels = ['enhancement'];
if (qualityScore >= 6) {
response = [
'## ✨ Great Feature Request!',
'',
'Thanks @' + author + ' for this well-thought-out suggestion!',
'',
'### 📊 Evaluation:',
'- Quality Score: **' + qualityScore + '/9** ⭐',
'- Use case: ' + (analysis.hasUseCase ? '✅ Clear' : '⚠️ Could be clearer'),
'- Description: ' + (analysis.hasDescription ? '✅ Detailed' : '⚠️ Brief'),
'- Examples: ' + (analysis.hasExample ? '✅ Provided' : '❌ Missing'),
'',
'### 📋 Next Steps:',
'1. I will evaluate feasibility',
'2. If approved, it goes on the roadmap',
'3. You are welcome to submit a PR implementing it!',
'',
'You will be **credited** if this feature is implemented! 🏆',
'',
'---',
'*🤖 NullSec Auto-Fix Bot*'
].join('\n');
labels.push('good-idea', 'considering');
} else {
response = [
'## 💡 Feature Request Received',
'',
'Thanks @' + author + ' for the suggestion!',
'',
'### 📝 To help evaluate this, please add:',
!analysis.hasUseCase ? '- **Use case:** Why do you need this?' : '',
!analysis.hasExample ? '- **Examples:** How would it work?' : '',
!analysis.hasBenefit ? '- **Benefits:** How does it improve the project?' : '',
'',
'---',
'*🤖 NullSec Auto-Fix Bot*'
].filter(l => l).join('\n');
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: response
});
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: labels
});
} catch (e) {}
owner-commands:
if: |
github.event_name == 'issue_comment' &&
github.event.comment.user.login == github.repository_owner
runs-on: ubuntu-latest
steps:
- name: Handle Owner Commands
uses: actions/github-script@v7
with:
script: |
const comment = context.payload.comment.body.trim();
const issue = context.payload.issue;
const issueNumber = issue.number;
const issueAuthor = issue.user.login;
// /confirm - Confirm bug is valid and credit reporter
if (comment.startsWith('/confirm')) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: [
'## ✅ Bug Confirmed!',
'',
'This bug has been verified by the maintainer.',
'',
'**Reporter @' + issueAuthor + ' will be credited when fixed.**',
'',
'---',
'*🤖 NullSec Auto-Fix Bot*'
].join('\n')
});
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['confirmed', 'credit-reporter']
});
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: 'needs-info'
});
} catch (e) {}
}
// /wontfix - Close as won't fix
if (comment.startsWith('/wontfix')) {
const reason = comment.replace('/wontfix', '').trim() || 'Not applicable to current scope';
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: [
'## 🚫 Closed: Won\'t Fix',
'',
'**Reason:** ' + reason,
'',
'Thanks @' + issueAuthor + ' for reporting. Feel free to open a new issue if circumstances change.',
'',
'---',
'*🤖 NullSec Auto-Fix Bot*'
].join('\n')
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: 'closed',
state_reason: 'not_planned'
});
}
// /duplicate #<number> - Mark as duplicate
if (comment.startsWith('/duplicate')) {
const dupMatch = comment.match(/\/duplicate\s+#?(\d+)/);
if (dupMatch) {
const dupNumber = dupMatch[1];
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: [
'## 🔄 Duplicate Issue',
'',
'This issue is a duplicate of #' + dupNumber,
'',
'Please follow that issue for updates.',
'',
'---',
'*🤖 NullSec Auto-Fix Bot*'
].join('\n')
});
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['duplicate']
});
} catch (e) {}
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: 'closed',
state_reason: 'not_planned'
});
}
}
// /priority <high|medium|low> - Set priority
if (comment.startsWith('/priority')) {
const prioMatch = comment.match(/\/priority\s+(high|medium|low)/i);
if (prioMatch) {
const priority = prioMatch[1].toLowerCase();
const prioLabels = {
'high': 'priority-high',
'medium': 'priority-medium',
'low': 'priority-low'
};
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: '🏷️ Priority set to **' + priority.toUpperCase() + '**\n\n---\n*🤖 NullSec Auto-Fix Bot*'
});
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: [prioLabels[priority]]
});
} catch (e) {}
}
}
// /credit - Manually credit reporter
if (comment.startsWith('/credit')) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: [
'## 🏆 Contributor Credit',
'',
'**@' + issueAuthor + '** has been credited for this contribution!',
'',
'Thanks for helping improve NullSec! 🙏',
'',
'---',
'*🤖 NullSec Auto-Fix Bot*'
].join('\n')
});
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['credited']
});
} catch (e) {}
}