Skip to content

Commit 25b34c0

Browse files
committed
Fix update-github-issue: properly place set -e and jq check at start of run section
1 parent 2b2cd37 commit 25b34c0

1 file changed

Lines changed: 8 additions & 181 deletions

File tree

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

Lines changed: 8 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -14,187 +14,14 @@ jobs:
1414
- name: Check if issue has 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
19-
if [ "${{ github.event.action }}" = "labeled" ]; then
20-
if [ "${{ github.event.label.name }}" = "enhancement" ]; then
21-
echo "has_enhancement=true" >> $GITHUB_OUTPUT
22-
else
23-
echo "has_enhancement=false" >> $GITHUB_OUTPUT
24-
fi
25-
else
26-
# For 'opened' events, check all labels
27-
LABELS="${{ join(github.event.issue.labels.*.name, ',') }}"
28-
if echo "$LABELS" | grep -q "enhancement"; then
29-
echo "has_enhancement=true" >> $GITHUB_OUTPUT
30-
else
31-
echo "has_enhancement=false" >> $GITHUB_OUTPUT
32-
fi
33-
- name: Check if issue already enhanced
34-
id: check-enhanced
35-
run: |
36-
# Check if issue already has enhanced content
37-
ISSUE_BODY="${{ github.event.issue.body }}"
38-
if echo "$ISSUE_BODY" | grep -q "Enhanced Feature Request"; then
39-
echo "already_enhanced=true" >> $GITHUB_OUTPUT
40-
echo "Issue already has enhanced content, skipping"
41-
else
42-
echo "already_enhanced=false" >> $GITHUB_OUTPUT
43-
44-
preprocess:
45-
runs-on: ubuntu-latest
46-
needs: check-label
47-
if: needs.check-label.outputs.has_enhancement == 'true' && needs.check-label.outputs.already_enhanced == 'false'
48-
permissions:
49-
contents: read
50-
outputs:
51-
enhanced_task: ${{ steps.preprocess.outputs.enhanced_task }}
52-
task_json: ${{ steps.preprocess.outputs.task_json }}
53-
steps:
54-
- name: Checkout develop
55-
uses: actions/checkout@v4
56-
with:
57-
ref: develop
58-
59-
- name: Setup Node.js
60-
uses: actions/setup-node@v4
61-
with:
62-
node-version: 20
63-
cache: 'npm'
64-
65-
- name: Install agent dependencies
66-
working-directory: .github/agent
67-
run: npm install
68-
69-
- name: Preprocess feature request to user story (OpenAI only)
70-
id: preprocess
71-
env:
72-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
73-
PREPROCESSING_MODEL: ${{ secrets.PREPROCESSING_MODEL }}
74-
TASK: ${{ github.event.issue.title }}
75-
REQUESTER: ${{ github.event.issue.user.login }}
76-
# Skip Confluence creation in preprocessing - will be done in parallel job
77-
CONFLUENCE_URL: ""
78-
CONFLUENCE_EMAIL: ""
79-
CONFLUENCE_API_TOKEN: ""
80-
CONFLUENCE_SPACE_KEY: ""
81-
CONFLUENCE_PARENT_PAGE_ID: ""
82-
GITHUB_RUN_ID: ${{ github.run_id }}
83-
run: |
84-
OUTPUT=$(node .github/agent/preprocess-task.mjs 2>&1)
85-
echo "$OUTPUT"
86-
87-
# Extract enhanced task from output
88-
if echo "$OUTPUT" | grep -q "ENHANCED_TASK_START"; then
89-
ENHANCED_TASK=$(echo "$OUTPUT" | sed -n '/ENHANCED_TASK_START/,/ENHANCED_TASK_END/p' | sed '1d;$d')
90-
echo "enhanced_task<<EOF" >> $GITHUB_OUTPUT
91-
echo "$ENHANCED_TASK" >> $GITHUB_OUTPUT
92-
echo "EOF" >> $GITHUB_OUTPUT
93-
else
94-
# Fallback to original task
95-
echo "enhanced_task=${{ github.event.issue.title }}" >> $GITHUB_OUTPUT
96-
97-
# Extract JSON if available
98-
JSON_LINE=$(echo "$OUTPUT" | grep "ENHANCED_TASK_JSON:" || true)
99-
if [ -n "$JSON_LINE" ]; then
100-
JSON_DATA=$(echo "$JSON_LINE" | sed 's/ENHANCED_TASK_JSON://')
101-
echo "task_json=$JSON_DATA" >> $GITHUB_OUTPUT
102-
else
103-
echo "task_json=null" >> $GITHUB_OUTPUT
104-
105-
create-confluence:
106-
runs-on: ubuntu-latest
107-
needs: preprocess
108-
permissions:
109-
contents: read
110-
issues: write
111-
outputs:
112-
confluence_url: ${{ steps.confluence.outputs.confluence_url }}
113-
steps:
114-
- name: Checkout develop
115-
uses: actions/checkout@v4
116-
with:
117-
ref: develop
118-
119-
- name: Setup Node.js
120-
uses: actions/setup-node@v4
121-
with:
122-
node-version: 20
123-
cache: 'npm'
124-
125-
- name: Install agent dependencies
126-
working-directory: .github/agent
127-
run: npm install
128-
129-
- name: Create Confluence page
130-
id: confluence
131-
env:
132-
TASK: ${{ github.event.issue.title }}
133-
REQUESTER: ${{ github.event.issue.user.login }}
134-
ISSUE_NUMBER: ${{ github.event.issue.number }}
135-
CONFLUENCE_URL: ${{ secrets.CONFLUENCE_URL }}
136-
CONFLUENCE_EMAIL: ${{ secrets.CONFLUENCE_EMAIL }}
137-
CONFLUENCE_API_TOKEN: ${{ secrets.CONFLUENCE_API_TOKEN }}
138-
CONFLUENCE_SPACE_KEY: ${{ secrets.CONFLUENCE_SPACE_KEY }}
139-
CONFLUENCE_PARENT_PAGE_ID: ${{ secrets.CONFLUENCE_PARENT_PAGE_ID }}
140-
GITHUB_RUN_ID: ${{ github.run_id }}
141-
GITHUB_REPOSITORY: ${{ github.repository }}
142-
ENHANCED_TASK: ${{ needs.preprocess.outputs.enhanced_task }}
143-
run: |
144-
OUTPUT=$(node .github/agent/create-confluence.mjs 2>&1)
145-
echo "$OUTPUT"
146-
147-
# Extract Confluence URL
148-
CONFLUENCE_URL=$(echo "$OUTPUT" | grep "CONFLUENCE_URL:" | sed 's/CONFLUENCE_URL://' || echo "")
149-
if [ -n "$CONFLUENCE_URL" ]; then
150-
echo "confluence_url=$CONFLUENCE_URL" >> $GITHUB_OUTPUT
151-
else
152-
echo "confluence_url=" >> $GITHUB_OUTPUT
153-
154-
- name: Add Confluence link to issue
155-
if: steps.confluence.outputs.confluence_url != ''
156-
env:
157-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158-
CONFLUENCE_URL: ${{ steps.confluence.outputs.confluence_url }}
159-
run: |
160-
# Get current issue body
161-
CURRENT_BODY=$(curl -s "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" \
162-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
163-
-H "Accept: application/vnd.github+json" | jq -r '.body')
164-
165-
# Add Confluence link to the end
166-
UPDATED_BODY=$(jq -n \
167-
--arg current "$CURRENT_BODY" \
168-
--arg confluence "$CONFLUENCE_URL" \
169-
'$current + "\n\n📄 **Requirements documented:** " + $confluence')
170-
171-
# Update issue with Confluence link
172-
PAYLOAD=$(jq -n \
173-
--arg body "$UPDATED_BODY" \
174-
'{body: $body}')
175-
176-
curl -X PATCH "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" \
177-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
178-
-H "Accept: application/vnd.github+json" \
179-
-H "Content-Type: application/json" \
180-
-d "$PAYLOAD"
181-
182-
echo "✅ Added Confluence link to issue"
183-
184-
update-github-issue:
185-
runs-on: ubuntu-latest
186-
needs: preprocess
187-
if: needs.preprocess.outcome == 'success'
188-
permissions:
189-
contents: read
190-
issues: write
191-
steps:
192-
- name: Update GitHub issue with enhanced description
193-
env:
194-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
195-
ISSUE_NUMBER: ${{ github.event.issue.number }}
196-
197-
run: |
17+
set -e # Exit on error
18+
19+
# Ensure jq is available
20+
if ! command -v jq &> /dev/null; then
21+
echo "⚠️ jq not found, installing..."
22+
sudo apt-get update && sudo apt-get install -y jq
23+
fi
24+
19825
# Read enhanced task from JSON output to avoid shell quoting issues
19926
TASK_JSON="${{ needs.preprocess.outputs.task_json }}"
20027
if [ -n "$TASK_JSON" ] && [ "$TASK_JSON" != "null" ]; then

0 commit comments

Comments
 (0)