Skip to content

Commit d9c01b9

Browse files
authored
Enhance feature request workflow with required inputs
Updated workflow to require issue number and enhanced label checks. Improved issue processing and output handling.
1 parent 844dd47 commit d9c01b9

1 file changed

Lines changed: 113 additions & 102 deletions

File tree

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

Lines changed: 113 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,67 @@ on:
66
workflow_dispatch:
77
inputs:
88
issue_number:
9-
description: 'Issue number to process (optional)'
10-
required: false
9+
description: 'Issue number to process'
10+
required: true
1111
type: string
1212

13+
permissions:
14+
issues: write
15+
contents: read
16+
1317
jobs:
1418
check-label:
1519
runs-on: ubuntu-latest
16-
permissions:
17-
issues: read
1820
outputs:
1921
has_enhancement: ${{ steps.check.outputs.has_enhancement }}
20-
already_enhanced: ${{ steps.check_enhanced.outputs.already_enhanced }}
22+
already_enhanced: ${{ steps.check.outputs.already_enhanced }}
23+
issue_number: ${{ steps.set_issue.outputs.issue_number }}
2124
steps:
22-
- name: Check enhancement label
25+
- name: Set issue number
26+
id: set_issue
27+
run: |
28+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
29+
echo "issue_number=${{ inputs.issue_number }}" >> "$GITHUB_OUTPUT"
30+
else
31+
echo "issue_number=${{ github.event.issue.number }}" >> "$GITHUB_OUTPUT"
32+
fi
33+
34+
- name: Fetch and check issue
2335
id: check
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
ISSUE_NUMBER: ${{ steps.set_issue.outputs.issue_number }}
2439
run: |
2540
set -e
26-
27-
echo "Event action: ${{ github.event.action }}"
28-
echo "Label name: ${{ github.event.label.name }}"
29-
30-
# Handle labeled events (when a label is added to an existing issue)
31-
if [ "${{ github.event.action }}" = "labeled" ]; then
32-
if [ "${{ github.event.label.name }}" = "enhancement" ]; then
33-
echo "✅ Labeled event with enhancement label"
34-
echo "has_enhancement=true" >> "$GITHUB_OUTPUT"
35-
else
36-
echo "❌ Labeled event but label is not 'enhancement'"
37-
echo "has_enhancement=false" >> "$GITHUB_OUTPUT"
38-
fi
39-
# Handle opened events (when an issue is created, possibly with labels)
40-
elif [ "${{ github.event.action }}" = "opened" ]; then
41-
# Use join to get all label names, then check if enhancement is in the list
42-
LABELS="${{ join(github.event.issue.labels.*.name, ' ') }}"
43-
echo "Issue labels: $LABELS"
44-
45-
if [ -n "$LABELS" ] && echo "$LABELS" | grep -qw "enhancement"; then
46-
echo "✅ Opened event with enhancement label"
47-
echo "has_enhancement=true" >> "$GITHUB_OUTPUT"
48-
else
49-
echo "❌ Opened event but no enhancement label found"
50-
echo "has_enhancement=false" >> "$GITHUB_OUTPUT"
51-
fi
41+
42+
# Fetch issue data
43+
ISSUE_JSON=$(curl -s \
44+
-H "Authorization: token $GITHUB_TOKEN" \
45+
-H "Accept: application/vnd.github+json" \
46+
"https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER")
47+
48+
# Write to temp file for safe parsing
49+
echo "$ISSUE_JSON" > /tmp/issue.json
50+
51+
# Extract labels
52+
LABELS=$(jq -r '.labels[].name' /tmp/issue.json)
53+
54+
# Check for enhancement label (word boundary, not exact line)
55+
if echo "$LABELS" | grep -qw "enhancement"; then
56+
echo "✅ Issue has enhancement label"
57+
echo "has_enhancement=true" >> "$GITHUB_OUTPUT"
5258
else
53-
echo "❌ Unknown event action: ${{ github.event.action }}"
59+
echo "❌ No enhancement label found"
5460
echo "has_enhancement=false" >> "$GITHUB_OUTPUT"
5561
fi
5662
57-
58-
- name: Check if issue already enhanced
59-
id: check_enhanced
60-
run: |
61-
set -e
62-
BODY="${{ github.event.issue.body }}"
63-
if echo "$BODY" | grep -qE "## .*Enhanced Feature Request"; then
63+
# Check if already enhanced
64+
BODY=$(jq -r '.body // ""' /tmp/issue.json)
65+
if echo "$BODY" | grep -qF "## 📝 Enhanced Feature Request"; then
66+
echo "⚠️ Issue already enhanced - skipping"
6467
echo "already_enhanced=true" >> "$GITHUB_OUTPUT"
6568
else
69+
echo "✅ Issue not yet enhanced"
6670
echo "already_enhanced=false" >> "$GITHUB_OUTPUT"
6771
fi
6872
@@ -72,6 +76,10 @@ jobs:
7276
if: needs.check-label.outputs.has_enhancement == 'true' && needs.check-label.outputs.already_enhanced == 'false'
7377
outputs:
7478
enhanced_task: ${{ steps.preprocess.outputs.enhanced_task }}
79+
issue_title: ${{ steps.fetch.outputs.issue_title }}
80+
issue_user: ${{ steps.fetch.outputs.issue_user }}
81+
issue_body: ${{ steps.fetch.outputs.issue_body }}
82+
issue_created: ${{ steps.fetch.outputs.issue_created }}
7583
steps:
7684
- uses: actions/checkout@v4
7785
with:
@@ -86,13 +94,38 @@ jobs:
8694
working-directory: .github/agent
8795
run: npm install
8896

