Skip to content

Commit 755789c

Browse files
committed
Fix Slack notifications and improve diff validation
- Fix all Slack notifications in aicode-agent.yml to use jq for proper JSON construction - Prevents shell quoting issues when task text contains quotes or special characters - Improve diff validation to better detect truncated file paths in +++ b/ lines - Fixes 'curl: URL rejected' and 'invalid_payload' errors in Slack notifications
1 parent cc4ed6c commit 755789c

2 files changed

Lines changed: 132 additions & 4 deletions

File tree

.github/agent/agent.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ function validateDiff(diff) {
198198

199199
const newPath = newPathLine.substring(6).trim();
200200

201+
// Check if the path is complete (not truncated)
202+
if (!newPath || newPath.length < 3 || newPath.includes('\n') || newPath.match(/^[a-z]$/i)) {
203+
errors.push(`Incomplete +++ b/ line detected: "${newPathLine}" - file name appears to be truncated or missing`);
204+
continue;
205+
}
206+
201207
// Check if the section has at least one hunk
202208
const hasHunk = section.includes('@@');
203209
if (!hasHunk && !section.includes('new file') && !section.includes('deleted file')) {

.github/workflows/aicode-agent.yml

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,39 @@ jobs:
7676
- name: Notify Slack on agent failure
7777
if: steps.agent.outcome != 'success'
7878
run: |
79+
# Use jq to safely construct JSON payload
80+
TASK="${{ github.event.client_payload.task || github.event.client_payload.original_task }}"
81+
REQUESTER="${{ github.event.client_payload.requester }}"
82+
RUN_ID="${{ github.run_id }}"
83+
84+
PAYLOAD=$(jq -n \
85+
--arg text "❌ AICODE Agent failed before tests" \
86+
--arg task "$TASK" \
87+
--arg requester "$REQUESTER" \
88+
--arg run_url "https://github.com/htilly/SlackONOS/actions/runs/$RUN_ID" \
89+
'{
90+
text: $text,
91+
blocks: [
92+
{
93+
type: "section",
94+
text: {
95+
type: "mrkdwn",
96+
text: ("❌ *AICODE Agent Failed*\n\n*Task:* " + $task + "\n*Requested by:* " + $requester + "\n*Stage:* Agent execution\n\nCheck the logs for detailed error information.")
97+
}
98+
},
99+
{
100+
type: "section",
101+
text: {
102+
type: "mrkdwn",
103+
text: ("<" + $run_url + "|View GitHub Actions logs>")
104+
}
105+
}
106+
]
107+
}')
108+
79109
curl -X POST "${{ secrets.SLACK_WEBHOOK_URL }}" \
80110
-H "Content-Type: application/json" \
81-
-d "{\"text\":\"❌ AICODE Agent failed before tests\",\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"❌ *AICODE Agent Failed*\\n\\n*Task:* ${{ github.event.client_payload.task || github.event.client_payload.original_task }}\\n*Requested by:* ${{ github.event.client_payload.requester }}\\n*Stage:* Agent execution\\n\\nCheck the logs for detailed error information.\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"<https://github.com/htilly/SlackONOS/actions/runs/${{ github.run_id }}|View GitHub Actions logs>\"}}]}"
111+
-d "$PAYLOAD"
82112
83113
- name: Validate diff format
84114
id: validate
@@ -170,20 +200,112 @@ jobs:
170200
if: steps.agent.outcome == 'success' && steps.tests.outcome == 'success' && steps.secrets-check.outcome == 'success'
171201
run: |
172202
CHANGED_FILES="${{ steps.changed-files.outputs.files }}"
203+
TASK="${{ github.event.client_payload.task || github.event.client_payload.original_task }}"
204+
ORIGINAL_TASK="${{ github.event.client_payload.original_task || 'N/A' }}"
205+
REQUESTER="${{ github.event.client_payload.requester }}"
206+
PR_NUMBER="${{ steps.cpr.outputs.pull-request-number }}"
207+
RUN_ID="${{ github.run_id }}"
208+
209+
PAYLOAD=$(jq -n \
210+
--arg text "✅ AICODE PR created: <https://github.com/htilly/SlackONOS/pull/$PR_NUMBER|#$PR_NUMBER>" \
211+
--arg task "$TASK" \
212+
--arg original_task "$ORIGINAL_TASK" \
213+
--arg requester "$REQUESTER" \
214+
--arg pr_number "$PR_NUMBER" \
215+
--arg changed_files "$CHANGED_FILES" \
216+
--arg run_id "$RUN_ID" \
217+
'{
218+
text: $text,
219+
blocks: [
220+
{
221+
type: "section",
222+
text: {
223+
type: "mrkdwn",
224+
text: ("✅ *AICODE Agent Success*\n\n*Task:* " + $task + "\n*Original:* " + $original_task + "\n*Requested by:* " + $requester + "\n*PR:* <https://github.com/htilly/SlackONOS/pull/" + $pr_number + "|#" + $pr_number + ">\n*Files changed:* " + $changed_files)
225+
}
226+
},
227+
{
228+
type: "section",
229+
text: {
230+
type: "mrkdwn",
231+
text: ("<https://github.com/htilly/SlackONOS/actions/runs/" + $run_id + "|View workflow run>")
232+
}
233+
}
234+
]
235+
}')
236+
173237
curl -X POST "${{ secrets.SLACK_WEBHOOK_URL }}" \
174238
-H "Content-Type: application/json" \
175-
-d "{\"text\":\"✅ AICODE PR created: <https://github.com/htilly/SlackONOS/pull/${{ steps.cpr.outputs.pull-request-number }}|#${{ steps.cpr.outputs.pull-request-number }}>\",\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"✅ *AICODE Agent Success*\\n\\n*Task:* ${{ github.event.client_payload.task || github.event.client_payload.original_task }}\\n*Original:* ${{ github.event.client_payload.original_task || 'N/A' }}\\n*Requested by:* ${{ github.event.client_payload.requester }}\\n*PR:* <https://github.com/htilly/SlackONOS/pull/${{ steps.cpr.outputs.pull-request-number }}|#${{ steps.cpr.outputs.pull-request-number }}>\\n*Files changed:* ${CHANGED_FILES}\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"<https://github.com/htilly/SlackONOS/actions/runs/${{ github.run_id }}|View workflow run>\"}}]}"
239+
-d "$PAYLOAD"
176240
177241
- name: Notify Slack on validation failure
178242
if: steps.agent.outcome == 'success' && steps.secrets-check.outcome != 'success'
179243
run: |
244+
TASK="${{ github.event.client_payload.task || github.event.client_payload.original_task }}"
245+
REQUESTER="${{ github.event.client_payload.requester }}"
246+
RUN_ID="${{ github.run_id }}"
247+
248+
PAYLOAD=$(jq -n \
249+
--arg text "🔒 AICODE failed: Security validation failed" \
250+
--arg task "$TASK" \
251+
--arg requester "$REQUESTER" \
252+
--arg run_id "$RUN_ID" \
253+
'{
254+
text: $text,
255+
blocks: [
256+
{
257+
type: "section",
258+
text: {
259+
type: "mrkdwn",
260+
text: ("🔒 *AICODE Security Validation Failed*\n\n*Task:* " + $task + "\n*Requested by:* " + $requester + "\n*Issue:* Potential secrets detected in generated code\n\nReview the changes manually before proceeding.")
261+
}
262+
},
263+
{
264+
type: "section",
265+
text: {
266+
type: "mrkdwn",
267+
text: ("<https://github.com/htilly/SlackONOS/actions/runs/" + $run_id + "|View GitHub Actions logs>")
268+
}
269+
}
270+
]
271+
}')
272+
180273
curl -X POST "${{ secrets.SLACK_WEBHOOK_URL }}" \
181274
-H "Content-Type: application/json" \
182-
-d "{\"text\":\"🔒 AICODE failed: Security validation failed\",\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"🔒 *AICODE Security Validation Failed*\\n\\n*Task:* ${{ github.event.client_payload.task || github.event.client_payload.original_task }}\\n*Requested by:* ${{ github.event.client_payload.requester }}\\n*Issue:* Potential secrets detected in generated code\\n\\nReview the changes manually before proceeding.\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"<https://github.com/htilly/SlackONOS/actions/runs/${{ github.run_id }}|View GitHub Actions logs>\"}}]}"
275+
-d "$PAYLOAD"
183276
184277
- name: Notify Slack on test failure
185278
if: steps.agent.outcome == 'success' && steps.secrets-check.outcome == 'success' && steps.tests.outcome != 'success'
186279
run: |
280+
TASK="${{ github.event.client_payload.task || github.event.client_payload.original_task }}"
281+
REQUESTER="${{ github.event.client_payload.requester }}"
282+
RUN_ID="${{ github.run_id }}"
283+
284+
PAYLOAD=$(jq -n \
285+
--arg text "❌ AICODE failed: Tests didn't pass" \
286+
--arg task "$TASK" \
287+
--arg requester "$REQUESTER" \
288+
--arg run_id "$RUN_ID" \
289+
'{
290+
text: $text,
291+
blocks: [
292+
{
293+
type: "section",
294+
text: {
295+
type: "mrkdwn",
296+
text: ("❌ *AICODE Test Failure*\n\n*Task:* " + $task + "\n*Requested by:* " + $requester + "\n*Issue:* Generated code failed tests\n\nReview the test output and adjust the changes.")
297+
}
298+
},
299+
{
300+
type: "section",
301+
text: {
302+
type: "mrkdwn",
303+
text: ("<https://github.com/htilly/SlackONOS/actions/runs/" + $run_id + "|View GitHub Actions logs>")
304+
}
305+
}
306+
]
307+
}')
308+
187309
curl -X POST "${{ secrets.SLACK_WEBHOOK_URL }}" \
188310
-H "Content-Type: application/json" \
189-
-d "{\"text\":\"❌ AICODE failed: Tests didn't pass\",\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"❌ *AICODE Test Failure*\\n\\n*Task:* ${{ github.event.client_payload.task || github.event.client_payload.original_task }}\\n*Requested by:* ${{ github.event.client_payload.requester }}\\n*Issue:* Generated code failed tests\\n\\nReview the test output and adjust the changes.\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"<https://github.com/htilly/SlackONOS/actions/runs/${{ github.run_id }}|View GitHub Actions logs>\"}}]}"
311+
-d "$PAYLOAD"

0 commit comments

Comments
 (0)