Enhance feature request workflow with regex and trimming #21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Enhance Feature Requests | ||
| on: | ||
| issues: | ||
| types: [opened, labeled] | ||
| workflow_dispatch: | ||
| inputs: | ||
| issue_number: | ||
| description: 'Issue number to process (optional)' | ||
| required: false | ||
| type: string | ||
| jobs: | ||
| check-label: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| issues: read | ||
| outputs: | ||
| has_enhancement: ${{ steps.check.outputs.has_enhancement }} | ||
| already_enhanced: ${{ steps.check_enhanced.outputs.already_enhanced }} | ||
| steps: | ||
| - name: Check enhancement label | ||
| id: check | ||
| run: | | ||
| set -e | ||
| echo "Event action: ${{ github.event.action }}" | ||
| echo "Label name: ${{ github.event.label.name }}" | ||
| # Handle labeled events (when a label is added to an existing issue) | ||
| if [ "${{ github.event.action }}" = "labeled" ]; then | ||
| if [ "${{ github.event.label.name }}" = "enhancement" ]; then | ||
| echo "✅ Labeled event with enhancement label" | ||
| echo "has_enhancement=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "❌ Labeled event but label is not 'enhancement'" | ||
| echo "has_enhancement=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| # Handle opened events (when an issue is created, possibly with labels) | ||
| elif [ "${{ github.event.action }}" = "opened" ]; then | ||
| # Use join to get all label names, then check if enhancement is in the list | ||
| LABELS="${{ join(github.event.issue.labels.*.name, ' ') }}" | ||
| echo "Issue labels: $LABELS" | ||
| if [ -n "$LABELS" ] && echo "$LABELS" | grep -qw "enhancement"; then | ||
| echo "✅ Opened event with enhancement label" | ||
| echo "has_enhancement=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "❌ Opened event but no enhancement label found" | ||
| echo "has_enhancement=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| else | ||
| echo "❌ Unknown event action: ${{ github.event.action }}" | ||
| echo "has_enhancement=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| - name: Check if issue already enhanced | ||
| id: check_enhanced | ||
| run: | | ||
| set -e | ||
| BODY="${{ github.event.issue.body }}" | ||
| if echo "$BODY" | grep -qE "## .*Enhanced Feature Request"; then | ||
| echo "already_enhanced=true" >> "$GITHUB_OUTPUT" | ||
| 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' | ||
| outputs: | ||
| enhanced_task: ${{ steps.preprocess.outputs.enhanced_task }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: develop | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: npm | ||
| - name: Install dependencies | ||
| working-directory: .github/agent | ||
| run: npm install | ||
| - name: Preprocess issue | ||
| 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 }} | ||
| GITHUB_RUN_ID: ${{ github.run_id }} | ||
| run: | | ||
| set -e | ||
| OUTPUT=$(node .github/agent/preprocess-task.mjs 2>&1) | ||
| echo "$OUTPUT" | ||
| if echo "$OUTPUT" | grep -q "ENHANCED_TASK_START"; then | ||
| ENHANCED=$(echo "$OUTPUT" | sed -n '/ENHANCED_TASK_START/,/ENHANCED_TASK_END/p' | sed '1d;$d') | ||
| else | ||
| ENHANCED="${{ github.event.issue.title }}" | ||
| fi | ||
| { | ||
| echo "enhanced_task<<EOF" | ||
| echo "$ENHANCED" | ||
| echo "EOF" | ||
| } >> "$GITHUB_OUTPUT" | ||
| create-confluence: | ||
| runs-on: ubuntu-latest | ||
| needs: preprocess | ||
| permissions: | ||
| issues: write | ||
| outputs: | ||
| confluence_url: ${{ steps.confluence.outputs.confluence_url }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: develop | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: npm | ||
| - name: Install dependencies | ||
| working-directory: .github/agent | ||
| run: npm install | ||
| - name: Create Confluence page | ||
| id: confluence | ||
| env: | ||
| TASK: ${{ github.event.issue.title }} | ||
| REQUESTER: ${{ github.event.issue.user.login }} | ||
| ISSUE_NUMBER: ${{ github.event.issue.number }} | ||
| 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 }} | ||
| ENHANCED_TASK: ${{ needs.preprocess.outputs.enhanced_task }} | ||
| run: | | ||
| set -e | ||
| OUTPUT=$(node .github/agent/create-confluence.mjs 2>&1) | ||
| echo "$OUTPUT" | ||
| URL=$(echo "$OUTPUT" | grep "CONFLUENCE_URL:" | sed 's/CONFLUENCE_URL://' | tr -d '[:space:]') | ||
| echo "confluence_url=$URL" >> "$GITHUB_OUTPUT" | ||
| update-issue: | ||
| runs-on: ubuntu-latest | ||
| needs: [preprocess, create-confluence] | ||
| permissions: | ||
| issues: write | ||
| steps: | ||
| - name: Update issue body | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| ENHANCED: ${{ needs.preprocess.outputs.enhanced_task }} | ||
| CONFLUENCE_URL: ${{ needs.create-confluence.outputs.confluence_url }} | ||
| run: | | ||
| set -euo pipefail | ||
| # Ensure jq exists | ||
| if ! command -v jq >/dev/null; then | ||
| sudo apt-get update | ||
| sudo apt-get install -y jq | ||
| fi | ||
| # Fetch original issue body (as-is) | ||
| ORIGINAL=$(curl -s \ | ||
| -H "Authorization: token $GITHUB_TOKEN" \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" \ | ||
| | jq -r '.body // "" | split("## 📝 Enhanced Feature Request")[0] // .') | ||
| # Build Markdown body (NO escaped \n, real newlines) | ||
| MARKDOWN=$(cat <<EOF | ||
| ## 📝 Enhanced Feature Request | ||
| $ENHANCED | ||
| --- | ||
| 📄 **Requirements documented:** ${CONFLUENCE_URL:-_Not available_} | ||
| --- | ||
| ## 📋 Original Request | ||
| $ORIGINAL | ||
| --- | ||
| **Requested by:** ${{ github.event.issue.user.login }} | ||
| **Created:** ${{ github.event.issue.created_at }} | ||
| EOF | ||
| ) | ||
| # Update the issue | ||
| curl -X PATCH \ | ||
| -H "Authorization: token $GITHUB_TOKEN" \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d "$(jq -n --arg body "$MARKDOWN" '{body:$body}')" \ | ||
| "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" | ||
| echo "✅ Issue updated with enhanced + original content" | ||
| add-comment: | ||
| runs-on: ubuntu-latest | ||
| needs: update-issue | ||
| permissions: | ||
| issues: write | ||
| steps: | ||
| - name: Comment | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| COMMENT="🤖 **Feature request enhanced!** | ||
| Issue description and requirements are now structured and documented." | ||
| jq -n --arg body "$COMMENT" '{body:$body}' \ | ||
| | curl -X POST \ | ||
| -H "Authorization: token $GITHUB_TOKEN" \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d @- \ | ||
| "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" | ||