Skip to content

Commit 34d040e

Browse files
authored
Fix workflow syntax and improve label checks
1 parent 89e85b3 commit 34d040e

1 file changed

Lines changed: 74 additions & 125 deletions

File tree

.github/workflows/feature-request-enhance.yml

Lines changed: 74 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -9,123 +9,102 @@ jobs:
99
runs-on: ubuntu-latest
1010
outputs:
1111
has_enhancement: ${{ steps.check.outputs.has_enhancement }}
12-
already_enhanced: ${{ steps.check-enhanced.outputs.already_enhanced }}
12+
already_enhanced: ${{ steps.check_enhanced.outputs.already_enhanced }}
1313
steps:
14-
- name: Check if issue has enhancement label
14+
- name: Check enhancement label
1515
id: check
1616
run: |
17-
# For 'labeled' events, check if the label being added is 'enhancement'
18-
# For 'opened' events, check if issue has 'enhancement' label
17+
set -e
18+
1919
if [ "${{ github.event.action }}" = "labeled" ]; then
2020
if [ "${{ github.event.label.name }}" = "enhancement" ]; then
21-
echo "has_enhancement=true" >> $GITHUB_OUTPUT
21+
echo "has_enhancement=true" >> "$GITHUB_OUTPUT"
2222
else
23-
echo "has_enhancement=false" >> $GITHUB_OUTPUT
23+
echo "has_enhancement=false" >> "$GITHUB_OUTPUT"
2424
fi
2525
else
26-
# For 'opened' events, check all labels
2726
LABELS="${{ join(github.event.issue.labels.*.name, ',') }}"
28-
if echo "$LABELS" | grep -q "enhancement"; then
29-
echo "has_enhancement=true" >> $GITHUB_OUTPUT
27+
if [ -n "$LABELS" ] && echo "$LABELS" | grep -q "enhancement"; then
28+
echo "has_enhancement=true" >> "$GITHUB_OUTPUT"
3029
else
31-
echo "has_enhancement=false" >> $GITHUB_OUTPUT
30+
echo "has_enhancement=false" >> "$GITHUB_OUTPUT"
3231
fi
3332
fi
34-
33+
3534
- name: Check if issue already enhanced
36-
id: check-enhanced
35+
id: check_enhanced
3736
run: |
38-
# Check if issue already has enhanced content
39-
ISSUE_BODY="${{ github.event.issue.body }}"
40-
if echo "$ISSUE_BODY" | grep -q "Enhanced Feature Request"; then
41-
echo "already_enhanced=true" >> $GITHUB_OUTPUT
42-
echo "Issue already has enhanced content, skipping"
37+
set -e
38+
BODY="${{ github.event.issue.body }}"
39+
if echo "$BODY" | grep -q "## .*Enhanced Feature Request"; then
40+
echo "already_enhanced=true" >> "$GITHUB_OUTPUT"
4341
else
44-
echo "already_enhanced=false" >> $GITHUB_OUTPUT
42+
echo "already_enhanced=false" >> "$GITHUB_OUTPUT"
4543
fi
4644
4745
preprocess:
4846
runs-on: ubuntu-latest
4947
needs: check-label
5048
if: needs.check-label.outputs.has_enhancement == 'true' && needs.check-label.outputs.already_enhanced == 'false'
51-
permissions:
52-
contents: read
5349
outputs:
5450
enhanced_task: ${{ steps.preprocess.outputs.enhanced_task }}
55-
task_json: ${{ steps.preprocess.outputs.task_json }}
5651
steps:
57-
- name: Checkout develop
58-
uses: actions/checkout@v4
52+
- uses: actions/checkout@v4
5953
with:
6054
ref: develop
6155

62-
- name: Setup Node.js
63-
uses: actions/setup-node@v4
56+
- uses: actions/setup-node@v4
6457
with:
6558
node-version: 20
66-
cache: 'npm'
59+
cache: npm
6760

68-
- name: Install agent dependencies
61+
- name: Install dependencies
6962
working-directory: .github/agent
7063
run: npm install
7164

