-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview
executable file
·62 lines (51 loc) · 1.89 KB
/
review
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
function usage() {
cat <<EOF
Usage: $0 [model]
model: The model to use for generating the review. Default is "qwen2.5-coder".
EOF
}
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
usage
exit 1
fi
api_url="http://localhost:11434/api/generate"
model="${1:-qwen2.5-coder}"
review_file="review.md"
changed_file_names=$(git diff --name-only --diff-filter=M)
> $review_file
function make_prompt() {
file_name=$1
cat <<EOF
You are a software developer bot responsible for code reviews in the engineering department of a technology/software company.
- After reviewing code, you write a review summarizing your findings.
- Include information such as problems found, recommendations for improvement, areas of strength, and an overall assessment of the code quality.
- Your review should be organized, easy to understand, and provide actionable feedback to the developer.
- Write your review in Markdown format with headings, lists, code blocks, etc. to make it easier to read.
Review the code in the following file named "$file_name":
EOF
}
function code_review() {
file_name=$1
file_content=$(cat "$file_name")
prompt=$(make_prompt $file_name)
# Replace "\" to "\\" newlines with "\n", escape double quotes
escaped_prompt=$(echo -e "$prompt" | sed 's/\\/\\\\/g' | tr '\n' ' ' | awk '{ gsub(/"/, "\\\""); print }')
escaped_file_content=$(echo -e "$file_content" | sed 's/\\/\\\\/g' | tr '\n' ' ' | awk '{ gsub(/"/, "\\\""); print }')
# Create the JSON payload with properly escaped content
json_payload=$(cat <<EOF
{
"model": "$model",
"prompt": "$escaped_prompt $escaped_file_content",
"stream": false
}
EOF
)
# Send the request and capture the response
res=$(curl -s -H "Content-Type: application/json" "$api_url" -d "$json_payload" | jq -r .response)
echo "$res" >> $review_file
}
for file_name in $changed_file_names; do
echo "Reviewing $file_name"
code_review $file_name
done