Skip to content

Commit 078847c

Browse files
committed
Add correction collection workflow with auto-CCA assignment
1 parent e8baba3 commit 078847c

1 file changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Collect triage agent corrections
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
concurrency:
8+
group: collect-corrections
9+
cancel-in-progress: false
10+
11+
permissions:
12+
issues: write
13+
14+
jobs:
15+
collect:
16+
runs-on: ubuntu-latest
17+
if: >-
18+
contains(github.event.comment.body, '<!-- triage-agent:') &&
19+
(
20+
github.event.comment.author_association == 'MEMBER' ||
21+
github.event.comment.author_association == 'COLLABORATOR' ||
22+
github.event.comment.author_association == 'OWNER'
23+
)
24+
steps:
25+
- name: Add correction label to the issue
26+
env:
27+
GH_TOKEN: ${{ github.token }}
28+
ISSUE_NUMBER: ${{ github.event.issue.number }}
29+
REPO: ${{ github.repository }}
30+
run: gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --add-label "triage-agent-correction"
31+
32+
- name: Find or create tracking issue
33+
id: tracking
34+
env:
35+
GH_TOKEN: ${{ github.token }}
36+
REPO: ${{ github.repository }}
37+
run: |
38+
# Search for an open tracking issue without copilot assigned
39+
TRACKING_ISSUE=$(gh issue list \
40+
--repo "$REPO" \
41+
--label "triage-agent-tracking" \
42+
--state open \
43+
--json number,assignees \
44+
--jq '[.[] | select(.assignees | map(.login) | index("copilot") == null)] | sort_by(.number) | last | .number // empty')
45+
46+
if [ -z "$TRACKING_ISSUE" ]; then
47+
echo "No available tracking issue found, creating one..."
48+
BODY=$(cat <<'EOF'
49+
# Triage Agent Corrections
50+
51+
This issue tracks corrections to the triage agent system. When assigned to
52+
Copilot, analyze the corrections and generate an improvement PR.
53+
54+
## Instructions for Copilot
55+
56+
When assigned:
57+
1. Read each linked correction comment and the original issue for full context
58+
2. Identify patterns (e.g., the classifier frequently confuses X with Y)
59+
3. Determine which workflow file(s) need improvement
60+
4. Use the `agentic-workflows` agent in this repo for guidance on workflow syntax and conventions
61+
5. Open a PR with targeted changes to the relevant `.md` workflow files in `.github/workflows/`
62+
6. Reference this issue in the PR description using `Closes #<this issue number>`
63+
7. Include a summary of which corrections motivated each change
64+
65+
## Corrections
66+
67+
| # | Issue | Correction | Date |
68+
|---|-------|------------|------|
69+
EOF
70+
)
71+
TRACKING_ISSUE=$(gh issue create \
72+
--repo "$REPO" \
73+
--title "Triage Agent Corrections" \
74+
--label "triage-agent-tracking" \
75+
--body "$BODY" \
76+
--json number --jq '.number')
77+
echo "Created tracking issue #$TRACKING_ISSUE"
78+
fi
79+
80+
echo "tracking_issue=$TRACKING_ISSUE" >> "$GITHUB_OUTPUT"
81+
82+
- name: Append correction to tracking issue
83+
env:
84+
GH_TOKEN: ${{ github.token }}
85+
REPO: ${{ github.repository }}
86+
TRACKING_ISSUE: ${{ steps.tracking.outputs.tracking_issue }}
87+
ISSUE_NUMBER: ${{ github.event.issue.number }}
88+
ISSUE_TITLE: ${{ github.event.issue.title }}
89+
COMMENT_URL: ${{ github.event.comment.html_url }}
90+
COMMENT_BODY: ${{ github.event.comment.body }}
91+
run: |
92+
# Extract the triage-agent correction text from the HTML comment
93+
CORRECTION_TEXT=$(echo "$COMMENT_BODY" | grep -oP '<!-- triage-agent:\s*\K.*?(?=\s*-->)' || echo "(see comment)")
94+
95+
# Sanitize inputs for markdown table (escape pipes, strip newlines)
96+
SAFE_TITLE=$(echo "$ISSUE_TITLE" | tr -d '\n\r' | sed 's/|/\\|/g')
97+
SAFE_CORRECTION=$(echo "$CORRECTION_TEXT" | tr -d '\n\r' | sed 's/|/\\|/g')
98+
99+
# Get the current tracking issue body
100+
CURRENT_BODY=$(gh issue view "$TRACKING_ISSUE" --repo "$REPO" --json body --jq '.body')
101+
102+
# Count existing corrections to determine the next number
103+
NEXT_NUM=$(( $(echo "$CURRENT_BODY" | grep -c '^| [0-9]') + 1 ))
104+
105+
# Get today's date
106+
TODAY=$(date -u +%Y-%m-%d)
107+
108+
# Append new row to the table
109+
NEW_ROW="| ${NEXT_NUM} | [#${ISSUE_NUMBER}](https://github.com/${REPO}/issues/${ISSUE_NUMBER}) — ${SAFE_TITLE} | [comment](${COMMENT_URL}) — ${SAFE_CORRECTION} | ${TODAY} |"
110+
UPDATED_BODY="${CURRENT_BODY}
111+
${NEW_ROW}"
112+
113+
gh issue edit "$TRACKING_ISSUE" --repo "$REPO" --body "$UPDATED_BODY"
114+
echo "Appended correction #$NEXT_NUM to tracking issue #$TRACKING_ISSUE"
115+
116+
- name: Auto-assign CCA if threshold reached
117+
env:
118+
GH_TOKEN: ${{ github.token }}
119+
REPO: ${{ github.repository }}
120+
TRACKING_ISSUE: ${{ steps.tracking.outputs.tracking_issue }}
121+
THRESHOLD: "10"
122+
run: |
123+
# Count corrections in the tracking issue
124+
BODY=$(gh issue view "$TRACKING_ISSUE" --repo "$REPO" --json body --jq '.body')
125+
COUNT=$(echo "$BODY" | grep -c '^| [0-9]' || true)
126+
127+
# Check if CCA is already assigned
128+
COPILOT_ASSIGNED=$(gh issue view "$TRACKING_ISSUE" --repo "$REPO" --json assignees --jq '[.assignees[].login] | index("copilot") != null')
129+
130+
if [ "$COUNT" -ge "$THRESHOLD" ] && [ "$COPILOT_ASSIGNED" != "true" ]; then
131+
echo "Threshold reached ($COUNT >= $THRESHOLD). Assigning CCA..."
132+
gh issue edit "$TRACKING_ISSUE" --repo "$REPO" --add-assignee copilot
133+
else
134+
echo "Threshold not reached ($COUNT/$THRESHOLD) or CCA already assigned. Skipping."
135+
fi

0 commit comments

Comments
 (0)