forked from NoeFabris/opencode-antigravity-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
255 lines (221 loc) · 9.73 KB
/
Copy pathissue-triage.yml
File metadata and controls
255 lines (221 loc) · 9.73 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
name: '🏷️ Issue Triage'
on:
issues:
types:
- 'opened'
- 'reopened'
issue_comment:
types:
- 'created'
workflow_dispatch:
inputs:
issue_number:
description: 'Issue number to triage'
required: true
type: 'number'
concurrency:
group: '${{ github.workflow }}-${{ github.event.issue.number || github.event.inputs.issue_number }}'
cancel-in-progress: true
permissions:
contents: 'read'
issues: 'write'
jobs:
triage-issue:
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'issues' ||
(
github.event_name == 'issue_comment' &&
contains(github.event.comment.body, '/triage') &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
)
timeout-minutes: 30
runs-on: self-hosted
steps:
- name: 'Check if already triaged'
id: 'check_labels'
if: github.event_name != 'workflow_dispatch'
uses: 'actions/github-script@v7'
with:
script: |
const labels = context.payload.issue?.labels?.map(l => l.name) || [];
const triageLabels = ['bug', 'enhancement', 'documentation', 'question', 'invalid'];
const areaLabels = labels.filter(l => l.startsWith('area/'));
const hasTriageLabel = labels.some(l => triageLabels.includes(l)) || areaLabels.length > 0;
const isRetriage = context.payload.comment?.body?.includes('/triage');
if (hasTriageLabel && !labels.includes('needs-triage') && !isRetriage) {
core.info(`Issue already triaged: ${labels.join(', ')}. Skipping.`);
core.setOutput('skip', 'true');
} else {
core.setOutput('skip', 'false');
}
- name: 'Get issue data'
id: 'get_issue'
if: steps.check_labels.outputs.skip != 'true'
uses: 'actions/github-script@v7'
with:
script: |
const issueNumber = context.payload.inputs?.issue_number || context.issue?.number;
core.setOutput('number', issueNumber);
- name: 'Run Opencode Triage'
id: 'opencode_triage'
if: steps.check_labels.outputs.skip != 'true'
run: |
echo "Running Opencode Triage on issue ${{ steps.get_issue.outputs.number }}..."
# Run CLI with the agent config
OUTPUT=$(opencode run --agent triage-bot "Triage issue ${{ steps.get_issue.outputs.number }}")
echo "Opencode Output: $OUTPUT"
echo "result<<EOF" >> $GITHUB_OUTPUT
echo "$OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: 'Apply Labels and Respond'
if: steps.check_labels.outputs.skip != 'true'
uses: 'actions/github-script@v7'
env:
ISSUE_NUMBER: '${{ steps.get_issue.outputs.number }}'
OPENCODE_OUTPUT: '${{ steps.opencode_triage.outputs.result }}'
with:
script: |
const rawOutput = process.env.OPENCODE_OUTPUT;
if (!rawOutput) {
core.warning('No triage output available');
return;
}
core.info(`Triage output: ${rawOutput}`);
let parsed;
try {
parsed = JSON.parse(rawOutput.trim());
} catch (e) {
const match = rawOutput.match(/```(?:json)?\s*([\s\S]*?)\s*```/) ||
rawOutput.match(/\{[\s\S]*?\}/);
if (match) {
try {
parsed = JSON.parse(match[1] || match[0]);
} catch (e2) {
core.setFailed(`Failed to parse output: ${rawOutput}`);
return;
}
} else {
core.setFailed(`Failed to parse output: ${rawOutput}`);
return;
}
}
const typeLabel = parsed.type_label;
const areaLabel = parsed.area_label;
const duplicateOf = parsed.duplicate_of;
const suggestedResponse = parsed.suggested_response;
// Validate required fields
if (!typeLabel || !areaLabel || suggestedResponse === undefined) {
core.setFailed(`Invalid JSON structure: missing required fields. Parsed: ${JSON.stringify(parsed)}`);
return;
}
const validTypeLabels = ['bug', 'enhancement', 'documentation', 'question', 'invalid'];
const validAreaLabels = ['area/auth', 'area/models', 'area/config', 'area/compat'];
if (!validTypeLabels.includes(typeLabel)) {
core.warning(`Invalid type_label: ${typeLabel}`);
return;
}
if (!validAreaLabels.includes(areaLabel)) {
core.warning(`Invalid area_label: ${areaLabel}`);
return;
}
let labelsToAdd = [];
let labelsToRemove = ['needs-triage'];
// Remove existing triage labels to prevent conflicts
validTypeLabels.forEach(label => labelsToRemove.push(label));
validAreaLabels.forEach(label => labelsToRemove.push(label));
// Only add one type label and one area label
if (typeLabel && validTypeLabels.includes(typeLabel)) {
labelsToAdd.push(typeLabel);
}
if (areaLabel && validAreaLabels.includes(areaLabel)) {
labelsToAdd.push(areaLabel);
}
if (duplicateOf) {
labelsToAdd.push('duplicate');
}
// Validate single label selection and deduplicate
const typeLabels = labelsToAdd.filter(label => validTypeLabels.includes(label));
const areaLabels = labelsToAdd.filter(label => validAreaLabels.includes(label));
const otherLabels = labelsToAdd.filter(label => !validTypeLabels.includes(label) && !validAreaLabels.includes(label));
if (typeLabels.length > 1) {
core.warning(`Multiple type labels detected: ${typeLabels.join(', ')}. Using only: ${typeLabel}`);
}
if (areaLabels.length > 1) {
core.warning(`Multiple area labels detected: ${areaLabels.join(', ')}. Using only: ${areaLabel}`);
}
// Rebuild labelsToAdd with single type and area labels
labelsToAdd = [];
if (typeLabel && validTypeLabels.includes(typeLabel)) {
labelsToAdd.push(typeLabel);
}
if (areaLabel && validAreaLabels.includes(areaLabel)) {
labelsToAdd.push(areaLabel);
}
labelsToAdd.push(...otherLabels);
// Avoid removing labels that are being added
labelsToRemove = labelsToRemove.filter(label => !labelsToAdd.includes(label));
const issueNumber = parseInt(process.env.ISSUE_NUMBER);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: labelsToAdd
});
core.info(`Added labels: ${labelsToAdd.join(', ')}`);
for (const label of labelsToRemove) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: label
});
core.info(`Removed label: ${label}`);
} catch (e) {
core.info(`Label ${label} not present, skipping removal`);
}
}
if (suggestedResponse && suggestedResponse.trim()) {
let body = `👋 Thanks for opening this issue!\n\n${suggestedResponse}`;
if (duplicateOf) {
body += `\n\n🔗 This appears to be related to #${duplicateOf}. Please check that issue for updates.`;
}
body += `\n\n---\n*This is an automated response. A maintainer will review your issue soon.*`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: body
});
core.info('Posted response comment');
}
if (duplicateOf) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: 'closed',
state_reason: 'not_planned'
});
core.info(`Closed as duplicate of #${duplicateOf}`);
}
- name: 'Comment on failure'
if: failure()
uses: 'actions/github-script@v7'
env:
ISSUE_NUMBER: '${{ steps.get_issue.outputs.number || github.event.issue.number }}'
RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
with:
script: |
if (!process.env.ISSUE_NUMBER) return;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(process.env.ISSUE_NUMBER),
body: `⚠️ Automated triage failed. [View logs](${process.env.RUN_URL})`
});