Enable create-instance command #67
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: Auto-Triage Issues | |
| on: | |
| issues: | |
| types: [opened, edited] | |
| permissions: | |
| issues: write | |
| contents: read | |
| pull-requests: write | |
| actions: read | |
| jobs: | |
| triage: | |
| runs-on: ubuntu-latest | |
| name: Auto-triage issue with AI | |
| # Skip if triggered by bot to avoid infinite loops | |
| if: github.actor != 'github-actions[bot]' && github.actor != 'dependabot[bot]' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| cd autoTriage | |
| pip install -r requirements.txt | |
| - name: Determine issue number | |
| id: issue | |
| run: | | |
| # Get issue number from the issues event payload | |
| echo "number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT | |
| # Check if this is a re-triage (not a new issue) | |
| if [ "${{ github.event.action }}" == "opened" ]; then | |
| echo "retriage=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "retriage=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Run triage analysis | |
| id: triage | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # GitHub Models (optional) | |
| GITHUB_MODELS_KEY: ${{ secrets.MODELS_API_KEY }} | |
| GITHUB_MODELS_ENDPOINT: https://models.inference.ai.azure.com | |
| GITHUB_MODELS_MODEL: gpt-4o-mini | |
| # Azure OpenAI (takes precedence if set) | |
| AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }} | |
| AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }} | |
| AZURE_OPENAI_DEPLOYMENT: ${{ secrets.AZURE_OPENAI_DEPLOYMENT }} | |
| AZURE_OPENAI_API_VERSION: ${{ secrets.AZURE_OPENAI_API_VERSION }} | |
| run: | | |
| cd autoTriage | |
| # Build args array | |
| ARGS=( | |
| --owner "${{ github.repository_owner }}" | |
| --repo "${{ github.event.repository.name }}" | |
| --issue-number "${{ steps.issue.outputs.number }}" | |
| --output "${{ runner.temp }}/triage_result.json" | |
| --apply | |
| ) | |
| if [ "${{ steps.issue.outputs.retriage }}" == "true" ]; then | |
| ARGS+=(--retriage) | |
| fi | |
| python cli/triage_issue.py "${ARGS[@]}" | |
| - name: Post triage results | |
| if: success() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| // Read triage result from cross-platform temp directory | |
| const triageResultPath = path.join(process.env.RUNNER_TEMP, 'triage_result.json'); | |
| let triageResult; | |
| try { | |
| triageResult = JSON.parse(fs.readFileSync(triageResultPath, 'utf8')); | |
| console.log('Triage result loaded:', JSON.stringify(triageResult, null, 2)); | |
| } catch (error) { | |
| console.log('No triage result file found, skipping comment'); | |
| return; | |
| } | |
| // Format rationale | |
| let rationaleText = 'No rationale provided'; | |
| if (triageResult.rationale) { | |
| if (typeof triageResult.rationale === 'object') { | |
| rationaleText = Object.entries(triageResult.rationale) | |
| .map(([key, value]) => `**${key.replace(/_/g, ' ')}:** ${value}`) | |
| .join('\n\n'); | |
| } else { | |
| rationaleText = triageResult.rationale; | |
| } | |
| } | |
| // Build comment body | |
| let comment = '## [AUTO-TRIAGE] Results\n\n'; | |
| comment += `**Classification:** ${triageResult.issue_type || 'Unknown'}\n`; | |
| comment += `**Priority:** ${triageResult.priority || 'P3'}\n`; | |
| comment += `**Confidence:** ${triageResult.confidence ? (triageResult.confidence * 100).toFixed(1) + '%' : 'N/A'}\n\n`; | |
| if (triageResult.recommended_assignee) { | |
| comment += `**Recommended Assignee:** @${triageResult.recommended_assignee}\n\n`; | |
| } | |
| comment += '**Analysis:**\n'; | |
| comment += rationaleText + '\n\n'; | |
| if (triageResult.is_copilot_fixable) { | |
| comment += '[OK] This issue appears to be Copilot-fixable!\n\n'; | |
| } | |
| // Add fix suggestions if available | |
| if (triageResult.fix_suggestions && triageResult.fix_suggestions.length > 0) { | |
| comment += '### [SUGGESTION] Suggested Approach\n\n'; | |
| triageResult.fix_suggestions.forEach((suggestion, index) => { | |
| comment += `${index + 1}. ${suggestion}\n`; | |
| }); | |
| comment += '\n'; | |
| } | |
| comment += '---\n*Generated by TeamAssistant Auto-Triage powered by GitHub Models*'; | |
| // Post comment | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: comment | |
| }); | |
| // Add labels if available | |
| const labels = []; | |
| if (triageResult.priority) { | |
| labels.push(triageResult.priority); | |
| } | |
| if (triageResult.issue_type) { | |
| labels.push(triageResult.issue_type.toLowerCase()); | |
| } | |
| console.log('Labels to add:', labels); | |
| if (labels.length > 0) { | |
| try { | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| labels: labels | |
| }); | |
| console.log('Successfully added labels:', labels); | |
| } catch (error) { | |
| console.log('Failed to add labels (may not exist):', error.message); | |
| console.log('Full error:', JSON.stringify(error, null, 2)); | |
| } | |
| } else { | |
| console.log('No labels to add'); | |
| } | |
| // Assign if recommended | |
| console.log('Recommended assignee:', triageResult.recommended_assignee); | |
| if (triageResult.recommended_assignee) { | |
| console.log('Attempting to assign:', triageResult.recommended_assignee); | |
| try { | |
| await github.rest.issues.addAssignees({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| assignees: [triageResult.recommended_assignee] | |
| }); | |
| console.log('Successfully assigned:', triageResult.recommended_assignee); | |
| } catch (error) { | |
| console.log('Failed to assign user:', error.message); | |
| console.log('Full error:', JSON.stringify(error, null, 2)); | |
| } | |
| } else { | |
| console.log('No recommended assignee in triage result'); | |
| } |