Skip to content

Commit d819d2f

Browse files
authored
fix: remove extra spaces before EOF in heredoc delimiters (#8103)
* fix: remove extra spaces before EOF in heredoc delimiters * fix: scripts
1 parent e78cca5 commit d819d2f

File tree

4 files changed

+177
-104
lines changed

4 files changed

+177
-104
lines changed

.github/workflows/continue-general-review.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Continue General Review
22

33
on:
4+
push:
5+
branches:
6+
- nate/fix-wf
47
pull_request:
58
types: [opened, ready_for_review]
69
issue_comment:

actions/general-review/action.yml

Lines changed: 12 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -170,62 +170,11 @@ runs:
170170
PR_NUMBER="${{ github.event.issue.number }}"
171171
fi
172172
173-
# Get PR diff
174-
gh pr diff $PR_NUMBER > pr_diff.txt
175-
176-
# Get PR details
177-
PR_TITLE=$(gh pr view $PR_NUMBER --json title -q .title)
178-
PR_AUTHOR=$(gh pr view $PR_NUMBER --json author -q .author.login)
179-
PR_BODY=$(gh pr view $PR_NUMBER --json body -q .body)
180-
FILES_CHANGED=$(gh pr view $PR_NUMBER --json files -q '.files | length')
181-
182-
# Create review prompt
183-
cat > review_prompt.txt << EOF
184-
You are reviewing a pull request. Please provide helpful, context-aware feedback.
185-
186-
CONTEXT:
187-
- Repository: ${{ github.repository }}
188-
- PR #$PR_NUMBER: $PR_TITLE
189-
- Files Changed: $FILES_CHANGED
190-
- Author: $PR_AUTHOR
191-
192-
REVIEW APPROACH:
193-
1. First, understand what this PR is trying to accomplish
194-
2. Check if similar patterns exist elsewhere in the codebase
195-
3. Focus on actual issues that affect functionality
196-
4. Be constructive and suggest solutions when possible
197-
198-
FOCUS ON:
199-
- Bugs that will cause failures or incorrect behavior
200-
- Security vulnerabilities (exposed secrets, injection risks)
201-
- Breaking changes that affect other parts of the system
202-
- Performance issues with real impact (memory leaks, O(n²) algorithms)
203-
- Missing tests for new features or bug fixes
204-
- Missing documentation for APIs or complex logic
205-
206-
SKIP COMMENTING ON:
207-
- Style and formatting (handled by linters)
208-
- Alternative approaches unless current is broken
209-
- Minor naming unless genuinely confusing
210-
- Trivial documentation for self-explanatory code
211-
212-
Be specific with line numbers and explain why something is an issue.
213-
214-
PR Description: ${PR_BODY:-No description provided}
215-
216-
Code Changes:
217-
EOF
218-
219-
# Add the diff
220-
cat pr_diff.txt >> review_prompt.txt
221-
222-
cat >> review_prompt.txt << 'EOF'
223-
224-
Your Review:
225-
Please provide constructive feedback on the code changes.
226-
Focus on issues that matter for functionality, security, and maintainability.
227-
If the code looks good overall, acknowledge that while noting any minor suggestions.
228-
EOF
173+
# Gather PR context and build prompt without heredocs
174+
gh pr diff "$PR_NUMBER" > pr_diff.txt
175+
gh pr view "$PR_NUMBER" --json title,author,body,files > pr_data.json
176+
node actions/general-review/scripts/buildPrompt.js "$PR_NUMBER"
177+
rm -f pr_data.json
229178
230179
- name: Run Continue CLI Review
231180
if: env.SHOULD_RUN == 'true'
@@ -247,15 +196,7 @@ runs:
247196
if [ -z "$CONTINUE_API_KEY" ]; then
248197
echo "Warning: CONTINUE_API_KEY environment variable is not set"
249198
# Create fallback review and continue
250-
cat > code_review.md << 'EOF'
251-
## Code Review Summary
252-
253-
⚠️ AI review skipped: CONTINUE_API_KEY not configured.
254-
255-
### Configuration Required
256-
- Please set the CONTINUE_API_KEY secret in repository settings
257-
- Verify that the organization and config path are valid
258-
EOF
199+
node actions/general-review/scripts/writeMarkdown.js code_review.md missing_api_key
259200
echo "SKIP_CLI=true" >> $GITHUB_ENV
260201
else
261202
echo "SKIP_CLI=false" >> $GITHUB_ENV
@@ -277,15 +218,7 @@ runs:
277218
echo "Testing Continue CLI..."
278219
if ! which cn > /dev/null 2>&1; then
279220
echo "Warning: Continue CLI not found or not working"
280-
cat > code_review.md << 'EOF'
281-
## Code Review Summary
282-
283-
⚠️ AI review skipped: Continue CLI installation failed.
284-
285-
### Troubleshooting
286-
- Check that npm installation succeeded
287-
- Verify @continuedev/cli package is available
288-
EOF
221+
node actions/general-review/scripts/writeMarkdown.js code_review.md cli_install_failed
289222
echo "SKIP_CLI=true" >> $GITHUB_ENV
290223
else
291224
echo "Continue CLI found at: $(which cn)"
@@ -321,11 +254,7 @@ runs:
321254
# Check if output is empty
322255
if [ ! -s code_review.md ]; then
323256
echo "Warning: Continue CLI returned empty output"
324-
cat > code_review.md << 'EOF'
325-
## Code Review Summary
326-
327-
⚠️ Continue CLI returned an empty response. Please check the configuration.
328-
EOF
257+
node actions/general-review/scripts/writeMarkdown.js code_review.md empty_output
329258
fi
330259
else
331260
echo "Error: Continue CLI command failed with exit code $?"
@@ -334,34 +263,13 @@ runs:
334263
335264
# Check for specific error patterns
336265
if grep -q "not found\|ENOENT" cli_error.log 2>/dev/null; then
337-
cat > code_review.md << 'EOF'
338-
## Code Review Summary
339-
340-
⚠️ Continue CLI is not properly installed. Please ensure @continuedev/cli is installed globally.
341-
EOF
266+
node actions/general-review/scripts/writeMarkdown.js code_review.md cli_not_found
342267
elif grep -q "config\|assistant" cli_error.log 2>/dev/null; then
343-
cat > code_review.md << 'EOF'
344-
## Code Review Summary
345-
346-
⚠️ Continue configuration error. Please verify that the assistant exists in Continue Hub.
347-
EOF
268+
node actions/general-review/scripts/writeMarkdown.js code_review.md config_error
348269
elif grep -q "api\|auth" cli_error.log 2>/dev/null; then
349-
cat > code_review.md << 'EOF'
350-
## Code Review Summary
351-
352-
⚠️ Continue API authentication failed. Please check your CONTINUE_API_KEY.
353-
EOF
270+
node actions/general-review/scripts/writeMarkdown.js code_review.md auth_error
354271
else
355-
cat > code_review.md << 'EOF'
356-
## Code Review Summary
357-
358-
⚠️ AI review failed. Please check the Continue API key and configuration.
359-
360-
### Troubleshooting
361-
- Verify the CONTINUE_API_KEY secret is set correctly
362-
- Check that the organization and config path are valid
363-
- Ensure the Continue service is accessible
364-
EOF
272+
node actions/general-review/scripts/writeMarkdown.js code_review.md generic_failure
365273
fi
366274
fi
367275
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
function main() {
5+
const prNumber = process.argv[2];
6+
if (!prNumber) {
7+
console.error(
8+
"buildPrompt.js requires the PR number as the first argument",
9+
);
10+
process.exit(1);
11+
}
12+
13+
const prDataPath = path.resolve(process.cwd(), "pr_data.json");
14+
const prDiffPath = path.resolve(process.cwd(), "pr_diff.txt");
15+
const outputPath = path.resolve(process.cwd(), "review_prompt.txt");
16+
17+
if (!fs.existsSync(prDataPath)) {
18+
console.error(`Missing PR metadata file: ${prDataPath}`);
19+
process.exit(1);
20+
}
21+
22+
if (!fs.existsSync(prDiffPath)) {
23+
console.error(`Missing PR diff file: ${prDiffPath}`);
24+
process.exit(1);
25+
}
26+
27+
const repo = process.env.GITHUB_REPOSITORY || "unknown-repo";
28+
let prData;
29+
30+
try {
31+
prData = JSON.parse(fs.readFileSync(prDataPath, "utf8"));
32+
} catch (error) {
33+
console.error("Failed to parse PR metadata JSON:", error);
34+
process.exit(1);
35+
}
36+
37+
const filesChanged = Array.isArray(prData.files) ? prData.files.length : 0;
38+
const authorLogin = prData.author?.login || "unknown-author";
39+
const title = prData.title || "Untitled";
40+
const prBody =
41+
prData.body && prData.body.trim()
42+
? prData.body.trim()
43+
: "No description provided";
44+
const diff = fs.readFileSync(prDiffPath, "utf8");
45+
46+
const promptSections = [
47+
"You are reviewing a pull request. Please provide helpful, context-aware feedback.",
48+
"",
49+
"CONTEXT:",
50+
`- Repository: ${repo}`,
51+
`- PR #${prNumber}: ${title}`,
52+
`- Files Changed: ${filesChanged}`,
53+
`- Author: ${authorLogin}`,
54+
"",
55+
"REVIEW APPROACH:",
56+
"1. First, understand what this PR is trying to accomplish",
57+
"2. Check if similar patterns exist elsewhere in the codebase",
58+
"3. Focus on actual issues that affect functionality",
59+
"4. Be constructive and suggest solutions when possible",
60+
"",
61+
"FOCUS ON:",
62+
"- Bugs that will cause failures or incorrect behavior",
63+
"- Security vulnerabilities (exposed secrets, injection risks)",
64+
"- Breaking changes that affect other parts of the system",
65+
"- Performance issues with real impact (memory leaks, O(n²) algorithms)",
66+
"- Missing tests for new features or bug fixes",
67+
"- Missing documentation for APIs or complex logic",
68+
"",
69+
"SKIP COMMENTING ON:",
70+
"- Style and formatting (handled by linters)",
71+
"- Alternative approaches unless current is broken",
72+
"- Minor naming unless genuinely confusing",
73+
"- Trivial documentation for self-explanatory code",
74+
"",
75+
"Be specific with line numbers and explain why something is an issue.",
76+
"",
77+
`PR Description: ${prBody}`,
78+
"",
79+
"Code Changes:",
80+
diff.trimEnd(),
81+
"",
82+
"Your Review:",
83+
"Please provide constructive feedback on the code changes.",
84+
"Focus on issues that matter for functionality, security, and maintainability.",
85+
"If the code looks good overall, acknowledge that while noting any minor suggestions.",
86+
];
87+
88+
const prompt = `${promptSections.join("\n")}\n`;
89+
90+
fs.writeFileSync(outputPath, prompt, "utf8");
91+
console.log(`Wrote review prompt to ${outputPath}`);
92+
}
93+
94+
main();
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
const messages = {
5+
missing_api_key: `## Code Review Summary
6+
7+
⚠️ AI review skipped: CONTINUE_API_KEY not configured.
8+
9+
### Configuration Required
10+
- Please set the CONTINUE_API_KEY secret in repository settings
11+
- Verify that the organization and config path are valid
12+
`,
13+
cli_install_failed: `## Code Review Summary
14+
15+
⚠️ AI review skipped: Continue CLI installation failed.
16+
17+
### Troubleshooting
18+
- Check that npm installation succeeded
19+
- Verify @continuedev/cli package is available
20+
`,
21+
empty_output: `## Code Review Summary
22+
23+
⚠️ Continue CLI returned an empty response. Please check the configuration.
24+
`,
25+
cli_not_found: `## Code Review Summary
26+
27+
⚠️ Continue CLI is not properly installed. Please ensure @continuedev/cli is installed globally.
28+
`,
29+
config_error: `## Code Review Summary
30+
31+
⚠️ Continue configuration error. Please verify that the assistant exists in Continue Hub.
32+
`,
33+
auth_error: `## Code Review Summary
34+
35+
⚠️ Continue API authentication failed. Please check your CONTINUE_API_KEY.
36+
`,
37+
generic_failure: `## Code Review Summary
38+
39+
⚠️ AI review failed. Please check the Continue API key and configuration.
40+
41+
### Troubleshooting
42+
- Verify the CONTINUE_API_KEY secret is set correctly
43+
- Check that the organization and config path are valid
44+
- Ensure the Continue service is accessible
45+
`,
46+
};
47+
48+
function main() {
49+
const [outputPath, messageKey] = process.argv.slice(2);
50+
51+
if (!outputPath || !messageKey) {
52+
console.error("Usage: node writeMarkdown.js <outputPath> <messageKey>");
53+
process.exit(1);
54+
}
55+
56+
const message = messages[messageKey];
57+
58+
if (!message) {
59+
console.error(`Unknown message key: ${messageKey}`);
60+
process.exit(1);
61+
}
62+
63+
const absolutePath = path.resolve(process.cwd(), outputPath);
64+
fs.writeFileSync(absolutePath, message, "utf8");
65+
console.log(`Wrote ${messageKey} message to ${absolutePath}`);
66+
}
67+
68+
main();

0 commit comments

Comments
 (0)