Skip to content

Commit 9a874bc

Browse files
Copilotsapphi-red
andauthored
ci: fix template check and clarity label applier action output parsing (#21658)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
1 parent cf30751 commit 9a874bc

File tree

2 files changed

+72
-13
lines changed

2 files changed

+72
-13
lines changed

.github/workflows/clarity-label.yml

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,21 @@ jobs:
8484
const output = process.env.AGENT_OUTPUT;
8585
let result;
8686
try {
87-
result = JSON.parse(output);
87+
// The agent outputs streaming JSON format with multiple lines
88+
// We need to extract the last line with type:"agent" and parse its text field
89+
const lines = output.trim().split('\n');
90+
let agentResponse = null;
91+
for (const line of lines) {
92+
const parsed = JSON.parse(line);
93+
if (parsed.type === 'agent') {
94+
agentResponse = parsed.text;
95+
}
96+
}
97+
if (!agentResponse) {
98+
core.setFailed('No agent response found in output');
99+
return;
100+
}
101+
result = JSON.parse(agentResponse);
88102
} catch (e) {
89103
core.setFailed(`Failed to parse agent output: ${e.message}`);
90104
return;
@@ -134,11 +148,33 @@ jobs:
134148
135149
- name: Write result to summary
136150
if: steps.agent.outputs.agent_output
151+
uses: actions/github-script@v7
137152
env:
138153
AGENT_OUTPUT: ${{ steps.agent.outputs.agent_output }}
139-
run: |
140-
echo "## Clarity Label" >> $GITHUB_STEP_SUMMARY
141-
echo "" >> $GITHUB_STEP_SUMMARY
142-
echo '```json' >> $GITHUB_STEP_SUMMARY
143-
echo "$AGENT_OUTPUT" >> $GITHUB_STEP_SUMMARY
144-
echo '```' >> $GITHUB_STEP_SUMMARY
154+
with:
155+
script: |
156+
const output = process.env.AGENT_OUTPUT;
157+
158+
try {
159+
// The agent outputs streaming JSON format with multiple lines
160+
// We need to extract the last line with type:"agent" and parse its text field
161+
const lines = output.trim().split('\n');
162+
let agentText = null;
163+
for (const line of lines) {
164+
try {
165+
const parsed = JSON.parse(line);
166+
if (parsed.type === 'agent' && parsed.text) {
167+
agentText = parsed.text;
168+
}
169+
} catch (e) {}
170+
}
171+
172+
if (agentText) {
173+
await core.summary
174+
.addHeading('Clarity Label')
175+
.addCodeBlock(agentText, 'json')
176+
.write();
177+
}
178+
} catch (e) {
179+
core.setFailed(`Failed to write summary: ${e.message}`);
180+
}

.github/workflows/issue-template-check.yml

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,35 @@ jobs:
9696

9797
- name: Write result to summary
9898
if: steps.detect.outputs.skip == 'false' && steps.agent.outputs.agent_output
99+
uses: actions/github-script@v7
99100
env:
100101
TEMPLATE_TYPE: ${{ steps.detect.outputs.template_type }}
101102
AGENT_OUTPUT: ${{ steps.agent.outputs.agent_output }}
102-
run: |
103-
echo "## Issue Template Check ($TEMPLATE_TYPE)" >> $GITHUB_STEP_SUMMARY
104-
echo "" >> $GITHUB_STEP_SUMMARY
105-
echo '```json' >> $GITHUB_STEP_SUMMARY
106-
echo "$AGENT_OUTPUT" >> $GITHUB_STEP_SUMMARY
107-
echo '```' >> $GITHUB_STEP_SUMMARY
103+
with:
104+
script: |
105+
const output = process.env.AGENT_OUTPUT;
106+
const templateType = process.env.TEMPLATE_TYPE;
107+
108+
try {
109+
// The agent outputs streaming JSON format with multiple lines
110+
// We need to extract the last line with type:"agent" and parse its text field
111+
const lines = output.trim().split('\n');
112+
let agentText = null;
113+
for (const line of lines) {
114+
try {
115+
const parsed = JSON.parse(line);
116+
if (parsed.type === 'agent' && parsed.text) {
117+
agentText = parsed.text;
118+
}
119+
} catch (e) {}
120+
}
121+
122+
if (agentText) {
123+
await core.summary
124+
.addHeading(`Issue Template Check (${templateType})`)
125+
.addCodeBlock(agentText, 'json')
126+
.write();
127+
}
128+
} catch (e) {
129+
core.setFailed(`Failed to write summary: ${e.message}`);
130+
}

0 commit comments

Comments
 (0)