72-
- name: Preprocess feature request to user story (OpenAI only)
65+
- name: Preprocess issue
7366
id: preprocess
7467
env:
7568
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
7669
PREPROCESSING_MODEL: ${{ secrets.PREPROCESSING_MODEL }}
7770
TASK: ${{ github.event.issue.title }}
7871
REQUESTER: ${{ github.event.issue.user.login }}
79-
# Skip Confluence creation in preprocessing - will be done in parallel job
80-
CONFLUENCE_URL: ""
81-
CONFLUENCE_EMAIL: ""
82-
CONFLUENCE_API_TOKEN: ""
83-
CONFLUENCE_SPACE_KEY: ""
84-
CONFLUENCE_PARENT_PAGE_ID: ""
8572
GITHUB_RUN_ID: ${{ github.run_id }}
8673
run: |
74+
set -e
8775
OUTPUT=$(node .github/agent/preprocess-task.mjs 2>&1)
8876
echo "$OUTPUT"
8977
90-
# Extract enhanced task from output
9178
if echo "$OUTPUT" | grep -q "ENHANCED_TASK_START"; then
92-
ENHANCED_TASK=$(echo "$OUTPUT" | sed -n '/ENHANCED_TASK_START/,/ENHANCED_TASK_END/p' | sed '1d;$d')
93-
echo "enhanced_task<<EOF" >> $GITHUB_OUTPUT
94-
echo "$ENHANCED_TASK" >> $GITHUB_OUTPUT
95-
echo "EOF" >> $GITHUB_OUTPUT
96-
else
97-
# Fallback to original task
98-
echo "enhanced_task=${{ github.event.issue.title }}" >> $GITHUB_OUTPUT
99-
100-
# Extract JSON if available
101-
JSON_LINE=$(echo "$OUTPUT" | grep "ENHANCED_TASK_JSON:" || true)
102-
if [ -n "$JSON_LINE" ]; then
103-
JSON_DATA=$(echo "$JSON_LINE" | sed 's/ENHANCED_TASK_JSON://')
104-
echo "task_json=$JSON_DATA" >> $GITHUB_OUTPUT
79+
ENHANCED=$(echo "$OUTPUT" | sed -n '/ENHANCED_TASK_START/,/ENHANCED_TASK_END/p' | sed '1d;$d')
10580
else
106-
echo "task_json=null" >> $GITHUB_OUTPUT
81+
ENHANCED="${{ github.event.issue.title }}"
82+
fi
83+
84+
{
85+
echo "enhanced_task<<EOF"
86+
echo "$ENHANCED"
87+
echo "EOF"
88+
} >> "$GITHUB_OUTPUT"
10789
10890
create-confluence:
10991
runs-on: ubuntu-latest
11092
needs: preprocess
11193
permissions:
112-
contents: read
11394
issues: write
11495
outputs:
11596
confluence_url: ${{ steps.confluence.outputs.confluence_url }}
11697
steps:
117-
- name: Checkout develop
118-
uses: actions/checkout@v4
98+
- uses: actions/checkout@v4
11999
with:
120100
ref: develop
121101

122-
- name: Setup Node.js
123-
uses: actions/setup-node@v4
102+
- uses: actions/setup-node@v4
124103
with:
125104
node-version: 20
126-
cache: 'npm'
105+
cache: npm
127106

128-
- name: Install agent dependencies
107+
- name: Install dependencies
129108
working-directory: .github/agent
130109
run: npm install
131110

