Repository navigation
571 lines (495 loc) · 26.9 KB
/
Copy pathissue-triage.yml
File metadata and controls
571 lines (495 loc) · 26.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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
name: Issue Triage
on:
issues:
types: [opened]
workflow_dispatch:
inputs:
issue_number:
description: 'Issue number to triage'
required: true
type: number
permissions:
issues: read
contents: read
models: read
jobs:
triage:
runs-on: ubuntu-latest
steps:
- name: Wait for acknowledgement
run: sleep 3600
- name: Triage Analysis
id: triage
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// --- GitHub Models helper: retry on transient errors, fall back across model chain ---
const MODEL_CHAIN = ["openai/gpt-4.1", "openai/gpt-4.1-mini"];
async function callModelOnce(model, prompt) {
const token = process.env.GITHUB_TOKEN;
const url = 'https://models.github.ai/inference/chat/completions';
const maxAttempts = 4;
const retryableStatuses = new Set([429, 500, 502, 503, 504]);
let lastErr;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
let response;
try {
response = await fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model,
messages: [{ role: "user", content: prompt }],
temperature: 0.1,
response_format: { type: "json_object" }
})
});
} catch (networkErr) {
lastErr = networkErr;
if (attempt < maxAttempts) {
const delay = Math.min(2000 * Math.pow(2, attempt - 1), 16000);
console.log(`GitHub Models network error on ${model} (attempt ${attempt}/${maxAttempts}): ${networkErr.message}. Retrying in ${delay}ms...`);
await new Promise(r => setTimeout(r, delay));
continue;
}
throw networkErr;
}
if (response.ok) {
const data = await response.json();
return data.choices[0].message.content;
}
const errText = await response.text();
lastErr = new Error(`GitHub Models error on ${model}: ${response.status} - ${errText}`);
if (retryableStatuses.has(response.status) && attempt < maxAttempts) {
const delay = Math.min(2000 * Math.pow(2, attempt - 1), 16000);
console.log(`GitHub Models transient ${response.status} on ${model} (attempt ${attempt}/${maxAttempts}). Retrying in ${delay}ms...`);
await new Promise(r => setTimeout(r, delay));
continue;
}
throw lastErr;
}
throw lastErr;
}
async function callGitHubModels(prompt) {
let lastErr;
for (let i = 0; i < MODEL_CHAIN.length; i++) {
const model = MODEL_CHAIN[i];
try {
return await callModelOnce(model, prompt);
} catch (e) {
lastErr = e;
if (i < MODEL_CHAIN.length - 1) {
console.log(`Model ${model} unavailable after retries — falling back to ${MODEL_CHAIN[i + 1]}. Last error: ${e.message}`);
}
}
}
throw lastErr;
}
// --- Get issue details ---
const issueNumber = context.payload.inputs?.issue_number
? parseInt(context.payload.inputs.issue_number)
: context.payload.issue.number;
let issue;
if (context.payload.issue && !context.payload.inputs?.issue_number) {
issue = context.payload.issue;
} else {
issue = (await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
})).data;
}
const issueTitle = issue.title;
const issueBody = issue.body || '';
const issueAuthor = issue.user.login;
console.log(`Triaging issue #${issueNumber}: ${issueTitle}`);
// --- Classify the issue ---
const classificationPrompt = `
You are an expert triage system for the mssql-python repository — a Python driver for Microsoft SQL Server.
The driver uses ODBC under the hood with a C++/pybind11 native extension layer and Python wrappers.
Note: The pybind/ directory contains C++/pybind11 code (NOT Rust). Only reference Rust if the issue is specifically about BCP (Bulk Copy Protocol).
Key source files in the repo:
- mssql_python/connection.py — Connection management, pooling integration
- mssql_python/cursor.py — Cursor operations, execute, fetch, bulkcopy
- mssql_python/auth.py — Authentication (SQL auth, Azure AD, etc.)
- mssql_python/exceptions.py — Error handling and exception classes
- mssql_python/pooling.py — Connection pooling
- mssql_python/helpers.py — Utility functions
- mssql_python/constants.py — Constants, SQL types, enums
- mssql_python/connection_string_parser.py — Connection string parsing
- mssql_python/parameter_helper.py — Query parameter handling
- mssql_python/logging.py — Logging infrastructure
- mssql_python/row.py — Row objects
- mssql_python/type.py — Type mappings
- mssql_python/ddbc_bindings.py — Python/pybind11 ODBC bindings (C++ native extension, NOT Rust)
- mssql_python/pybind/ — C++/pybind11 native extension layer (NOT Rust)
Classify the following GitHub issue into EXACTLY ONE category:
1. FEATURE_REQUEST — User wants new functionality or enhancements
2. BUG — Something is broken, incorrect behavior, or errors
3. DISCUSSION — User is asking a question or wants clarification
4. BREAK_FIX — A regression or critical bug: segfaults, crashes, data corruption,
or user says "this used to work"
Respond in this exact JSON format:
{
"category": "BUG|FEATURE_REQUEST|DISCUSSION|BREAK_FIX",
"confidence": <0-100>,
"justification": "<2-3 sentence explanation>",
"severity": "critical|high|medium|low",
"relevant_source_files": ["<top 3 most relevant source file paths>"],
"keywords": ["<key technical terms from the issue>"],
"summary_for_maintainers": "<detailed 3-5 sentence analysis for maintainer notification>"
}
Issue Title: ${issueTitle}
Issue Body:
${issueBody.slice(0, 4000)}
`;
let analysis;
try {
const classifyResult = await callGitHubModels(classificationPrompt);
analysis = JSON.parse(classifyResult);
} catch (e) {
core.setFailed(`Classification failed: ${e.message}`);
return;
}
console.log(`Classification: ${analysis.category} (${analysis.confidence}%)`);
console.log(`Severity: ${analysis.severity}`);
// --- Fetch relevant source files (for ALL categories) ---
console.log('Fetching relevant source files for code-grounded analysis...');
const fileContents = [];
for (const filePath of analysis.relevant_source_files.slice(0, 3)) {
try {
const file = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: filePath
});
const content = Buffer.from(file.data.content, 'base64').toString();
fileContents.push(`### File: ${filePath}\n\`\`\`python\n${content.slice(0, 3000)}\n\`\`\``);
console.log(`Fetched: ${filePath}`);
} catch (e) {
console.log(`Could not fetch ${filePath}: ${e.message}`);
}
}
const codeContext = fileContents.length > 0
? `\n\nRelevant source files from the repository:\n${fileContents.join('\n\n')}`
: '';
// --- For BUG/BREAK_FIX, analyze codebase ---
let codeAnalysis = '';
if (['BUG', 'BREAK_FIX'].includes(analysis.category) && fileContents.length > 0) {
console.log('Bug/Break-fix detected — analyzing codebase...');
const codePrompt = `
You are a senior Python developer analyzing a potential
${analysis.category === 'BREAK_FIX' ? 'regression/break-fix' : 'bug'}
in the mssql-python driver (Python + ODBC + C++/pybind11 native layer).
IMPORTANT: ddbc_bindings.py and the pybind/ directory are C++/pybind11 code, NOT Rust. Only mention Rust if the issue is specifically about BCP (Bulk Copy Protocol).
IMPORTANT: Base your analysis ONLY on the actual source code provided below. Do not speculate about code you haven't seen.
Bug Report:
Title: ${issueTitle}
Body: ${issueBody.slice(0, 2000)}
${codeContext}
Provide analysis in JSON:
{
"is_bug": "Confirmed Bug|Likely Bug|Require More Analysis|Not a Bug",
"root_cause": "<detailed root cause analysis based on actual code above>",
"affected_components": ["<affected modules/functions from the code above>"],
"evidence_and_context": "<specific evidence from the codebase — cite exact functions, variables, line logic, or patterns that support your analysis>",
"recommended_fixes": ["<fix 1 — describe the approach referencing specific code>", "<fix 2>", "<fix 3>"],
"code_locations": ["<file:function or file:class where changes should be made>"],
"risk_assessment": "<risk to users>"
}
`;
try {
codeAnalysis = await callGitHubModels(codePrompt);
console.log('Code analysis complete');
} catch (e) {
console.log(`Code analysis failed: ${e.message}`);
}
}
// --- For FEATURE_REQUEST/DISCUSSION, provide code-grounded engineer guidance ---
let engineerGuidance = '';
if (['FEATURE_REQUEST', 'DISCUSSION'].includes(analysis.category)) {
console.log('Non-bug issue — generating code-grounded engineer guidance...');
const guidancePrompt = `
You are a senior engineer on the mssql-python team — a Python driver for Microsoft SQL Server
(ODBC + C++/pybind11 native extension + Python wrappers).
IMPORTANT: Base your analysis ONLY on the actual source code provided below. Do not speculate about code you haven't seen. If the code doesn't contain enough information, say so explicitly.
A user filed a GitHub issue classified as: ${analysis.category}
Issue Title: ${issueTitle}
Issue Body:
${issueBody.slice(0, 3000)}
${codeContext}
Based on the ACTUAL SOURCE CODE above, provide a detailed analysis to help the engineering team respond efficiently.
Respond in JSON:
{
"technical_assessment": "<detailed technical assessment grounded in the actual code above>",
"verdict": "Confirmed Bug|Likely Bug|Require More Analysis|Not a Bug",
"issue_identified": true/false,
"affected_files": ["<specific source files, modules, functions, or classes from the code above>"],
"current_behavior": "<describe what the current code actually does based on your reading>",
"implementation_approach": "<concrete implementation steps referencing specific functions/lines from the code — ONLY if issue_identified is true, otherwise empty string>",
"effort_estimate": "small|medium|large|epic",
"risks_and_tradeoffs": "<potential risks, backward compatibility concerns, or tradeoffs — ONLY if issue_identified is true, otherwise empty string>",
"related_considerations": ["<other things the team should think about — ONLY if issue_identified is true, otherwise empty array>"]
}
IMPORTANT: If your technical_assessment does not identify any actual issue or gap in the code, set issue_identified to false and leave implementation_approach, risks_and_tradeoffs, and related_considerations empty. Only populate those fields when a real problem or improvement opportunity is confirmed in the code.
`;
try {
engineerGuidance = await callGitHubModels(guidancePrompt);
console.log('Engineer guidance generated');
} catch (e) {
console.log(`Engineer guidance failed: ${e.message}`);
}
}
// --- Search for similar/duplicate issues and recent fixes ---
console.log('Searching for similar issues and recent fixes...');
let similarIssuesAnalysis = '';
try {
// Fetch recent open issues (last 30)
const openIssues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 30,
sort: 'created',
direction: 'desc'
});
// Fetch recently closed issues (last 30)
const closedIssues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
per_page: 30,
sort: 'updated',
direction: 'desc'
});
const allIssues = [...openIssues.data, ...closedIssues.data]
.filter(i => i.number !== issueNumber && !i.pull_request)
.map(i => ({
number: i.number,
title: i.title,
state: i.state,
labels: i.labels.map(l => l.name).join(', '),
created_at: i.created_at,
closed_at: i.closed_at,
body_preview: (i.body || '').slice(0, 300)
}));
console.log(`Found ${allIssues.length} issues to compare against`);
const similarPrompt = `
You are an expert triage system for the mssql-python repository.
A new issue has been filed. Your job is to check if any similar or duplicate issues
already exist (open or recently closed/fixed).
NEW ISSUE:
Title: ${issueTitle}
Body: ${issueBody.slice(0, 2000)}
Keywords: ${analysis.keywords.join(', ')}
EXISTING ISSUES (recent open + recently closed):
${JSON.stringify(allIssues, null, 2).slice(0, 6000)}
Analyze and respond in JSON:
{
"has_duplicates": true/false,
"has_similar": true/false,
"duplicate_issues": [
{
"issue_number": <number>,
"title": "<title>",
"state": "open|closed",
"similarity": "duplicate|highly_similar|related",
"explanation": "<why this is a duplicate/similar>"
}
],
"recently_fixed": [
{
"issue_number": <number>,
"title": "<title>",
"closed_at": "<date>",
"relevance": "<how this fix relates to the new issue>"
}
],
"summary": "<1-3 sentence summary: are there duplicates? was this recently fixed? should the new issue be closed as duplicate?>"
}
IMPORTANT:
- Only flag as duplicate if the core problem is truly the same, not just topically related
- For recently_fixed, only include issues that were closed AND directly address the same problem
- If no duplicates or similar issues exist, set has_duplicates and has_similar to false with empty arrays
`;
const similarResult = await callGitHubModels(similarPrompt);
similarIssuesAnalysis = similarResult;
const parsed = JSON.parse(similarResult);
console.log(`Similar issues check: duplicates=${parsed.has_duplicates}, similar=${parsed.has_similar}`);
} catch (e) {
console.log(`Similar issues search failed: ${e.message}`);
similarIssuesAnalysis = '';
}
// --- Generate workaround suggestions (BUG/BREAK_FIX only) ---
let workaroundAnalysis = '';
if (['BUG', 'BREAK_FIX'].includes(analysis.category)) {
console.log('Generating workaround suggestions...');
const workaroundContext = codeAnalysis
? `Code Analysis:\n${codeAnalysis}`
: '';
const workaroundPrompt = `
You are a senior support engineer on the mssql-python team — Microsoft's Python driver for SQL Server.
A user has reported a ${analysis.category === 'BREAK_FIX' ? 'regression/break-fix' : 'bug'}.
Your job is to suggest practical workarounds the user can apply RIGHT NOW while the team works on a proper fix.
Issue Title: ${issueTitle}
Issue Body:
${issueBody.slice(0, 2000)}
${workaroundContext}
${codeContext}
Provide workaround suggestions in JSON:
{
"has_workaround": true/false,
"workarounds": [
{
"description": "<clear description of the workaround>",
"code_snippet": "<code snippet showing the workaround, if applicable>",
"language": "python|cpp|sql|shell|other",
"limitations": "<any limitations or caveats of this workaround>",
"confidence": "high|medium|low"
}
],
"can_downgrade": true/false,
"downgrade_version": "<safe version to downgrade to, if applicable>",
"summary": "<1-2 sentence summary of available workarounds>"
}
IMPORTANT:
- Only suggest workarounds you are confident about based on the code and issue description
- Workarounds should be practical and safe for production use
- If no reliable workaround exists, set has_workaround to false
- For BREAK_FIX issues, always consider if downgrading to a previous version is viable
- Code snippets should be complete and copy-pasteable
- CRITICAL: code_snippet MUST be a multi-line string with REAL newline characters (\n) between every statement. Do NOT collapse statements onto a single line. Indent body lines with 4 spaces (Python) or proper braces (C++).
- Set "language" to one of: "python" (default for mssql-python), "cpp" (for the pybind/native layer), "sql", "shell", or "other".
`;
try {
workaroundAnalysis = await callGitHubModels(workaroundPrompt);
const parsed = JSON.parse(workaroundAnalysis);
console.log(`Workaround analysis: has_workaround=${parsed.has_workaround}`);
} catch (e) {
console.log(`Workaround generation failed: ${e.message}`);
workaroundAnalysis = '';
}
}
// NO labels modified on the issue — label info sent to Teams only
// NO comment posted to the issue
// --- Generate suggested customer response (all categories) ---
console.log('Generating suggested customer response...');
let suggestedResponse = '';
const analysisContext = codeAnalysis
? `Code Analysis:\n${codeAnalysis}`
: engineerGuidance
? `Engineer Guidance:\n${engineerGuidance}`
: '';
const workaroundContext = workaroundAnalysis
? `Workaround Analysis:\n${workaroundAnalysis}`
: '';
const similarContext = similarIssuesAnalysis
? `Similar Issues Analysis:\n${similarIssuesAnalysis}`
: '';
const responsePrompt = `
You are a senior support engineer on the mssql-python team — Microsoft's Python driver for SQL Server.
A customer filed a GitHub issue and you need to craft a helpful, professional, and empathetic response
that an engineer can copy-paste (or lightly edit) and post on the issue.
Issue Category: ${analysis.category}
Severity: ${analysis.severity}
Issue Title: ${issueTitle}
Issue Author: @${issueAuthor}
Issue Body:
${issueBody.slice(0, 3000)}
${analysisContext}
${workaroundContext}
${similarContext}
Write a suggested response following these guidelines:
- Address the author by their GitHub username (@username)
- Thank them for filing the issue
- Acknowledge the specific problem or request they described
- For BUG/BREAK_FIX: Let them know the team is investigating; ask for OS, Python version,
mssql-python version, SQL Server version, and a minimal repro script if not already provided;
if workarounds are available, mention them briefly
- For FEATURE_REQUEST: Acknowledge the value of the request; mention the team will evaluate it;
ask for use-case details or code examples showing desired behavior if not provided
- For DISCUSSION: Provide helpful guidance or clarification based on the analysis;
point to relevant docs or code if applicable
- If similar or duplicate issues were found, mention them (e.g., "This looks related to #123")
- Always ask for a minimal reproduction script/code snippet if the user hasn't provided one
- Keep the tone warm, professional, and collaborative
- Use Markdown formatting suitable for GitHub comments
- Do NOT promise timelines or specific fixes
- Do NOT reveal internal triage details or AI involvement
- Keep it concise (under 200 words)
Respond in JSON:
{
"suggested_response": "<the full Markdown response ready to post on GitHub>"
}
`;
try {
const responseResult = await callGitHubModels(responsePrompt);
const parsed = JSON.parse(responseResult);
suggestedResponse = parsed.suggested_response || '';
console.log('Suggested customer response generated');
} catch (e) {
console.log(`Suggested response generation failed: ${e.message}`);
suggestedResponse = '';
}
// --- Store outputs ---
core.setOutput('category', analysis.category);
core.setOutput('confidence', analysis.confidence.toString());
core.setOutput('severity', analysis.severity);
core.setOutput('justification', analysis.justification);
core.setOutput('summary_for_maintainers', analysis.summary_for_maintainers || analysis.justification);
core.setOutput('relevant_files', analysis.relevant_source_files.join(', '));
core.setOutput('keywords', analysis.keywords.join(', '));
core.setOutput('code_analysis', codeAnalysis);
core.setOutput('engineer_guidance', engineerGuidance);
core.setOutput('suggested_response', suggestedResponse);
core.setOutput('similar_issues', similarIssuesAnalysis);
core.setOutput('workaround', workaroundAnalysis);
core.setOutput('issue_number', issueNumber.toString());
core.setOutput('issue_title', issueTitle);
core.setOutput('issue_url', issue.html_url);
core.setOutput('issue_author', issueAuthor);
outputs:
category: ${{ steps.triage.outputs.category }}
confidence: ${{ steps.triage.outputs.confidence }}
severity: ${{ steps.triage.outputs.severity }}
justification: ${{ steps.triage.outputs.justification }}
summary_for_maintainers: ${{ steps.triage.outputs.summary_for_maintainers }}
relevant_files: ${{ steps.triage.outputs.relevant_files }}
keywords: ${{ steps.triage.outputs.keywords }}
code_analysis: ${{ steps.triage.outputs.code_analysis }}
engineer_guidance: ${{ steps.triage.outputs.engineer_guidance }}
suggested_response: ${{ steps.triage.outputs.suggested_response }}
similar_issues: ${{ steps.triage.outputs.similar_issues }}
workaround: ${{ steps.triage.outputs.workaround }}
issue_number: ${{ steps.triage.outputs.issue_number }}
issue_title: ${{ steps.triage.outputs.issue_title }}
issue_url: ${{ steps.triage.outputs.issue_url }}
issue_author: ${{ steps.triage.outputs.issue_author }}
notify:
needs: triage
uses: ./.github/workflows/issue-notify.yml
with:
category: ${{ needs.triage.outputs.category }}
confidence: ${{ needs.triage.outputs.confidence }}
severity: ${{ needs.triage.outputs.severity }}
justification: ${{ needs.triage.outputs.justification }}
summary_for_maintainers: ${{ needs.triage.outputs.summary_for_maintainers }}
relevant_files: ${{ needs.triage.outputs.relevant_files }}
keywords: ${{ needs.triage.outputs.keywords }}
code_analysis: ${{ needs.triage.outputs.code_analysis }}
engineer_guidance: ${{ needs.triage.outputs.engineer_guidance }}
suggested_response: ${{ needs.triage.outputs.suggested_response }}
similar_issues: ${{ needs.triage.outputs.similar_issues }}
workaround: ${{ needs.triage.outputs.workaround }}
issue_number: ${{ needs.triage.outputs.issue_number }}
issue_title: ${{ needs.triage.outputs.issue_title }}
issue_url: ${{ needs.triage.outputs.issue_url }}
issue_author: ${{ needs.triage.outputs.issue_author }}
secrets:
TEAMS_WEBHOOK_URL: ${{ secrets.TEAMS_WEBHOOK_URL }}