create a function that is called bugreport. Should work the same way as featurerequest but for bug reporting instead. Label should be bug. #11
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] | |
| 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 | |
| - 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 | |
| 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 }} | |
| steps: | |
| - name: Checkout develop | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: develop | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - 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 | |
| # 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 | |
| create-confluence: | |
| runs-on: ubuntu-latest | |
| needs: preprocess | |
| permissions: | |
| contents: read | |
| issues: write | |
| outputs: | |
| confluence_url: ${{ steps.confluence.outputs.confluence_url }} | |
| steps: | |
| - name: Checkout develop | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: develop | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - name: Install agent 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 }} | |
| GITHUB_RUN_ID: ${{ github.run_id }} | |
| GITHUB_REPOSITORY: ${{ github.repository }} | |
| ENHANCED_TASK: ${{ needs.preprocess.outputs.enhanced_task }} | |
| run: | | |
| OUTPUT=$(node .github/agent/create-confluence.mjs 2>&1) | |
| echo "$OUTPUT" | |
| # Extract Confluence URL | |
| CONFLUENCE_URL=$(echo "$OUTPUT" | grep "CONFLUENCE_URL:" | sed 's/CONFLUENCE_URL://' || echo "") | |
| if [ -n "$CONFLUENCE_URL" ]; then | |
| echo "confluence_url=$CONFLUENCE_URL" >> $GITHUB_OUTPUT | |
| else | |
| echo "confluence_url=" >> $GITHUB_OUTPUT | |
| - name: Add Confluence link to issue | |
| if: steps.confluence.outputs.confluence_url != '' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| CONFLUENCE_URL: ${{ steps.confluence.outputs.confluence_url }} | |
| run: | | |
| # 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 -n \ | |
| --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" | |
| 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: | | |
| set -e # Exit on error | |
| # Ensure jq is available (should be pre-installed in ubuntu-latest) | |
| if ! command -v jq &> /dev/null; then | |
| echo "⚠️ jq not found, installing..." | |
| sudo apt-get update && sudo apt-get install -y jq | |
| fi | |
| # 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 | |
| ENHANCED_BODY=$(jq -n \ | |
| --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') | |
| # 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-comment: | |
| runs-on: ubuntu-latest | |
| needs: update-github-issue | |
| permissions: | |
| issues: write | |
| steps: | |
| - name: Add comment to issue | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Build comment with proper escaping using jq | |
| 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."') | |
| # 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" | |
| echo "✅ Added comment to issue" |