mirror of
https://github.com/hustcer/deepseek-review.git
synced 2026-05-13 05:16:05 +08:00
Compare commits
5 Commits
v1.17
...
feature/pr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91c90031c0 | ||
|
|
2157323736 | ||
|
|
981ef03409 | ||
|
|
9852118ba7 | ||
|
|
985f205ae5 |
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -46,7 +46,7 @@ jobs:
|
||||
- name: Checkout Nutest Repo
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: v1.0.1
|
||||
ref: v1.1.0
|
||||
path: nutest
|
||||
repository: vyadh/nutest
|
||||
sparse-checkout: nutest/
|
||||
|
||||
@@ -126,7 +126,7 @@ With this setup, DeepSeek code review will not run automatically upon PR creatio
|
||||
| max-length | Int | Optional, Maximum length(Unicode width) of the content for review, if the content length exceeds this value, the review will be skipped. Default `0` means no limit. |
|
||||
| sys-prompt | String | Optional, System prompt corresponding to `$sys_prompt` in the payload, default value see note below |
|
||||
| user-prompt | String | Optional, User prompt corresponding to `$user_prompt` in the payload, default value see note below |
|
||||
| temperature | Number | Optional, The temperature for the model to generate the response, between `0` and `2`, default value `1.0` |
|
||||
| temperature | Number | Optional, The temperature for the model to generate the response, between `0` and `2`, default value `0.3` |
|
||||
| include-patterns | String | Optional, The comma separated file patterns to include in the code review. No default |
|
||||
| exclude-patterns | String | Optional, The comma separated file patterns to exclude in the code review. Default to `pnpm-lock.yaml,package-lock.json,*.lock` |
|
||||
| github-token | String | Optional, The `GITHUB_TOKEN` secret or personal access token to authenticate. Defaults to `${{ github.token }}`. |
|
||||
@@ -179,8 +179,8 @@ Flags:
|
||||
-r, --repo <string>: GitHub repo name, e.g. hustcer/deepseek-review
|
||||
-n, --pr-number <string>: GitHub PR number
|
||||
-k, --gh-token <string>: Your GitHub token, fallback to GITHUB_TOKEN env var
|
||||
-t, --diff-to <string>: Diff to git REF
|
||||
-f, --diff-from <string>: Diff from git REF
|
||||
-f, --diff-from <string>: Git diff starting commit SHA
|
||||
-t, --diff-to <string>: Git diff ending commit SHA
|
||||
-c, --patch-cmd <string>: The `git show` or `git diff` command to get the diff content, for local CR only
|
||||
-l, --max-length <int>: Maximum length of the content for review, 0 means no limit.
|
||||
-m, --model <string>: Model name, or read from CHAT_MODEL env var, `deepseek-chat` by default
|
||||
@@ -190,7 +190,7 @@ Flags:
|
||||
-u, --user-prompt <string>: Default to $DEFAULT_OPTIONS.USER_PROMPT,
|
||||
-i, --include <string>: Comma separated file patterns to include in the code review
|
||||
-x, --exclude <string>: Comma separated file patterns to exclude in the code review
|
||||
-T, --temperature <float>: Temperature for the model, between `0` and `2`, default value `1.0`
|
||||
-T, --temperature <float>: Temperature for the model, between `0` and `2`, default value `0.3`
|
||||
-C, --config <string>: Config file path, default to `config.yml`
|
||||
-o, --output <string>: Output file path
|
||||
-h, --help: Display the help message for this command
|
||||
|
||||
@@ -124,7 +124,7 @@ jobs:
|
||||
| max-length | Int | 可选,待审查内容的最大 Unicode 长度, 默认 `0` 表示没有限制,超过非零值则跳过审查 |
|
||||
| sys-prompt | String | 可选,系统提示词对应入参中的 `$sys_prompt`, 默认值见后文注释 |
|
||||
| user-prompt | String | 可选,用户提示词对应入参中的 `$user_prompt`, 默认值见后文注释 |
|
||||
| temperature | Number | 可选,采样温度,介于 `0` 和 `2` 之间, 默认值 `1.0` |
|
||||
| temperature | Number | 可选,采样温度,介于 `0` 和 `2` 之间, 默认值 `0.3` |
|
||||
| include-patterns | String | 可选,代码审查中要包含的以逗号分隔的文件模式,无默认值 |
|
||||
| exclude-patterns | String | 可选,代码审查中要排除的以逗号分隔的文件模式,默认值为 `pnpm-lock.yaml,package-lock.json,*.lock` |
|
||||
| github-token | String | 可选,用于访问 API 进行 PR 管理的 GitHub Token,默认为 `${{ github.token }}` |
|
||||
@@ -176,8 +176,8 @@ Flags:
|
||||
-r, --repo <string>: GitHub repo name, e.g. hustcer/deepseek-review
|
||||
-n, --pr-number <string>: GitHub PR number
|
||||
-k, --gh-token <string>: Your GitHub token, fallback to GITHUB_TOKEN env var
|
||||
-t, --diff-to <string>: Diff to git REF
|
||||
-f, --diff-from <string>: Diff from git REF
|
||||
-f, --diff-from <string>: Git diff starting commit SHA
|
||||
-t, --diff-to <string>: Git diff ending commit SHA
|
||||
-c, --patch-cmd <string>: The `git show` or `git diff` command to get the diff content, for local CR only
|
||||
-l, --max-length <int>: Maximum length of the content for review, 0 means no limit.
|
||||
-m, --model <string>: Model name, or read from CHAT_MODEL env var, `deepseek-chat` by default
|
||||
@@ -187,7 +187,7 @@ Flags:
|
||||
-u, --user-prompt <string>: Default to $DEFAULT_OPTIONS.USER_PROMPT,
|
||||
-i, --include <string>: Comma separated file patterns to include in the code review
|
||||
-x, --exclude <string>: Comma separated file patterns to exclude in the code review
|
||||
-T, --temperature <float>: Temperature for the model, between `0` and `2`, default value `1.0`
|
||||
-T, --temperature <float>: Temperature for the model, between `0` and `2`, default value `0.3`
|
||||
-C, --config <string>: Config file path, default to `config.yml`
|
||||
-o, --output <string>: Output file path
|
||||
-h, --help: Display the help message for this command
|
||||
|
||||
@@ -28,7 +28,7 @@ inputs:
|
||||
description: 'The DeepSeek model to choose for code review.'
|
||||
temperature:
|
||||
required: false
|
||||
default: 1.0
|
||||
default: 0.3
|
||||
description: 'The temperature of the model.'
|
||||
base-url:
|
||||
required: false
|
||||
@@ -78,7 +78,7 @@ runs:
|
||||
let includePatterns = '${{ inputs.include-patterns }}'
|
||||
let excludePatterns = '${{ inputs.exclude-patterns }}'
|
||||
let maxLength = try { '${{ inputs.max-length }}' | into int } catch { 0 }
|
||||
let temperature = try { '${{ inputs.temperature }}' | into float } catch { 1.0 }
|
||||
let temperature = try { '${{ inputs.temperature }}' | into float } catch { 0.3 }
|
||||
(deepseek-review $token
|
||||
--model $model
|
||||
--repo $repo
|
||||
|
||||
@@ -17,8 +17,8 @@ settings:
|
||||
# If the content length exceeds the non-zero limit, the review will be skipped
|
||||
# Note that it's unicode width not LLM token length
|
||||
max-length: 0
|
||||
# The temperature of the model, The value should be between 0 and 2, with default value 1.0
|
||||
temperature: 1.0
|
||||
# The temperature of the model, The value should be between 0 and 2, with default value 0.3
|
||||
temperature: 0.3
|
||||
# The user prompt name to use for DeepSeek API select from 'prompts.user'
|
||||
user-prompt: 'default'
|
||||
# The system prompt name to use for DeepSeek API select from 'prompts.system'
|
||||
|
||||
10
cr
10
cr
@@ -14,18 +14,18 @@ def main [
|
||||
--repo(-r): string, # GitHub repo name, e.g. hustcer/deepseek-review
|
||||
--pr-number(-n): string, # GitHub PR number
|
||||
--gh-token(-k): string, # Your GitHub token, fallback to GITHUB_TOKEN env var
|
||||
--diff-to(-t): string, # Diff to git REF
|
||||
--diff-from(-f): string, # Diff from git REF
|
||||
--diff-from(-f): string, # Git diff starting commit SHA
|
||||
--diff-to(-t): string, # Git diff ending commit SHA
|
||||
--patch-cmd(-c): string, # The `git show` or `git diff` command to get the diff content, for local CR only
|
||||
--max-length(-l): int, # Maximum length of the content for review, 0 means no limit.
|
||||
--model(-m): string, # Model name, or read from CHAT_MODEL env var, `deepseek-chat` by default
|
||||
--base-url(-b): string, # DeepSeek API base URL, fallback to BASE_URL env var
|
||||
--chat-url(-U): string, # DeepSeek Model chat full API URL, e.g. http://localhost:11535/api/chat
|
||||
--sys-prompt(-s): string # Default to $DEFAULT_OPTIONS.SYS_PROMPT,
|
||||
--user-prompt(-u): string # Default to $DEFAULT_OPTIONS.USER_PROMPT,
|
||||
--sys-prompt(-s): string # Optional, System prompt message, fallback to SYSTEM_PROMPT env var
|
||||
--user-prompt(-u): string # Default to $DEFAULT_OPTIONS.USER_PROMPT
|
||||
--include(-i): string, # Comma separated file patterns to include in the code review
|
||||
--exclude(-x): string, # Comma separated file patterns to exclude in the code review
|
||||
--temperature(-T): float, # Temperature for the model, between `0` and `2`, default value `1.0`
|
||||
--temperature(-T): float, # Temperature for the model, between `0` and `2`, default value `0.3`
|
||||
--config(-C): string # Config file path, default to `config.yml`
|
||||
--output(-o): string, # Output file path
|
||||
] {
|
||||
|
||||
@@ -23,7 +23,8 @@ def file-exists [file: string] {
|
||||
# Check if the prompt keys exist in the config.yml file
|
||||
def check-prompts [options: record] {
|
||||
check-prompt $options user
|
||||
check-prompt $options system
|
||||
# System prompt is optional, so we don't exit if it's missing
|
||||
# check-prompt $options system
|
||||
}
|
||||
|
||||
# Check if the specified type of prompt key exists in the config.yml file
|
||||
|
||||
24
nu/review.nu
24
nu/review.nu
@@ -44,10 +44,9 @@ const HTTP_HEADERS = [User-Agent curl/8.9]
|
||||
|
||||
const DEFAULT_OPTIONS = {
|
||||
MODEL: 'deepseek-chat',
|
||||
TEMPERATURE: 1.0,
|
||||
TEMPERATURE: 0.3,
|
||||
BASE_URL: 'https://api.deepseek.com',
|
||||
USER_PROMPT: 'Please review the following code changes:',
|
||||
SYS_PROMPT: 'You are a professional code review assistant responsible for analyzing code changes in GitHub Pull Requests. Identify potential issues such as code style violations, logical errors, security vulnerabilities, and provide improvement suggestions. Clearly list the problems and recommendations in a concise manner.',
|
||||
USER_PROMPT: 'You are a professional code review assistant responsible for analyzing code changes. Identify potential issues such as code style violations, logical errors, security vulnerabilities, and provide improvement suggestions. Clearly list the problems and recommendations in a concise manner. Please review the following code changes:',
|
||||
}
|
||||
|
||||
# Use DeepSeek AI to review code changes locally or in GitHub Actions
|
||||
@@ -58,18 +57,18 @@ export def --env deepseek-review [
|
||||
--output(-o): string, # Output file path
|
||||
--pr-number(-n): string, # GitHub PR number
|
||||
--gh-token(-k): string, # Your GitHub token, fallback to GITHUB_TOKEN env var
|
||||
--diff-to(-t): string, # Diff to git REF
|
||||
--diff-from(-f): string, # Diff from git REF
|
||||
--diff-to(-t): string, # Git diff ending commit SHA
|
||||
--diff-from(-f): string, # Git diff starting commit SHA
|
||||
--patch-cmd(-c): string, # The `git show` or `git diff` command to get the diff content, for local CR only
|
||||
--max-length(-l): int, # Maximum length of the content for review, 0 means no limit.
|
||||
--model(-m): string, # Model name, or read from CHAT_MODEL env var, `deepseek-chat` by default
|
||||
--base-url(-b): string, # DeepSeek API base URL, fallback to BASE_URL env var
|
||||
--chat-url(-U): string, # DeepSeek Model chat full API URL, e.g. http://localhost:11535/api/chat
|
||||
--sys-prompt(-s): string # Default to $DEFAULT_OPTIONS.SYS_PROMPT,
|
||||
--user-prompt(-u): string # Default to $DEFAULT_OPTIONS.USER_PROMPT,
|
||||
--sys-prompt(-s): string # Optional, System prompt message, fallback to SYSTEM_PROMPT env var
|
||||
--user-prompt(-u): string # Default to $DEFAULT_OPTIONS.USER_PROMPT
|
||||
--include(-i): string, # Comma separated file patterns to include in the code review
|
||||
--exclude(-x): string, # Comma separated file patterns to exclude in the code review
|
||||
--temperature(-T): float, # Temperature for the model, between `0` and `2`, default value `1.0`
|
||||
--temperature(-T): float, # Temperature for the model, between `0` and `2`, default value `0.3`
|
||||
]: nothing -> nothing {
|
||||
|
||||
$env.config.table.mode = 'psql'
|
||||
@@ -126,16 +125,15 @@ export def --env deepseek-review [
|
||||
exit $ECODE.SUCCESS
|
||||
}
|
||||
print $'Review content length: (ansi g)($length)(ansi reset), current max length: (ansi g)($max_length)(ansi reset)'
|
||||
let sys_prompt = $sys_prompt | default $env.SYSTEM_PROMPT? | default $DEFAULT_OPTIONS.SYS_PROMPT
|
||||
let sys_prompt = $sys_prompt | default $env.SYSTEM_PROMPT?
|
||||
let user_prompt = $user_prompt | default $env.USER_PROMPT? | default $DEFAULT_OPTIONS.USER_PROMPT
|
||||
mut messages = if ($sys_prompt | is-empty) { [] } else { [{ role: 'system', content: $sys_prompt }] }
|
||||
$messages = $messages | append { role: 'user', content: $"($user_prompt)\n($content)" }
|
||||
let payload = {
|
||||
model: $model,
|
||||
stream: $stream,
|
||||
messages: $messages
|
||||
temperature: $temperature,
|
||||
messages: [
|
||||
{ role: 'system', content: $sys_prompt },
|
||||
{ role: 'user', content: $"($user_prompt):\n($content)" }
|
||||
]
|
||||
}
|
||||
if $debug { print $'(char nl)Code Changes:'; hr-line; print $content }
|
||||
print $'(char nl)Waiting for response from (ansi g)($url)(ansi reset) ...'
|
||||
|
||||
@@ -1,39 +1,40 @@
|
||||
|
||||
use std/assert
|
||||
use std/testing *
|
||||
|
||||
use ../nu/common.nu [
|
||||
compare-ver, 'from env', is-installed, has-ref,
|
||||
git-check, compact-record, is-repo, windows?, mac?,
|
||||
]
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'compare-ver:v1.0.0 is greater than v0.999.0' [] {
|
||||
assert equal (compare-ver 1.0.0 0.999.0) 1
|
||||
assert equal (compare-ver v1.0.0 v0.999.0) 1
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'compare-ver:v1.0.1 is equal to v1.0.1' [] {
|
||||
assert equal (compare-ver 1.0.1 1.0.1) 0
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'compare-ver:v1.0.0 is equal to v1' [] {
|
||||
assert equal (compare-ver v1.0.0 v1) 0
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'compare-ver:v1.0.1 is greater than v1' [] {
|
||||
assert equal (compare-ver v1.0.1 v1) 1
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'compare-ver:v1.0.1 is lower than v1.1.0' [] {
|
||||
assert less (compare-ver 1.0.1 v1.1) 0
|
||||
assert equal (compare-ver 1.0.1 1.1.0) (-1)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'from-env:.env load should work' [] {
|
||||
open tests/resources/.env.test | from env | load-env
|
||||
assert equal $env.CHAT_MODEL deepseek-chat
|
||||
@@ -43,35 +44,35 @@ def 'from-env:.env load should work' [] {
|
||||
assert equal $env.USER_PROMPT 'Please review the following code changes'
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'is-installed:binary install check should work' [] {
|
||||
assert equal (is-installed git) true
|
||||
assert equal (is-installed abc) false
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'has-ref:git repo should has HEAD ref' [] {
|
||||
assert equal (has-ref HEAD) true
|
||||
assert equal (has-ref 0000) false
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'is-repo:current dir is a git repo' [] {
|
||||
assert equal (is-repo) true
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'git-check:current dir is a git repo' [] {
|
||||
assert equal (git-check (pwd) --check-repo=1) true
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'compact-record:should work as expected' [] {
|
||||
assert equal ({a: null, b: '', c: 'abc' } | compact-record) { c: 'abc' }
|
||||
assert equal ({a: null, b: 0, c: 1, e: { f: 'g' } } | compact-record) { b: 0, c: 1, e: { f: 'g' } }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'OS check should work as expected' [] {
|
||||
# `$env.RUNNER_OS` Possible values are Linux, Windows, or macOS in GitHub Actions
|
||||
match $nu.os-info.name {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
|
||||
use std/assert
|
||||
use std/testing *
|
||||
use ../nu/diff.nu [get-diff]
|
||||
use ../nu/util.nu [is-safe-git, prepare-awk, generate-include-regex, generate-exclude-regex]
|
||||
|
||||
# Get the unicode width of the input string
|
||||
def get-uw [] { $in | str stats | get unicode-width }
|
||||
|
||||
#[before-all]
|
||||
@before-all
|
||||
def setup [] {
|
||||
let awk_bin = (prepare-awk)
|
||||
let patch = open -r tests/resources/diff.patch
|
||||
@@ -14,7 +15,7 @@ def setup [] {
|
||||
{ patch: $patch, awk: $awk_bin, SHA: 22e7b71 }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'is-safe-git:should work as expected' [] {
|
||||
assert equal (is-safe-git 'git diff') true
|
||||
assert equal (is-safe-git 'git show') true
|
||||
@@ -45,7 +46,7 @@ def 'is-safe-git:should work as expected' [] {
|
||||
assert equal (is-safe-git 'git show HEAD:nu/common.nu') true
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'generate-include-regex:should work as expected' [] {
|
||||
let patch = $in.patch
|
||||
let awk_bin = $in.awk
|
||||
@@ -55,7 +56,7 @@ def 'generate-include-regex:should work as expected' [] {
|
||||
assert equal ($patch | ^$awk_bin (generate-include-regex [.env*, *.md, nu/*]) | get-uw) 6871
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'generate-exclude-regex:should work as expected' [] {
|
||||
let patch = $in.patch
|
||||
let awk_bin = $in.awk
|
||||
@@ -63,7 +64,7 @@ def 'generate-exclude-regex:should work as expected' [] {
|
||||
assert equal ($patch | ^$awk_bin (generate-exclude-regex [.env*, *.md, nu/*]) | get-uw) (1350 + 99)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'both include and exclude should work as expected' [] {
|
||||
let patch = $in.patch
|
||||
let awk_bin = $in.awk
|
||||
@@ -73,7 +74,7 @@ def 'both include and exclude should work as expected' [] {
|
||||
| get-uw) 2576
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'both exclude and include should work as expected' [] {
|
||||
let patch = $in.patch
|
||||
let awk_bin = $in.awk
|
||||
@@ -83,7 +84,7 @@ def 'both exclude and include should work as expected' [] {
|
||||
| get-uw) 2576
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'get-diff:get patch from remote PR should work' [] {
|
||||
$env.GH_TOKEN = $env.GITHUB_TOKEN?
|
||||
const repo = 'hustcer/deepseek-review'
|
||||
@@ -93,7 +94,7 @@ def 'get-diff:get patch from remote PR should work' [] {
|
||||
| str join "\n" | get-uw) 7923
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'get-diff:get patch from remote PR with include should work' [] {
|
||||
$env.GH_TOKEN = $env.GITHUB_TOKEN?
|
||||
const repo = 'hustcer/deepseek-review'
|
||||
@@ -102,7 +103,7 @@ def 'get-diff:get patch from remote PR with include should work' [] {
|
||||
assert equal ($patch | get-uw) 2576
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'get-diff:get patch from remote PR with exclude should work' [] {
|
||||
$env.GH_TOKEN = $env.GITHUB_TOKEN?
|
||||
const repo = 'hustcer/deepseek-review'
|
||||
@@ -111,7 +112,7 @@ def 'get-diff:get patch from remote PR with exclude should work' [] {
|
||||
assert equal ($patch | get-uw) 555
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def 'get-diff:get patch from remote PR with exclude & include should work' [] {
|
||||
$env.GH_TOKEN = $env.GITHUB_TOKEN?
|
||||
const repo = 'hustcer/deepseek-review'
|
||||
|
||||
Reference in New Issue
Block a user