|
| 1 | +name: AI Triage - Label and Comment on New Issues |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + issue_number: |
| 9 | + description: 'Issue number to triage (manual run). e.g. 123' |
| 10 | + required: true |
| 11 | + |
| 12 | +permissions: |
| 13 | + issues: write |
| 14 | + contents: read |
| 15 | + |
| 16 | +jobs: |
| 17 | + label_and_comment: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v2 |
| 23 | + |
| 24 | + - name: Get issue data |
| 25 | + id: get_issue |
| 26 | + uses: actions/github-script@v6 |
| 27 | + with: |
| 28 | + script: | |
| 29 | + const eventName = context.eventName; |
| 30 | + let issue; |
| 31 | + if (eventName === 'workflow_dispatch') { |
| 32 | + const inputs = context.payload.inputs || {}; |
| 33 | + const issueNumber = inputs.issue_number || inputs.issueNumber; |
| 34 | + if (!issueNumber) core.setFailed('Input issue_number is required for manual run.'); |
| 35 | + const { data } = await github.rest.issues.get({ |
| 36 | + owner: context.repo.owner, |
| 37 | + repo: context.repo.repo, |
| 38 | + issue_number: parseInt(issueNumber, 10), |
| 39 | + }); |
| 40 | + issue = data; |
| 41 | + } else if (context.payload.issue) { |
| 42 | + issue = context.payload.issue; |
| 43 | + } else { |
| 44 | + core.setFailed('No issue information found in the event payload.'); |
| 45 | + } |
| 46 | + core.setOutput('id', String(issue.number)); |
| 47 | + core.setOutput('user', String((issue.user && issue.user.login) || '')); |
| 48 | + core.setOutput('title', String(issue.title || '')); |
| 49 | + core.setOutput('body', String(issue.body || '')); |
| 50 | + const labelNames = (issue.labels || []).map(label => label.name); |
| 51 | + core.setOutput('labels', JSON.stringify(labelNames)); |
| 52 | +
|
| 53 | + - name: Call Azure Function |
| 54 | + id: call_azure_function |
| 55 | + env: |
| 56 | + PAYLOAD: >- |
| 57 | + { |
| 58 | + "authToken": "${{ secrets.GITHUB_TOKEN }}", |
| 59 | + "repoId": "microsoft/vscode-java-debug", |
| 60 | + "issueData": { |
| 61 | + "id": ${{ steps.get_issue.outputs.id }}, |
| 62 | + "user": ${{ toJson(steps.get_issue.outputs.user) }}, |
| 63 | + "title": ${{ toJson(steps.get_issue.outputs.title) }}, |
| 64 | + "body": ${{ toJson(steps.get_issue.outputs.body) }}, |
| 65 | + "labels": ${{ steps.get_issue.outputs.labels }} |
| 66 | + }, |
| 67 | + "mode": "DirectUpdate" |
| 68 | + } |
| 69 | +
|
| 70 | + run: | |
| 71 | + # Make the HTTP request with improved error handling and timeouts |
| 72 | + echo "Making request to triage agent..." |
| 73 | +
|
| 74 | + # Add timeout handling and better error detection |
| 75 | + set +e # Don't exit on curl failure |
| 76 | + response=$(timeout ${{ vars.TRIAGE_AGENT_TIMEOUT }} curl \ |
| 77 | + --max-time 0 \ |
| 78 | + --connect-timeout 30 \ |
| 79 | + --fail-with-body \ |
| 80 | + --silent \ |
| 81 | + --show-error \ |
| 82 | + --write-out "HTTPSTATUS:%{http_code}" \ |
| 83 | + --header "Content-Type: application/json" \ |
| 84 | + --request POST \ |
| 85 | + --data "$PAYLOAD" \ |
| 86 | + ${{ secrets.TRIAGE_FUNCTION_LINK }} 2>&1) |
| 87 | +
|
| 88 | + curl_exit_code=$? |
| 89 | + set -e # Re-enable exit on error |
| 90 | +
|
| 91 | + echo "Curl exit code: $curl_exit_code" |
| 92 | +
|
| 93 | + # Check if curl command timed out or failed |
| 94 | + if [ $curl_exit_code -eq 124 ]; then |
| 95 | + echo "❌ Request timed out after 650 seconds" |
| 96 | + exit 1 |
| 97 | + elif [ $curl_exit_code -ne 0 ]; then |
| 98 | + echo "❌ Curl command failed with exit code: $curl_exit_code" |
| 99 | + echo "Response: $response" |
| 100 | + exit 1 |
| 101 | + fi |
| 102 | +
|
| 103 | + # Extract HTTP status code and response body |
| 104 | + http_code=$(echo "$response" | grep -o "HTTPSTATUS:[0-9]*" | cut -d: -f2) |
| 105 | + response_body=$(echo "$response" | sed 's/HTTPSTATUS:[0-9]*$//') |
| 106 | +
|
| 107 | + echo "HTTP Status Code: $http_code" |
| 108 | +
|
| 109 | + # Validate HTTP status code |
| 110 | + if [ -z "$http_code" ]; then |
| 111 | + echo "❌ Failed to extract HTTP status code from response" |
| 112 | + echo "Raw response: $response" |
| 113 | + exit 1 |
| 114 | + fi |
| 115 | +
|
| 116 | + # Check if the request was successful |
| 117 | + if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then |
| 118 | + echo "✅ Azure Function call succeeded" |
| 119 | + else |
| 120 | + echo "❌ Azure Function call failed with status code: $http_code" |
| 121 | + echo "Response: $response_body" |
| 122 | + exit 1 |
| 123 | + fi |
0 commit comments