Skip to content

Commit 7b47837

Browse files
fix: resolve YAML syntax error in OpenCode AI PR review workflow
Fixes the heredoc syntax issue that was causing workflow validation failures. Replaced problematic heredoc with jq-based JSON construction for proper escaping of special characters in PR diff and comments. Changes: - workflows/opencode/pr/opencode-pr.yml: Use jq to build API payload - workflows/opencode/pr/opencode-pr-nix.yml: Same fix for Nix variant - .github/workflows/opencode-pr.yml: Apply fix to installed workflow This resolves the "Invalid workflow file" error that prevented the OpenCode AI PR review from running.
1 parent ca79782 commit 7b47837

3 files changed

Lines changed: 45 additions & 90 deletions

File tree

.github/workflows/opencode-pr.yml

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,25 @@ jobs:
6767
# Read the diff file
6868
DIFF_CONTENT=$(cat "$PR_DIFF")
6969
70-
# Create the review prompt
71-
PROMPT=$(cat <<EOF
72-
You are an expert code reviewer. Review the following pull request:
73-
74-
Title: $PR_TITLE
75-
Description: $PR_DESCRIPTION
76-
77-
Previous Review Context:
78-
$PREVIOUS_COMMENTS
79-
80-
Code Changes:
81-
\`\`\`diff
82-
$DIFF_CONTENT
83-
\`\`\`
84-
85-
Provide a structured review with:
86-
1. Overall assessment (merge-ready, needs changes, etc.)
87-
2. Critical issues (if any)
88-
3. High-priority improvements
89-
4. Medium-priority suggestions
90-
5. Low-priority nitpicks
91-
6. Confidence score (0-100)
92-
93-
Format as markdown with clear headers.
94-
EOF
95-
)
70+
# Build prompt using jq
71+
jq -n \
72+
--arg title "$PR_TITLE" \
73+
--arg desc "$PR_DESCRIPTION" \
74+
--arg previous "$PREVIOUS_COMMENTS" \
75+
--arg diff "$DIFF_CONTENT" \
76+
'{
77+
model: "kimi-latest",
78+
messages: [{
79+
role: "user",
80+
content: "You are an expert code reviewer. Review the following pull request:\n\nTitle: \($title)\n\nDescription: \($desc)\n\nPrevious Review Context:\n\($previous)\n\nCode Changes:\n\`\`\`diff\n\($diff)\n\`\`\`\n\nProvide a structured review with:\n1. Overall assessment (merge-ready, needs changes, etc.)\n2. Critical issues (if any)\n3. High-priority improvements\n4. Medium-priority suggestions\n5. Low-priority nitpicks\n6. Confidence score (0-100)\n\nFormat as markdown with clear headers."
81+
}]
82+
}' > prompt.json
9683
9784
# Call OpenCode AI API
9885
curl -X POST https://api.opencode.ai/v1/chat/completions \
9986
-H "Authorization: Bearer $KIMI_API_KEY" \
10087
-H "Content-Type: application/json" \
101-
-d "{
102-
\"model\": \"kimi-latest\",
103-
\"messages\": [{\"role\": \"user\", \"content\": $(echo "$PROMPT" | jq -Rs .)}]
104-
}" > review_response.json
88+
-d @prompt.json > review_response.json
10589
10690
# Extract and post review
10791
REVIEW_TEXT=$(cat review_response.json | jq -r '.choices[0].message.content')

workflows/opencode/pr/opencode-pr-nix.yml

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,44 +73,31 @@ jobs:
7373
- name: Run OpenCode AI Review
7474
env:
7575
KIMI_API_KEY: ${{ secrets.KIMI_API_KEY }}
76+
PR_TITLE: ${{ github.event.pull_request.title }}
77+
PR_DESCRIPTION: ${{ github.event.pull_request.body }}
78+
PREVIOUS_COMMENTS: ${{ steps.previous-comments.outputs.result }}
7679
run: |
7780
nix develop --command bash -c '
7881
DIFF_CONTENT=$(cat pr_diff.txt)
79-
PREVIOUS_COMMENTS="${{ steps.previous-comments.outputs.result }}"
8082
81-
PROMPT=$(cat <<EOF
82-
You are an expert code reviewer. Review the following pull request:
83-
84-
Title: ${{ github.event.pull_request.title }}
85-
Description: ${{ github.event.pull_request.body }}
86-
87-
Previous Review Context:
88-
$PREVIOUS_COMMENTS
89-
90-
Code Changes:
91-
\`\`\`diff
92-
$DIFF_CONTENT
93-
\`\`\`
94-
95-
Provide a structured review with:
96-
1. Overall assessment (merge-ready, needs changes, etc.)
97-
2. Critical issues (if any)
98-
3. High-priority improvements
99-
4. Medium-priority suggestions
100-
5. Low-priority nitpicks
101-
6. Confidence score (0-100)
102-
103-
Format as markdown with clear headers.
104-
EOF
105-
)
83+
# Build prompt using jq
84+
jq -n \
85+
--arg title "$PR_TITLE" \
86+
--arg desc "$PR_DESCRIPTION" \
87+
--arg previous "$PREVIOUS_COMMENTS" \
88+
--arg diff "$DIFF_CONTENT" \
89+
\'{
90+
model: "kimi-latest",
91+
messages: [{
92+
role: "user",
93+
content: "You are an expert code reviewer. Review the following pull request:\n\nTitle: \($title)\n\nDescription: \($desc)\n\nPrevious Review Context:\n\($previous)\n\nCode Changes:\n\`\`\`diff\n\($diff)\n\`\`\`\n\nProvide a structured review with:\n1. Overall assessment (merge-ready, needs changes, etc.)\n2. Critical issues (if any)\n3. High-priority improvements\n4. Medium-priority suggestions\n5. Low-priority nitpicks\n6. Confidence score (0-100)\n\nFormat as markdown with clear headers."
94+
}]
95+
}\' > prompt.json
10696
10797
curl -X POST https://api.opencode.ai/v1/chat/completions \
10898
-H "Authorization: Bearer $KIMI_API_KEY" \
10999
-H "Content-Type: application/json" \
110-
-d "{
111-
\"model\": \"kimi-latest\",
112-
\"messages\": [{\"role\": \"user\", \"content\": $(echo "$PROMPT" | jq -Rs .)}]
113-
}" > review_response.json
100+
-d @prompt.json > review_response.json
114101
115102
cat review_response.json | jq -r ".choices[0].message.content" > review_output.txt
116103
'

workflows/opencode/pr/opencode-pr.yml

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,25 @@ jobs:
6767
# Read the diff file
6868
DIFF_CONTENT=$(cat "$PR_DIFF")
6969
70-
# Create the review prompt
71-
PROMPT=$(cat <<EOF
72-
You are an expert code reviewer. Review the following pull request:
73-
74-
Title: $PR_TITLE
75-
Description: $PR_DESCRIPTION
76-
77-
Previous Review Context:
78-
$PREVIOUS_COMMENTS
79-
80-
Code Changes:
81-
\`\`\`diff
82-
$DIFF_CONTENT
83-
\`\`\`
84-
85-
Provide a structured review with:
86-
1. Overall assessment (merge-ready, needs changes, etc.)
87-
2. Critical issues (if any)
88-
3. High-priority improvements
89-
4. Medium-priority suggestions
90-
5. Low-priority nitpicks
91-
6. Confidence score (0-100)
92-
93-
Format as markdown with clear headers.
94-
EOF
95-
)
70+
# Build prompt using jq
71+
jq -n \
72+
--arg title "$PR_TITLE" \
73+
--arg desc "$PR_DESCRIPTION" \
74+
--arg previous "$PREVIOUS_COMMENTS" \
75+
--arg diff "$DIFF_CONTENT" \
76+
'{
77+
model: "kimi-latest",
78+
messages: [{
79+
role: "user",
80+
content: "You are an expert code reviewer. Review the following pull request:\n\nTitle: \($title)\n\nDescription: \($desc)\n\nPrevious Review Context:\n\($previous)\n\nCode Changes:\n\`\`\`diff\n\($diff)\n\`\`\`\n\nProvide a structured review with:\n1. Overall assessment (merge-ready, needs changes, etc.)\n2. Critical issues (if any)\n3. High-priority improvements\n4. Medium-priority suggestions\n5. Low-priority nitpicks\n6. Confidence score (0-100)\n\nFormat as markdown with clear headers."
81+
}]
82+
}' > prompt.json
9683
9784
# Call OpenCode AI API
9885
curl -X POST https://api.opencode.ai/v1/chat/completions \
9986
-H "Authorization: Bearer $KIMI_API_KEY" \
10087
-H "Content-Type: application/json" \
101-
-d "{
102-
\"model\": \"kimi-latest\",
103-
\"messages\": [{\"role\": \"user\", \"content\": $(echo "$PROMPT" | jq -Rs .)}]
104-
}" > review_response.json
88+
-d @prompt.json > review_response.json
10589
10690
# Extract and post review
10791
REVIEW_TEXT=$(cat review_response.json | jq -r '.choices[0].message.content')

0 commit comments

Comments
 (0)