mirror of
https://github.com/hustcer/deepseek-review.git
synced 2026-05-13 05:16:05 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88206a92f0 | ||
|
|
2ab221a624 | ||
|
|
cc5bb6bb4c |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
.env
|
||||
.env.dev
|
||||
.env.local
|
||||
prompts.yaml
|
||||
|
||||
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,6 +1,20 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [1.7.0] - 2025-02-08
|
||||
|
||||
### Features
|
||||
|
||||
- Remove the dependency on `just` for local code review (#84)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Fix possible GitHub comment posting errors
|
||||
|
||||
### Refactor
|
||||
|
||||
- Improve prompts loading helper (#82)
|
||||
|
||||
## [1.6.0] - 2025-02-07
|
||||
|
||||
### Features
|
||||
|
||||
16
README.md
16
README.md
@@ -141,14 +141,14 @@ With this setup, DeepSeek code review will not run automatically upon PR creatio
|
||||
|
||||
To perform code reviews locally(should works for `macOS`, `Ubuntu`, and `Windows`), you need to install the following tools:
|
||||
|
||||
- [`Nushell`](https://www.nushell.sh/book/installation.html) & [`Just`](https://just.systems/man/en/packages.html). It is recommended to install the latest versions.
|
||||
- Once the tools are installed, simply clone this repository to your local machine, navigate to the repository directory, and run `just code-review -h` or `just cr -h`. You should see an output similar to the following:
|
||||
- [`Nushell`](https://www.nushell.sh/book/installation.html). It is recommended to install the latest versions.
|
||||
- Once `Nushell` was installed, simply clone this repository to your local machine, navigate to the repository directory, and run `nu cr -h`. You should see an output similar to the following:
|
||||
|
||||
```console
|
||||
Use DeepSeek AI to review code changes locally or in GitHub Actions
|
||||
|
||||
Usage:
|
||||
> deepseek-review {flags} (token)
|
||||
> cr {flags} (token)
|
||||
|
||||
Flags:
|
||||
-d, --debug: Debug mode
|
||||
@@ -185,15 +185,15 @@ To perform code reviews locally, you need to modify the configuration file. A sa
|
||||
|
||||
```sh
|
||||
# Perform code review on the `git diff` changes in the local DEFAULT_LOCAL_REPO repo
|
||||
just cr
|
||||
nu cr
|
||||
# Perform code review on the `git diff f536acc` changes in the local DEFAULT_LOCAL_REPO repo
|
||||
just cr --diff-from f536acc
|
||||
nu cr --diff-from f536acc
|
||||
# Perform code review on the `git diff f536acc 0dd0eb5` changes in the local DEFAULT_LOCAL_REPO repo
|
||||
just cr --diff-from f536acc --diff-to 0dd0eb5
|
||||
nu cr --diff-from f536acc --diff-to 0dd0eb5
|
||||
# Perform code review on PR #31 in the remote DEFAULT_GITHUB_REPO repo
|
||||
just cr --pr-number 31
|
||||
nu cr --pr-number 31
|
||||
# Perform code review on PR #31 in the remote hustcer/deepseek-review repo
|
||||
just cr --pr-number 31 --repo hustcer/deepseek-review
|
||||
nu cr --pr-number 31 --repo hustcer/deepseek-review
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
@@ -138,14 +138,14 @@ DeepSeek 接口调用入参:
|
||||
|
||||
在本地进行代码审查,支持 `macOS`, `Ubuntu` & `Windows` 不过需要安装以下工具:
|
||||
|
||||
- [`Nushell`](https://www.nushell.sh/book/installation.html) & [`Just`](https://just.systems/man/en/packages.html), 建议安装最新版本
|
||||
- 接下来只需要把本仓库代码克隆到本地,然后进入仓库目录执行 `just code-review -h` 或者 `just cr -h` 即可看到类似如下输出:
|
||||
- [`Nushell`](https://www.nushell.sh/book/installation.html), 建议安装最新版本
|
||||
- 接下来只需要把本仓库代码克隆到本地,然后进入仓库目录执行 `nu cr -h` 即可看到类似如下输出:
|
||||
|
||||
```console
|
||||
Use DeepSeek AI to review code changes locally or in GitHub Actions
|
||||
|
||||
Usage:
|
||||
> deepseek-review {flags} (token)
|
||||
> cr {flags} (token)
|
||||
|
||||
Flags:
|
||||
-d, --debug: Debug mode
|
||||
@@ -181,15 +181,15 @@ Parameters:
|
||||
|
||||
```sh
|
||||
# 对本地 DEFAULT_LOCAL_REPO 仓库 `git diff` 修改内容进行代码审查
|
||||
just cr
|
||||
nu cr
|
||||
# 对本地 DEFAULT_LOCAL_REPO 仓库 `git diff f536acc` 修改内容进行代码审查
|
||||
just cr --diff-from f536acc
|
||||
nu cr --diff-from f536acc
|
||||
# 对本地 DEFAULT_LOCAL_REPO 仓库 `git diff f536acc 0dd0eb5` 修改内容进行代码审查
|
||||
just cr --diff-from f536acc --diff-to 0dd0eb5
|
||||
nu cr --diff-from f536acc --diff-to 0dd0eb5
|
||||
# 对远程 DEFAULT_GITHUB_REPO 仓库编号为 31 的 PR 进行代码审查
|
||||
just cr --pr-number 31
|
||||
nu cr --pr-number 31
|
||||
# 对远程 hustcer/deepseek-review 仓库编号为 31 的 PR 进行代码审查
|
||||
just cr --pr-number 31 --repo hustcer/deepseek-review
|
||||
nu cr --pr-number 31 --repo hustcer/deepseek-review
|
||||
```
|
||||
|
||||
## 许可
|
||||
|
||||
47
cr
Normal file
47
cr
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env nu
|
||||
# Author: hustcer
|
||||
# Created: 2025/02/08 19:02:15
|
||||
# Description: A wrapper for nu/review.nu as the main entry point of the project.
|
||||
|
||||
use nu/review.nu [deepseek-review, 'from env', ECODE]
|
||||
|
||||
# Use DeepSeek AI to review code changes locally or in GitHub Actions
|
||||
def main [
|
||||
token?: string, # Your DeepSeek API token, fallback to CHAT_TOKEN env var
|
||||
--debug(-d), # Debug mode
|
||||
--repo(-r): string, # GitHub repository 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
|
||||
--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
|
||||
--sys-prompt(-s): string # Default to $DEFAULT_OPTIONS.SYS_PROMPT,
|
||||
--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
|
||||
] {
|
||||
|
||||
if not ('.env' | path exists) {
|
||||
print $'Please refer to (ansi g)`.env.example`(ansi reset) to create a (ansi r)`.env`(ansi reset) file in the root directory of the project.'
|
||||
exit $ECODE.MISSING_DEPENDENCY
|
||||
}
|
||||
open .env | load-env
|
||||
(
|
||||
deepseek-review $token
|
||||
--repo=$repo
|
||||
--debug=$debug
|
||||
--model=$model
|
||||
--include=$include
|
||||
--exclude=$exclude
|
||||
--diff-to=$diff_to
|
||||
--base-url=$base_url
|
||||
--gh-token=$gh_token
|
||||
--diff-from=$diff_from
|
||||
--pr-number=$pr_number
|
||||
--max-length=$max_length
|
||||
--sys-prompt=$sys_prompt
|
||||
--user-prompt=$user_prompt
|
||||
)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "deepseek-review",
|
||||
"version": "1.6.0",
|
||||
"actionVer": "v1.6",
|
||||
"version": "1.7.0",
|
||||
"actionVer": "v1.7",
|
||||
"author": "hustcer",
|
||||
"license": "MIT",
|
||||
"github": "https://github.com/hustcer/deepseek-review",
|
||||
|
||||
43
nu/review.nu
43
nu/review.nu
@@ -24,7 +24,7 @@
|
||||
# - Local PR Review: just cr -r hustcer/deepseek-review -n 32
|
||||
|
||||
# Commonly used exit codes
|
||||
const ECODE = {
|
||||
export const ECODE = {
|
||||
SUCCESS: 0,
|
||||
OUTDATED: 1,
|
||||
AUTH_FAILED: 2,
|
||||
@@ -139,7 +139,7 @@ export def --env deepseek-review [
|
||||
print $'Code Review Result:'; hr-line; print $review
|
||||
} else {
|
||||
let BASE_HEADER = [Authorization $'Bearer ($env.GH_TOKEN)' Accept application/vnd.github.v3+json ...$HTTP_HEADERS]
|
||||
http post -H $BASE_HEADER $'($GITHUB_API_BASE)/repos/($repo)/issues/($pr_number)/comments' ({ body: $review } | to json)
|
||||
http post -t application/json -H $BASE_HEADER $'($GITHUB_API_BASE)/repos/($repo)/issues/($pr_number)/comments' { body: $review }
|
||||
print $'✅ Code review finished!PR (ansi g)#($pr_number)(ansi reset) review result was posted as a comment.'
|
||||
}
|
||||
print $'(char nl)Token Usage Info:'; hr-line
|
||||
@@ -151,14 +151,18 @@ export def load-prompt-from-env [
|
||||
prompt_key: string,
|
||||
] {
|
||||
let prompt = $env | get -i $prompt_key | default ''
|
||||
if $prompt =~ '.yaml' {
|
||||
let key = $prompt | split row : | last
|
||||
let path = $prompt | split row : | first
|
||||
try { open $path | get -i $key } catch {
|
||||
print $'(ansi r)Failed to load the prompt content from ($path), please check it again.(ansi reset)'
|
||||
exit $ECODE.INVALID_PARAMETER
|
||||
}
|
||||
} else { $prompt }
|
||||
if ($prompt !~ '.ya?ml') { return $prompt }
|
||||
let parts = $prompt | split row :
|
||||
if ($parts | length) != 2 {
|
||||
print $'(ansi r)Invalid prompt format: expected path:key for YAML files.(ansi reset)'
|
||||
exit $ECODE.INVALID_PARAMETER
|
||||
}
|
||||
let key = $parts | last
|
||||
let path = $parts | first
|
||||
try { open $path | get -i $key } catch {
|
||||
print $'(ansi r)Failed to load the prompt content from ($path), please check it again.(ansi reset)'
|
||||
exit $ECODE.INVALID_PARAMETER
|
||||
}
|
||||
}
|
||||
|
||||
# Get the diff content from GitHub PR or local git changes
|
||||
@@ -316,4 +320,23 @@ def generate-exclude-regex [patterns: list<string>] {
|
||||
$"/^diff --git/{p=/^diff --git a\\/($pattern)/}!p"
|
||||
}
|
||||
|
||||
# Converts a .env file into a record
|
||||
# may be used like this: open .env | load-env
|
||||
# works with quoted and unquoted .env files
|
||||
export def "from env" []: string -> record {
|
||||
lines
|
||||
| split column '#' # remove comments
|
||||
| get column1
|
||||
| parse "{key}={value}"
|
||||
| update value {
|
||||
str trim # Trim whitespace between value and inline comments
|
||||
| str trim -c '"' # unquote double-quoted values
|
||||
| str trim -c "'" # unquote single-quoted values
|
||||
| str replace -a "\\n" "\n" # replace `\n` with newline char
|
||||
| str replace -a "\\r" "\r" # replace `\r` with carriage return
|
||||
| str replace -a "\\t" "\t" # replace `\t` with tab
|
||||
}
|
||||
| transpose -r -d
|
||||
}
|
||||
|
||||
alias main = deepseek-review
|
||||
|
||||
Reference in New Issue
Block a user