-
Notifications
You must be signed in to change notification settings - Fork 215
163 lines (149 loc) · 5.99 KB
/
issue-triage.yml
File metadata and controls
163 lines (149 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
name: Issue Triage
on:
issues:
types: [opened]
# Limit concurrent runs to prevent race conditions on Gist updates
concurrency:
group: issue-triage
cancel-in-progress: false
jobs:
triage:
name: AI Issue Triage
runs-on: ubuntu-latest
# Don't run on issues created by bots
if: github.actor != 'github-actions[bot]' && github.actor != 'dependabot[bot]'
permissions:
issues: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
.github/scripts
sparse-checkout-cone-mode: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Run AI Triage
id: triage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIST_PAT: ${{ secrets.GIST_PAT }}
GIST_ID: ${{ secrets.GIST_ID }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_BODY: ${{ github.event.issue.body }}
ISSUE_URL: ${{ github.event.issue.html_url }}
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
run: node .github/scripts/triage-issue.js
- name: Summary
if: always()
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
TRIAGE_LABELS: ${{ steps.triage.outputs.labels }}
TRIAGE_SUMMARY: ${{ steps.triage.outputs.summary }}
TRIAGE_CONFIDENCE: ${{ steps.triage.outputs.confidence }}
run: |
echo "## Issue Triage Results" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Issue:** #$ISSUE_NUMBER" >> "$GITHUB_STEP_SUMMARY"
echo "**Title:** $ISSUE_TITLE" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
if [ -n "$TRIAGE_LABELS" ]; then
echo "**Labels Applied:** $TRIAGE_LABELS" >> "$GITHUB_STEP_SUMMARY"
SAFE_TRIAGE_SUMMARY=$(printf '%s' "$TRIAGE_SUMMARY" | sed 's/\\/\\\\/g; s/`/\\`/g; s/\$/\\$/g')
echo "**AI Summary:** $SAFE_TRIAGE_SUMMARY" >> "$GITHUB_STEP_SUMMARY"
echo "**Confidence:** $TRIAGE_CONFIDENCE" >> "$GITHUB_STEP_SUMMARY"
else
echo "[WARN] No labels were applied" >> "$GITHUB_STEP_SUMMARY"
fi
- name: Send Teams Notification
if: success() && steps.triage.outputs.labels != ''
continue-on-error: true
env:
TEAMS_CHANNEL_WEBHOOK_URL: ${{ secrets.TEAMS_CHANNEL_WEBHOOK_URL }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_URL: ${{ github.event.issue.html_url }}
TRIAGE_LABELS: ${{ steps.triage.outputs.labels }}
TRIAGE_SUMMARY: ${{ steps.triage.outputs.summary }}
TRIAGE_CONFIDENCE: ${{ steps.triage.outputs.confidence }}
run: |
if [ -z "$TEAMS_CHANNEL_WEBHOOK_URL" ]; then
echo "Teams webhook not configured, skipping notification"
exit 0
fi
# Escape special characters for JSON
MAX_TITLE_LENGTH=120
TITLE_FOR_TEAMS="$ISSUE_TITLE"
if [ "${#ISSUE_TITLE}" -gt "$MAX_TITLE_LENGTH" ]; then
TRUNCATED_TITLE=$(printf '%s' "$ISSUE_TITLE" | cut -c1-$((MAX_TITLE_LENGTH - 1)))
TITLE_FOR_TEAMS="${TRUNCATED_TITLE}..."
fi
SAFE_TITLE=$(printf '%s' "$TITLE_FOR_TEAMS" | jq -Rs '.')
SAFE_LABELS=$(printf '%s' "${TRIAGE_LABELS:-none}" | jq -Rs '.')
SAFE_SUMMARY_TEXT=$(printf '**Summary:** %s' "$TRIAGE_SUMMARY" | jq -Rs '.')
CONFIDENCE_PCT=$(echo "$TRIAGE_CONFIDENCE" | awk '{printf "%.0f", $1 * 100}')
# Build Adaptive Card JSON
cat > /tmp/teams-card.json << CARD_EOF
{
"type": "message",
"attachments": [{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"\$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.4",
"body": [
{
"type": "TextBlock",
"text": "New Issue Triaged",
"weight": "Bolder",
"size": "Large",
"color": "Accent"
},
{
"type": "FactSet",
"facts": [
{ "title": "Issue", "value": "#$ISSUE_NUMBER" },
{ "title": "Title", "value": ${SAFE_TITLE} },
{ "title": "Labels", "value": ${SAFE_LABELS} },
{ "title": "Confidence", "value": "${CONFIDENCE_PCT}%" }
]
},
{
"type": "TextBlock",
"text": ${SAFE_SUMMARY_TEXT},
"wrap": true,
"spacing": "Medium"
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "View Issue",
"url": "$ISSUE_URL"
}
]
}
}]
}
CARD_EOF
# Send to Teams
HTTP_CODE=$(curl -s -o /tmp/teams-response.txt -w "%{http_code}" \
-X POST "$TEAMS_CHANNEL_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d @/tmp/teams-card.json)
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
echo "Teams notification sent successfully"
else
echo "Failed to send Teams notification (HTTP $HTTP_CODE)"
cat /tmp/teams-response.txt
exit 1
fi