-
Notifications
You must be signed in to change notification settings - Fork 37
371 lines (324 loc) · 15.3 KB
/
Copy pathenhance_feature_requests.yml
File metadata and controls
371 lines (324 loc) · 15.3 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
name: Enhance Feature Requests
on:
issues:
types: [opened, labeled]
jobs:
check-label:
runs-on: ubuntu-latest
outputs:
has_enhancement: ${{ steps.check.outputs.has_enhancement }}
already_enhanced: ${{ steps.check-enhanced.outputs.already_enhanced }}
steps:
- name: Check if issue has enhancement label
id: check
run: |
# For 'labeled' events, check if the label being added is 'enhancement'
# For 'opened' events, check if issue has 'enhancement' label
if [ "${{ github.event.action }}" = "labeled" ]; then
if [ "${{ github.event.label.name }}" = "enhancement" ]; then
echo "has_enhancement=true" >> $GITHUB_OUTPUT
else
echo "has_enhancement=false" >> $GITHUB_OUTPUT
fi
else
# For 'opened' events, check all labels
LABELS="${{ join(github.event.issue.labels.*.name, ',') }}"
if echo "$LABELS" | grep -q "enhancement"; then
echo "has_enhancement=true" >> $GITHUB_OUTPUT
else
echo "has_enhancement=false" >> $GITHUB_OUTPUT
fi
fi
- name: Check if issue already enhanced
id: check-enhanced
run: |
# Check if issue already has enhanced content
ISSUE_BODY="${{ github.event.issue.body }}"
if echo "$ISSUE_BODY" | grep -q "Enhanced Feature Request"; then
echo "already_enhanced=true" >> $GITHUB_OUTPUT
echo "Issue already has enhanced content, skipping"
else
echo "already_enhanced=false" >> $GITHUB_OUTPUT
fi
preprocess:
runs-on: ubuntu-latest
needs: check-label
if: needs.check-label.outputs.has_enhancement == 'true' && needs.check-label.outputs.already_enhanced == 'false'
permissions:
contents: read
outputs:
enhanced_task: ${{ steps.preprocess.outputs.enhanced_task }}
task_json: ${{ steps.preprocess.outputs.task_json }}
confluence_url: ${{ steps.preprocess.outputs.confluence_url }}
steps:
- name: Checkout master
uses: actions/checkout@v6
with:
ref: master
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22.x
cache: 'npm'
cache-dependency-path: .github/agent/package-lock.json
- name: Install agent dependencies
working-directory: .github/agent
run: npm install
- name: Preprocess feature request to user story (OpenAI only)
id: preprocess
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
PREPROCESSING_MODEL: ${{ secrets.PREPROCESSING_MODEL }}
TASK: ${{ github.event.issue.title }}
REQUESTER: ${{ github.event.issue.user.login }}
# Skip Confluence creation in preprocessing - will be done in parallel job
CONFLUENCE_URL: ""
CONFLUENCE_EMAIL: ""
CONFLUENCE_API_TOKEN: ""
CONFLUENCE_SPACE_KEY: ""
CONFLUENCE_PARENT_PAGE_ID: ""
GITHUB_RUN_ID: ${{ github.run_id }}
run: |
OUTPUT=$(node .github/agent/preprocess-task.mjs 2>&1)
echo "$OUTPUT"
# Extract enhanced task from output
if echo "$OUTPUT" | grep -q "ENHANCED_TASK_START"; then
ENHANCED_TASK=$(echo "$OUTPUT" | sed -n '/ENHANCED_TASK_START/,/ENHANCED_TASK_END/p' | sed '1d;$d')
echo "enhanced_task<<EOF" >> $GITHUB_OUTPUT
echo "$ENHANCED_TASK" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
# Fallback to original task
echo "enhanced_task=${{ github.event.issue.title }}" >> $GITHUB_OUTPUT
fi
# Extract JSON if available
JSON_LINE=$(echo "$OUTPUT" | grep "ENHANCED_TASK_JSON:" || true)
if [ -n "$JSON_LINE" ]; then
JSON_DATA=$(echo "$JSON_LINE" | sed 's/ENHANCED_TASK_JSON://')
echo "task_json=$JSON_DATA" >> $GITHUB_OUTPUT
else
echo "task_json=null" >> $GITHUB_OUTPUT
fi
create-confluence:
runs-on: ubuntu-latest
needs: preprocess
if: needs.preprocess.outcome == 'success'
permissions:
contents: read
steps:
- name: Checkout master
uses: actions/checkout@v6
with:
ref: master
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22.x
cache: 'npm'
cache-dependency-path: .github/agent/package-lock.json
- name: Install agent dependencies
working-directory: .github/agent
run: npm install
- name: Create Confluence page
id: confluence
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
PREPROCESSING_MODEL: ${{ secrets.PREPROCESSING_MODEL }}
TASK: ${{ github.event.issue.title }}
REQUESTER: ${{ github.event.issue.user.login }}
CONFLUENCE_URL: ${{ secrets.CONFLUENCE_URL }}
CONFLUENCE_EMAIL: ${{ secrets.CONFLUENCE_EMAIL }}
CONFLUENCE_API_TOKEN: ${{ secrets.CONFLUENCE_API_TOKEN }}
CONFLUENCE_SPACE_KEY: ${{ secrets.CONFLUENCE_SPACE_KEY }}
CONFLUENCE_PARENT_PAGE_ID: ${{ secrets.CONFLUENCE_PARENT_PAGE_ID }}
GITHUB_RUN_ID: ${{ github.run_id }}
# Use enhanced task from preprocessing
ENHANCED_TASK: ${{ needs.preprocess.outputs.enhanced_task }}
run: |
# Create a temporary script that only creates Confluence page
cat > /tmp/create-confluence.mjs << 'SCRIPT_EOF'
// Use native fetch (Node 20+)
const enhancedTask = process.env.ENHANCED_TASK || "";
const task = process.env.TASK || "";
const requester = process.env.REQUESTER || "unknown";
const confluenceUrl = process.env.CONFLUENCE_URL || "";
const confluenceEmail = process.env.CONFLUENCE_EMAIL || "";
const confluenceApiToken = process.env.CONFLUENCE_API_TOKEN || "";
const confluenceSpaceKey = process.env.CONFLUENCE_SPACE_KEY || "AICODE";
const confluenceParentPageId = process.env.CONFLUENCE_PARENT_PAGE_ID || "";
const githubRunId = process.env.GITHUB_RUN_ID || "unknown";
if (!confluenceUrl || !confluenceEmail || !confluenceApiToken) {
console.log("[CONFLUENCE] Confluence credentials not configured, skipping page creation");
process.exit(0);
}
try {
const timestamp = new Date().toISOString().split('T')[0];
const pageTitle = `AICODE: ${task.substring(0, 80)} (${timestamp})`;
const storageContent = `
<h2>Original Task</h2>
<p>${task.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, '<br/>')}</p>
<h2>User Story</h2>
<p>${enhancedTask.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, '<br/>')}</p>
<h2>Implementation Status</h2>
<p><ac:structured-macro ac:name="status"><ac:parameter ac:name="colour">Yellow</ac:parameter><ac:parameter ac:name="title">In Progress</ac:parameter></ac:structured-macro></p>
<h2>Related Links</h2>
<p>GitHub Run: <a href="https://github.com/htilly/SlackONOS/actions/runs/${githubRunId}">View Workflow</a></p>
`.trim();
const auth = Buffer.from(`${confluenceEmail}:${confluenceApiToken}`).toString('base64');
const pageData = {
type: 'page',
title: pageTitle,
space: { key: confluenceSpaceKey },
body: {
storage: {
value: storageContent,
representation: 'storage'
}
}
};
if (confluenceParentPageId) {
pageData.ancestors = [{ id: confluenceParentPageId }];
}
const response = await fetch(`${confluenceUrl}/rest/api/content`, {
method: 'POST',
headers: {
'Authorization': `Basic ${auth}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(pageData)
});
if (!response.ok) {
const errorText = await response.text();
console.error(`[CONFLUENCE] Failed to create page: ${response.status} ${response.statusText}`);
console.error(`[CONFLUENCE] Error details: ${errorText}`);
process.exit(1);
}
const data = await response.json();
const pageUrl = `${confluenceUrl}/wiki${data._links.webui}`;
console.log(`[CONFLUENCE] ✅ Confluence page created: ${pageUrl}`);
console.log(`CONFLUENCE_URL:${pageUrl}`);
} catch (error) {
console.error(`[CONFLUENCE] Error creating page: ${error.message}`);
process.exit(1);
}
SCRIPT_EOF
OUTPUT=$(node /tmp/create-confluence.mjs 2>&1)
echo "$OUTPUT"
# Extract Confluence URL
CONFLUENCE_URL=$(echo "$OUTPUT" | grep "CONFLUENCE_URL:" | sed 's/CONFLUENCE_URL://' || echo "N/A")
echo "confluence_url=$CONFLUENCE_URL" >> $GITHUB_OUTPUT
update-github-issue:
runs-on: ubuntu-latest
needs: preprocess
if: needs.preprocess.outcome == 'success'
permissions:
contents: read
issues: write
steps:
- name: Update GitHub issue with enhanced description
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: |
# Read enhanced task from JSON output to avoid shell quoting issues
TASK_JSON="${{ needs.preprocess.outputs.task_json }}"
if [ -n "$TASK_JSON" ] && [ "$TASK_JSON" != "null" ]; then
# Extract values from JSON using jq
ENHANCED_TASK=$(echo "$TASK_JSON" | jq -r '.enhanced // empty')
ORIGINAL_TASK=$(echo "$TASK_JSON" | jq -r '.original // empty')
else
# Fallback to outputs if JSON not available
ENHANCED_TASK="${{ needs.preprocess.outputs.enhanced_task }}"
ORIGINAL_TASK="${{ github.event.issue.title }}"
fi
# Get original body (may be null/empty)
ORIGINAL_BODY="${{ github.event.issue.body }}"
if [ -z "$ORIGINAL_BODY" ] || [ "$ORIGINAL_BODY" = "null" ]; then
ORIGINAL_BODY="_(No description provided)_"
fi
# Build enhanced body with proper escaping using jq
# Start with base content (without Confluence link for now)
BASE_BODY=$(jq -nr \
--arg enhanced "$ENHANCED_TASK" \
--arg original "$ORIGINAL_BODY" \
--arg requester "${{ github.event.issue.user.login }}" \
--arg created "${{ github.event.issue.created_at }}" \
'"## 📝 Enhanced Feature Request\n\n" + $enhanced + "\n\n---\n\n## 📋 Original Request\n\n" + $original + "\n\n---\n\n**Requested by:** " + $requester + " \n**Created:** " + $created')
ENHANCED_BODY="$BASE_BODY"
# Use jq to properly construct JSON payload for PATCH
PAYLOAD=$(jq -n \
--arg body "$ENHANCED_BODY" \
'{body: $body}')
# Update the issue
curl -X PATCH "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"
echo "✅ Issue #${{ github.event.issue.number }} updated with enhanced description"
add-confluence-link:
runs-on: ubuntu-latest
needs: [preprocess, create-confluence, update-github-issue]
if: needs.create-confluence.outcome == 'success' && needs.update-github-issue.outcome == 'success'
permissions:
issues: write
steps:
- name: Add Confluence link to issue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CONFLUENCE_URL="${{ needs.create-confluence.outputs.confluence_url }}"
if [ "$CONFLUENCE_URL" = "N/A" ] || [ -z "$CONFLUENCE_URL" ]; then
echo "No Confluence URL to add"
exit 0
fi
# Get current issue body
CURRENT_BODY=$(curl -s "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" | jq -r '.body')
# Add Confluence link to the end
UPDATED_BODY=$(jq -nr \
--arg current "$CURRENT_BODY" \
--arg confluence "$CONFLUENCE_URL" \
'$current + "\n\n📄 **Requirements documented:** " + $confluence')
# Update issue with Confluence link
PAYLOAD=$(jq -n \
--arg body "$UPDATED_BODY" \
'{body: $body}')
curl -X PATCH "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"
echo "✅ Added Confluence link to issue"
add-comment:
runs-on: ubuntu-latest
needs: [preprocess, create-confluence, update-github-issue]
if: always() && (needs.preprocess.outcome == 'success' || needs.update-github-issue.outcome == 'success')
permissions:
issues: write
steps:
- name: Add comment to issue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CONFLUENCE_URL="${{ needs.create-confluence.outputs.confluence_url }}"
# Build comment with proper escaping using jq
if [ "$CONFLUENCE_URL" != "N/A" ] && [ -n "$CONFLUENCE_URL" ]; then
COMMENT=$(jq -nr \
--arg confluence "$CONFLUENCE_URL" \
'"🤖 **Feature request enhanced!**\n\nThis feature request has been automatically enhanced with a structured user story format.\n\n📄 Requirements documented: " + $confluence + "\n\nThe issue description has been updated with acceptance criteria and technical notes."')
else
COMMENT=$(jq -nr \
'"🤖 **Feature request enhanced!**\n\nThis feature request has been automatically enhanced with a structured user story format.\n\nThe issue description has been updated with acceptance criteria and technical notes."')
fi
# Use jq to properly construct JSON payload
PAYLOAD=$(jq -n \
--arg body "$COMMENT" \
'{body: $body}')
curl -X POST "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"