@@ -140,78 +119,56 @@ jobs:
140119
CONFLUENCE_API_TOKEN: ${{ secrets.CONFLUENCE_API_TOKEN }}
141120
CONFLUENCE_SPACE_KEY: ${{ secrets.CONFLUENCE_SPACE_KEY }}
142121
CONFLUENCE_PARENT_PAGE_ID: ${{ secrets.CONFLUENCE_PARENT_PAGE_ID }}
143-
GITHUB_RUN_ID: ${{ github.run_id }}
144-
GITHUB_REPOSITORY: ${{ github.repository }}
145122
ENHANCED_TASK: ${{ needs.preprocess.outputs.enhanced_task }}
146123
run: |
124+
set -e
147125
OUTPUT=$(node .github/agent/create-confluence.mjs 2>&1)
148126
echo "$OUTPUT"
149127
150-
# Extract Confluence URL
151-
CONFLUENCE_URL=$(echo "$OUTPUT" | grep "CONFLUENCE_URL:" | sed 's/CONFLUENCE_URL://' || echo "")
152-
if [ -n "$CONFLUENCE_URL" ]; then
153-
echo "confluence_url=$CONFLUENCE_URL" >> $GITHUB_OUTPUT
154-
else
155-
echo "confluence_url=" >> $GITHUB_OUTPUT
156-
157-
- name: Add Confluence link to issue
158-
if: steps.confluence.outputs.confluence_url != ''
159-
env:
160-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
161-
CONFLUENCE_URL: ${{ steps.confluence.outputs.confluence_url }}
162-
run: |
163-
# Get current issue body
164-
CURRENT_BODY=$(curl -s "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" \
165-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
166-
-H "Accept: application/vnd.github+json" | jq -r '.body')
167-
168-
# Add Confluence link to the end
169-
UPDATED_BODY=$(jq -n \
170-
--arg current "$CURRENT_BODY" \
171-
--arg confluence "$CONFLUENCE_URL" \
172-
'$current + "\n\n📄 **Requirements documented:** " + $confluence')
173-
174-
# Update issue with Confluence link
175-
PAYLOAD=$(jq -n \
176-
--arg body "$UPDATED_BODY" \
177-
'{body: $body}')
178-
179-
curl -X PATCH "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" \
180-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
181-
-H "Accept: application/vnd.github+json" \
182-
-H "Content-Type: application/json" \
183-
-d "$PAYLOAD"
128+
URL=$(echo "$OUTPUT" | grep "CONFLUENCE_URL:" | sed 's/CONFLUENCE_URL://')
129+
echo "confluence_url=$URL" >> "$GITHUB_OUTPUT"
184130
185-
echo "✅ Added Confluence link to issue"
186-
187-
update-github-issue:
131+
update-issue:
188132
runs-on: ubuntu-latest
189-
needs: preprocess
190-
if: needs.preprocess.outcome == 'success'
133+
needs: [preprocess, create-confluence]
191134
permissions:
192-
contents: read
193135
issues: write
194136
steps:
195137
- name: Update issue body
196138
env:
197139
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
140+
ENHANCED: ${{ needs.preprocess.outputs.enhanced_task }}
141+
CONFLUENCE_URL: ${{ needs.create-confluence.outputs.confluence_url }}
198142
run: |
199143
set -euo pipefail
200-
command -v jq >/dev/null || sudo apt-get update && sudo apt-get install -y jq
201144
202-
TASK_JSON='${{ needs.preprocess.outputs.task_json }}'
203-
if [ "$TASK_JSON" != "null" ] && [ -n "$TASK_JSON" ]; then
204-
ENHANCED=$(echo "$TASK_JSON" | jq -r '.enhanced // empty')
205-
else
206-
ENHANCED='${{ needs.preprocess.outputs.enhanced_task }}'
145+
if ! command -v jq >/dev/null; then
146+
sudo apt-get update
147+
sudo apt-get install -y jq
207148
fi
208149
150+
ORIGINAL=$(curl -s \
151+
-H "Authorization: token $GITHUB_TOKEN" \
152+
-H "Accept: application/vnd.github+json" \
153+
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" \
154+
| jq -r '.body // ""')
155+
209156
BODY=$(jq -n \
210157
--arg enhanced "$ENHANCED" \
211-
--arg original "${{ github.event.issue.body || '' }}" \
158+
--arg original "$ORIGINAL" \
159+
--arg confluence "$CONFLUENCE_URL" \
212160
--arg requester "${{ github.event.issue.user.login }}" \
213161
--arg created "${{ github.event.issue.created_at }}" \
214-
'"## 📝 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')
162+
'"## 📝 Enhanced Feature Request\n\n"
163+
+ $enhanced
164+
+ "\n\n---\n\n📄 **Requirements documented:** "
165+
+ $confluence
166+
+ "\n\n---\n\n## 📋 Original Request\n\n"
167+
+ $original
168+
+ "\n\n---\n\n**Requested by:** "
169+
+ $requester
170+
+ "\n**Created:** "
171+
+ $created')
215172
216173
curl -X PATCH \
217174
-H "Authorization: token $GITHUB_TOKEN" \
@@ -220,30 +177,22 @@ jobs:
220177
-d "$(jq -n --arg body "$BODY" '{body:$body}')" \
221178
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}"
222179
223-
echo "✅ Issue #${{ github.event.issue.number }} updated with enhanced description"
224-
225180
add-comment:
226181
runs-on: ubuntu-latest
227-
needs: update-github-issue
182+
needs: update-issue
228183
permissions:
229184
issues: write
230185
steps:
231-
- name: Add comment to issue
186+
- name: Comment
232187
env:
233188
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
234189
run: |
235-
# Build comment with proper escaping using jq
236-
COMMENT=$(jq -n '"🤖 **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."')
237-
238-
# Use jq to properly construct JSON payload
239-
PAYLOAD=$(jq -n \
240-
--arg body "$COMMENT" \
241-
'{body: $body}')
242-
243-
curl -X POST "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
244-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
245-
-H "Accept: application/vnd.github+json" \
246-
-H "Content-Type: application/json" \
247-
-d "$PAYLOAD"
248-
249-
echo "✅ Added comment to issue"
190+
jq -n \
191+
--arg body "🤖 **Feature request enhanced!**\n\nIssue description and requirements are now structured and documented." \
192+
'{body:$body}' \
193+
| curl -X POST \
194+
-H "Authorization: token $GITHUB_TOKEN" \
195+
-H "Accept: application/vnd.github+json" \
196+
-H "Content-Type: application/json" \
197+
-d @- \
198+
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments"

0 commit comments

Comments
 (0)