97+
- name: Fetch full issue data
98+
id: fetch
99+
env:
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
ISSUE_NUMBER: ${{ needs.check-label.outputs.issue_number }}
102+
run: |
103+
ISSUE_JSON=$(curl -s \
104+
-H "Authorization: token $GITHUB_TOKEN" \
105+
-H "Accept: application/vnd.github+json" \
106+
"https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER")
107+
108+
TITLE=$(echo "$ISSUE_JSON" | jq -r '.title')
109+
USER=$(echo "$ISSUE_JSON" | jq -r '.user.login')
110+
BODY=$(echo "$ISSUE_JSON" | jq -r '.body // ""')
111+
CREATED=$(echo "$ISSUE_JSON" | jq -r '.created_at')
112+
113+
echo "issue_title=$TITLE" >> "$GITHUB_OUTPUT"
114+
echo "issue_user=$USER" >> "$GITHUB_OUTPUT"
115+
echo "issue_created=$CREATED" >> "$GITHUB_OUTPUT"
116+
{
117+
echo "issue_body<<EOF"
118+
echo "$BODY"
119+
echo "EOF"
120+
} >> "$GITHUB_OUTPUT"
121+
89122
- name: Preprocess issue
90123
id: preprocess
91124
env:
92125
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
93126
PREPROCESSING_MODEL: ${{ secrets.PREPROCESSING_MODEL }}
94-
TASK: ${{ github.event.issue.title }}
95-
REQUESTER: ${{ github.event.issue.user.login }}
127+
TASK: ${{ steps.fetch.outputs.issue_title }}
128+
REQUESTER: ${{ steps.fetch.outputs.issue_user }}
96129
GITHUB_RUN_ID: ${{ github.run_id }}
97130
run: |
98131
set -e
@@ -102,7 +135,7 @@ jobs:
102135
if echo "$OUTPUT" | grep -q "ENHANCED_TASK_START"; then
103136
ENHANCED=$(echo "$OUTPUT" | sed -n '/ENHANCED_TASK_START/,/ENHANCED_TASK_END/p' | sed '1d;$d')
104137
else
105-
ENHANCED="${{ github.event.issue.title }}"
138+
ENHANCED="$TASK"
106139
fi
107140
108141
{
@@ -113,9 +146,7 @@ jobs:
113146
114147
create-confluence:
115148
runs-on: ubuntu-latest
116-
needs: preprocess
117-
permissions:
118-
issues: write
149+
needs: [check-label, preprocess]
119150
outputs:
120151
confluence_url: ${{ steps.confluence.outputs.confluence_url }}
121152
steps:
@@ -135,9 +166,9 @@ jobs:
135166
- name: Create Confluence page
136167
id: confluence
137168
env:
138-
TASK: ${{ github.event.issue.title }}
139-
REQUESTER: ${{ github.event.issue.user.login }}
140-
ISSUE_NUMBER: ${{ github.event.issue.number }}
169+
TASK: ${{ needs.preprocess.outputs.issue_title }}
170+
REQUESTER: ${{ needs.preprocess.outputs.issue_user }}
171+
ISSUE_NUMBER: ${{ needs.check-label.outputs.issue_number }}
141172
CONFLUENCE_URL: ${{ secrets.CONFLUENCE_URL }}
142173
CONFLUENCE_EMAIL: ${{ secrets.CONFLUENCE_EMAIL }}
143174
CONFLUENCE_API_TOKEN: ${{ secrets.CONFLUENCE_API_TOKEN }}
@@ -154,76 +185,56 @@ jobs:
154185
155186
update-issue:
156187
runs-on: ubuntu-latest
157-
needs: [preprocess, create-confluence]
158-
permissions:
159-
issues: write
188+
needs: [check-label, preprocess, create-confluence]
160189
steps:
161190
- name: Update issue body
162191
env:
163192
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164-
ENHANCED: ${{ needs.preprocess.outputs.enhanced_task }}
165-
CONFLUENCE_URL: ${{ needs.create-confluence.outputs.confluence_url }}
193+
ISSUE_NUMBER: ${{ needs.check-label.outputs.issue_number }}
166194
run: |
167195
set -euo pipefail
168196
169-
# Ensure jq exists
170-
if ! command -v jq >/dev/null; then
171-
sudo apt-get update
172-
sudo apt-get install -y jq
173-
fi
174-
175-
# Fetch original issue body (as-is)
176-
ORIGINAL=$(curl -s \
177-
-H "Authorization: token $GITHUB_TOKEN" \
178-
-H "Accept: application/vnd.github+json" \
179-
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" \
180-
| jq -r '.body // "" | split("## 📝 Enhanced Feature Request")[0] // .')
181-
182-
183-
# Build Markdown body (NO escaped \n, real newlines)
184-
MARKDOWN=$(cat <<EOF
185-
## 📝 Enhanced Feature Request
186-
187-
$ENHANCED
188-
189-
---
190-
191-
📄 **Requirements documented:** ${CONFLUENCE_URL:-_Not available_}
192-
193-
---
194-
195-
## 📋 Original Request
196-
197-
$ORIGINAL
198-
199-
---
200-
201-
**Requested by:** ${{ github.event.issue.user.login }}
202-
**Created:** ${{ github.event.issue.created_at }}
203-
EOF
204-
)
205-
206-
# Update the issue
207-
curl -X PATCH \
208-
-H "Authorization: token $GITHUB_TOKEN" \
209-
-H "Accept: application/vnd.github+json" \
210-
-H "Content-Type: application/json" \
211-
-d "$(jq -n --arg body "$MARKDOWN" '{body:$body}')" \
212-
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}"
197+
# Use jq to safely build JSON with proper escaping
198+
jq -n \
199+
--arg enhanced "${{ needs.preprocess.outputs.enhanced_task }}" \
200+
--arg confluence "${{ needs.create-confluence.outputs.confluence_url }}" \
201+
--arg original "${{ needs.preprocess.outputs.issue_body }}" \
202+
--arg requester "${{ needs.preprocess.outputs.issue_user }}" \
203+
--arg created "${{ needs.preprocess.outputs.issue_created }}" \
204+
'{
205+
body: (
206+
"## 📝 Enhanced Feature Request\n\n" +
207+
$enhanced +
208+
"\n\n---\n\n" +
209+
"📄 **Requirements documented:** " +
210+
(if $confluence != "" then $confluence else "_Not available_" end) +
211+
"\n\n---\n\n" +
212+
"## 📋 Original Request\n\n" +
213+
$original +
214+
"\n\n---\n\n" +
215+
"**Requested by:** " + $requester + "\n" +
216+
"**Created:** " + $created
217+
)
218+
}' \
219+
| curl -X PATCH \
220+
-H "Authorization: token $GITHUB_TOKEN" \
221+
-H "Accept: application/vnd.github+json" \
222+
-H "Content-Type: application/json" \
223+
-d @- \
224+
"https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER"
213225
214226
echo "✅ Issue updated with enhanced + original content"
215227
216228
217229
218230
add-comment:
219231
runs-on: ubuntu-latest
220-
needs: update-issue
221-
permissions:
222-
issues: write
232+
needs: [check-label, update-issue]
223233
steps:
224234
- name: Comment
225235
env:
226236
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
237+
ISSUE_NUMBER: ${{ needs.check-label.outputs.issue_number }}
227238
run: |
228239
COMMENT="🤖 **Feature request enhanced!**
229240
@@ -235,4 +246,4 @@ EOF
235246
-H "Accept: application/vnd.github+json" \
236247
-H "Content-Type: application/json" \
237248
-d @- \
238-
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments"
249+
"https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER/comments"

0 commit comments

Comments
 (0)