mirror of
https://github.com/hustcer/deepseek-review.git
synced 2026-05-13 05:16:05 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00000001ec | ||
|
|
025694ce43 | ||
|
|
f847c1a154 | ||
|
|
7b21216ef9 | ||
|
|
c984584c3a | ||
|
|
e9361125bc | ||
|
|
000000086e | ||
|
|
5225cc66ea | ||
|
|
e94ff03208 | ||
|
|
a7fd374fc1 | ||
|
|
a7699eee9c |
@@ -2,11 +2,13 @@
|
||||
# Usage: Copy this file to .env and replace the values with your own
|
||||
# WARNING: Do not commit the actual .env file to version control as it may contain sensitive information.
|
||||
|
||||
# DEEPSEEK_TOKEN: Obtain this token from your Deepseek account settings
|
||||
DEEPSEEK_TOKEN='Your Deepseek API token'
|
||||
# CHAT_TOKEN: Obtain this token from your Deepseek account settings
|
||||
CHAT_TOKEN='Your Deepseek API token'
|
||||
# GITHUB_TOKEN: Your GitHub API token to query GitHub PR changes
|
||||
# Generate this token from your GitHub account with the necessary permissions
|
||||
GITHUB_TOKEN='Your GitHub API token'
|
||||
# MAX_LENGTH: The maximum length of the content for review, 0 means no limit.
|
||||
MAX_LENGTH='0'
|
||||
# Default GitHub repository name to fetch PR changes
|
||||
DEFAULT_GITHUB_REPO='hustcer/deepseek-review'
|
||||
# Default local repository absolute path to query commit changes
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
name: Code Review
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened, synchronize, reopened]
|
||||
types:
|
||||
- opened # Triggers when a PR is opened
|
||||
- reopened # Triggers when a PR is reopened
|
||||
- synchronize # Triggers when a commit is pushed to the PR
|
||||
|
||||
# fix: GraphQL: Resource not accessible by integration (addComment) error
|
||||
permissions:
|
||||
@@ -20,4 +23,5 @@ jobs:
|
||||
- name: Deepseek Code Review
|
||||
uses: hustcer/deepseek-review@develop
|
||||
with:
|
||||
deepseek-token: ${{ secrets.DEEPSEEK_TOKEN }}
|
||||
max-length: 10000
|
||||
chat-token: ${{ secrets.CHAT_TOKEN }}
|
||||
30
CHANGELOG.md
30
CHANGELOG.md
@@ -1,6 +1,36 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [1.3.0] - 2025-01-31
|
||||
|
||||
### Documentation
|
||||
|
||||
- Update CLI help output (#53)
|
||||
- Polish documents (#57)
|
||||
|
||||
### Features
|
||||
|
||||
- Add `github-token` input (#55)
|
||||
- Add `skip cr` or `skip review` to PR title or body to disable code review in GitHub Actions (#56)
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Increase `max-length` in review workflow (#54)
|
||||
|
||||
## [1.2.0] - 2025-01-31
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
- Change `DEEPSEEK_TOKEN` to `CHAT_TOKEN` (#50)
|
||||
|
||||
### Features
|
||||
|
||||
- Add `max-length` input (#52)
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Update action name, description and icon (#49)
|
||||
|
||||
## [1.1.0] - 2025-01-30
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
27
README.md
27
README.md
@@ -9,20 +9,26 @@
|
||||
- Analyze Commit Changes with Deepseek for Any Local Repository with CLI
|
||||
- Fully Customizable: Choose Models, Base URLs, and Prompts
|
||||
- Supports Self-Hosted Deepseek Models for Enhanced Flexibility
|
||||
- Add `skip cr` or `skip review` to PR title or body to disable code review in GitHub Actions
|
||||
- Cross-platform Support: Compatible with GitHub Runners across `macOS`, `Ubuntu`, and `Windows`.
|
||||
|
||||
## Planned Features
|
||||
|
||||
- [ ] **Skip Code Review via Commit Message**: Add `skip cr` or `skip review` to a commit message to disable code review for the associated PR.
|
||||
- [ ] **Trigger Code Review on Mention**: Automatically initiate code review when the `github-actions` bot is mentioned in a PR comment.
|
||||
- [ ] **Exclude Specific File Changes**: Ignore changes to specified files, such as `Cargo.lock`, `pnpm-lock.yaml`, and others.
|
||||
|
||||
## Code Review with GitHub Action
|
||||
|
||||
Add a GitHub workflow with the following contents:
|
||||
|
||||
```yaml
|
||||
name: Code Review
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened]
|
||||
types:
|
||||
- opened # Triggers when a PR is opened
|
||||
- reopened # Triggers when a PR is reopened
|
||||
- synchronize # Triggers when a commit is pushed to the PR
|
||||
|
||||
# fix: GraphQL: Resource not accessible by integration (addComment) error
|
||||
permissions:
|
||||
@@ -36,18 +42,22 @@ jobs:
|
||||
- name: Deepseek Code Review
|
||||
uses: hustcer/deepseek-review@v1
|
||||
with:
|
||||
deepseek-token: ${{ secrets.DEEPSEEK_TOKEN }}
|
||||
chat-token: ${{ secrets.CHAT_TOKEN }}
|
||||
```
|
||||
|
||||
When a PR is created, Deepseek code review will be automatically triggered, and the review results will be posted as comments on the corresponding PR. For example: [Example](https://github.com/hustcer/deepseek-review/pull/30) & [Run Log](https://github.com/hustcer/deepseek-review/actions/runs/13043609677/job/36390331791#step:2:53).
|
||||
|
||||
## Input Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| -------------- | ------ | ----------------------------------------------------------------------- |
|
||||
| deepseek-token | String | Required, Deepseek API Token |
|
||||
| chat-token | String | Required, Deepseek API Token |
|
||||
| model | String | Optional, the model used for code review, defaults to `deepseek-chat` |
|
||||
| base-url | String | Optional, Deepseek API Base URL, defaults to `https://api.deepseek.com` |
|
||||
| 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 |
|
||||
| github-token | String | Optional, The `GITHUB_TOKEN` secret or personal access token to authenticate. Defaults to `github.token`. |
|
||||
|
||||
**Deepseek API Call Payload**:
|
||||
|
||||
@@ -73,14 +83,14 @@ jobs:
|
||||
|
||||
### Required Tools
|
||||
|
||||
To perform code reviews locally, you need to install the following tools:
|
||||
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.
|
||||
- If you need to review GitHub PRs locally, you also need to install [`gh`](https://cli.github.com/).
|
||||
- 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:
|
||||
|
||||
```console
|
||||
Use Deepseek AI to review code changes
|
||||
Use Deepseek AI to review code changes locally or in GitHub Actions
|
||||
|
||||
Usage:
|
||||
> deepseek-review {flags} (token)
|
||||
@@ -89,9 +99,10 @@ Flags:
|
||||
-d, --debug: Debug mode
|
||||
-r, --repo <string>: GitHub repository name, e.g. hustcer/deepseek-review
|
||||
-n, --pr-number <string>: GitHub PR number
|
||||
--gh-token <string>: Your GitHub token, GITHUB_TOKEN by default
|
||||
--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
|
||||
-l, --max-length <int>: Maximum length of the content for review, 0 means no limit.
|
||||
-m, --model <string>: Model name, deepseek-chat by default (default: 'deepseek-chat')
|
||||
--base-url <string> (default: 'https://api.deepseek.com')
|
||||
-s, --sys-prompt <string> (default: '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.')
|
||||
@@ -99,7 +110,7 @@ Flags:
|
||||
-h, --help: Display the help message for this command
|
||||
|
||||
Parameters:
|
||||
token <string>: Your Deepseek API token, fallback to DEEPSEEK_TOKEN (optional)
|
||||
token <string>: Your Deepseek API token, fallback to CHAT_TOKEN env var (optional)
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -7,20 +7,26 @@
|
||||
- 通过本地 CLI 使用 Deepseek 分析任何本地仓库的提交变更
|
||||
- 完全可定制:选择模型、基础 URL 和提示词
|
||||
- 支持自托管 Deepseek 模型,提供更强的灵活性
|
||||
- 在 PR 的标题或描述中添加 `skip cr` or `skip review` 可跳过 GitHub Actions 里的代码审查
|
||||
- 跨平台:支持 GitHub `macOS`, `Ubuntu` & `Windows` Runners
|
||||
|
||||
## 计划支持特性
|
||||
|
||||
- [ ] **通过提交信息跳过代码审查**:在提交信息中添加 `skip cr` 或 `skip review` 以跳过该 PR 的代码审查
|
||||
- [ ] **通过提及触发代码审查**:当 PR 评论中提及 `github-actions bot` 时,自动触发代码审查
|
||||
- [ ] **忽略指定文件变更**:忽略对指定文件的更改,例如 `Cargo.lock`、`pnpm-lock.yaml` 等
|
||||
|
||||
## 通过 GitHub Action 进行代码审核
|
||||
|
||||
创建一个 GitHub workflow 内容如下:
|
||||
|
||||
```yaml
|
||||
name: Code Review
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened]
|
||||
types:
|
||||
- opened # Triggers when a PR is opened
|
||||
- reopened # Triggers when a PR is reopened
|
||||
- synchronize # Triggers when a commit is pushed to the PR
|
||||
|
||||
# fix: GraphQL: Resource not accessible by integration (addComment) error
|
||||
permissions:
|
||||
@@ -34,18 +40,22 @@ jobs:
|
||||
- name: Deepseek Code Review
|
||||
uses: hustcer/deepseek-review@v1
|
||||
with:
|
||||
deepseek-token: ${{ secrets.DEEPSEEK_TOKEN }}
|
||||
chat-token: ${{ secrets.CHAT_TOKEN }}
|
||||
```
|
||||
|
||||
当 PR 创建的时候会自动触发 Deepseek 代码审核,并将审核结果以评论的方式发布到对应的 PR 上。比如:[示例](https://github.com/hustcer/deepseek-review/pull/30) & [运行日志](https://github.com/hustcer/deepseek-review/actions/runs/13043609677/job/36390331791#step:2:53)
|
||||
|
||||
## 输入参数
|
||||
|
||||
| 名称 | 类型 | 描述 |
|
||||
| -------------- | ------ | -------------------------------------------------------------- |
|
||||
| deepseek-token | String | 必填,Deepseek API Token |
|
||||
| chat-token | String | 必填,Deepseek API Token |
|
||||
| model | String | 可选,配置代码审核选用的模型,默认为 `deepseek-chat` |
|
||||
| base-url | String | 可选,Deepseek API Base URL, 默认为 `https://api.deepseek.com` |
|
||||
| max-length | Int | 可选,待审核内容的最大 Unicode 长度, 默认 `0` 表示没有限制,超过非零值则跳过审核 |
|
||||
| sys-prompt | String | 可选,系统 Prompt 对应入参中的 `$sys_prompt`, 默认值见后文注释 |
|
||||
| user-prompt | String | 可选,用户 Prompt 对应入参中的 `$user_prompt`, 默认值见后文注释 |
|
||||
| github-token | String | 可选,用于访问 API 进行 PR 管理的 GitHub Token,默认为 `${{ github.token }}` |
|
||||
|
||||
Deepseek 接口调用入参:
|
||||
|
||||
@@ -71,14 +81,14 @@ Deepseek 接口调用入参:
|
||||
|
||||
### 依赖工具
|
||||
|
||||
在本地进行代码审核需要安装以下工具:
|
||||
在本地进行代码审核,支持 `macOS`, `Ubuntu` & `Windows` 不过需要安装以下工具:
|
||||
|
||||
- [`Nushell`](https://www.nushell.sh/book/installation.html) & [`Just`](https://just.systems/man/en/packages.html), 建议安装最新版本
|
||||
- 如果你需要在本地审核 GitHub PRs 还需要安装 [`gh`](https://cli.github.com/)
|
||||
- 接下来只需要把本仓库代码克隆到本地,然后进入仓库目录执行 `just code-review -h` 或者 `just cr -h` 即可看到类似如下输出:
|
||||
|
||||
```console
|
||||
Use Deepseek AI to review code changes
|
||||
Use Deepseek AI to review code changes locally or in GitHub Actions
|
||||
|
||||
Usage:
|
||||
> deepseek-review {flags} (token)
|
||||
@@ -87,9 +97,10 @@ Flags:
|
||||
-d, --debug: Debug mode
|
||||
-r, --repo <string>: GitHub repository name, e.g. hustcer/deepseek-review
|
||||
-n, --pr-number <string>: GitHub PR number
|
||||
--gh-token <string>: Your GitHub token, GITHUB_TOKEN by default
|
||||
--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
|
||||
-l, --max-length <int>: Maximum length of the content for review, 0 means no limit.
|
||||
-m, --model <string>: Model name, deepseek-chat by default (default: 'deepseek-chat')
|
||||
--base-url <string> (default: 'https://api.deepseek.com')
|
||||
-s, --sys-prompt <string> (default: '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.')
|
||||
@@ -97,7 +108,7 @@ Flags:
|
||||
-h, --help: Display the help message for this command
|
||||
|
||||
Parameters:
|
||||
token <string>: Your Deepseek API token, fallback to DEEPSEEK_TOKEN (optional)
|
||||
token <string>: Your Deepseek API token, fallback to CHAT_TOKEN env var (optional)
|
||||
|
||||
```
|
||||
|
||||
|
||||
30
action.yaml
30
action.yaml
@@ -6,18 +6,22 @@
|
||||
# - https://docs.github.com/cn/actions/creating-actions/metadata-syntax-for-github-actions
|
||||
# - https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
|
||||
|
||||
name: 'Deepseek Code Review'
|
||||
name: 'Deepseek CR'
|
||||
author: 'hustcer'
|
||||
description: 'A github action to do code review by Deepseek for PRs.'
|
||||
description: '🚀 Sharpen Your Code, Ship with Confidence – Elevate Your Workflow with Deepseek Code Review 🚀'
|
||||
|
||||
branding:
|
||||
icon: 'code'
|
||||
icon: 'eye'
|
||||
color: 'purple'
|
||||
|
||||
inputs:
|
||||
deepseek-token:
|
||||
chat-token:
|
||||
required: true
|
||||
description: 'Your deepseek API token.'
|
||||
max-length:
|
||||
default: 0
|
||||
required: false
|
||||
description: 'The maximum length of the content for review, 0 means no limit.'
|
||||
model:
|
||||
required: false
|
||||
default: 'deepseek-chat'
|
||||
@@ -34,6 +38,10 @@ inputs:
|
||||
required: false
|
||||
default: 'Please review the following code changes'
|
||||
description: 'The user prompt for deepseek API.'
|
||||
github-token:
|
||||
required: false
|
||||
default: '${{ github.token }}'
|
||||
description: 'The GITHUB_TOKEN secret or personal access token to authenticate. Defaults to `github.token`.'
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
@@ -48,20 +56,22 @@ runs:
|
||||
run: |
|
||||
const NU_LIB_DIRS = [ ${{ github.action_path }}/nu ]
|
||||
use review.nu *
|
||||
let model = '${{inputs.model}}'
|
||||
let ghToken = '${{ github.token }}'
|
||||
let baseUrl = '${{inputs.base-url}}'
|
||||
let model = '${{ inputs.model }}'
|
||||
let baseUrl = '${{ inputs.base-url }}'
|
||||
let repo = '${{ github.repository }}'
|
||||
let token = '${{inputs.deepseek-token}}'
|
||||
let sysPrompt = '${{inputs.sys-prompt}}'
|
||||
let userPrompt = '${{inputs.user-prompt}}'
|
||||
let token = '${{ inputs.chat-token }}'
|
||||
let ghToken = '${{ inputs.github-token }}'
|
||||
let sysPrompt = '${{ inputs.sys-prompt }}'
|
||||
let userPrompt = '${{ inputs.user-prompt }}'
|
||||
let pr = '${{ github.event.pull_request.number }}'
|
||||
let maxLength = try { '${{ inputs.max-length }}' | into int } catch { 0 }
|
||||
(deepseek-review $token
|
||||
--model $model
|
||||
--repo $repo
|
||||
--pr-number $pr
|
||||
--gh-token $ghToken
|
||||
--base-url $baseUrl
|
||||
--max-length $maxLength
|
||||
--sys-prompt $sysPrompt
|
||||
--user-prompt $userPrompt
|
||||
)
|
||||
|
||||
@@ -39,6 +39,7 @@ commit_parsers = [
|
||||
{ message = "^doc", group = "Documentation"},
|
||||
{ message = "^perf", group = "Performance"},
|
||||
{ message = "^refactor", group = "Refactor"},
|
||||
{ message = "^breaking", group = "Breaking Changes"},
|
||||
{ message = "^style", group = "Styling"},
|
||||
{ message = "^test", group = "Testing"},
|
||||
{ message = "^chore\\(release\\): prepare for", skip = true},
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"name": "deepseek-review",
|
||||
"version": "1.1.0",
|
||||
"actionVer": "v1.1",
|
||||
"version": "1.3.0",
|
||||
"actionVer": "v1.3",
|
||||
"author": "hustcer",
|
||||
"license": "MIT",
|
||||
"github": "https://github.com/hustcer/deepseek-review",
|
||||
"home": "https://github.com/marketplace/actions/deepseek-review",
|
||||
"description": "A github action to do code review for pull requests."
|
||||
"home": "https://github.com/marketplace/actions/deepseek-cr",
|
||||
"description": "🚀 Sharpen Your Code, Ship with Confidence – Elevate Your Workflow with Deepseek Code Review 🚀"
|
||||
}
|
||||
|
||||
51
nu/review.nu
51
nu/review.nu
@@ -10,7 +10,7 @@
|
||||
# Description: A script to do code review by deepseek
|
||||
# Env vars:
|
||||
# GITHUB_TOKEN: Your GitHub API token
|
||||
# DEEPSEEK_TOKEN: Your Deepseek API token
|
||||
# CHAT_TOKEN: Your Deepseek API token
|
||||
# BASE_URL: Deepseek API base URL
|
||||
# SYSTEM_PROMPT: System prompt message
|
||||
# USER_PROMPT: User prompt message
|
||||
@@ -38,42 +38,48 @@ const DEFAULT_OPTIONS = {
|
||||
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.',
|
||||
}
|
||||
|
||||
# Use Deepseek AI to review code changes
|
||||
# If the PR title or body contains any of these keywords, skip the review
|
||||
const IGNORE_REVIEW_KEYWORDS = ['skip review' 'skip cr']
|
||||
|
||||
# Use Deepseek AI to review code changes locally or in GitHub Actions
|
||||
export def --env deepseek-review [
|
||||
token?: string, # Your Deepseek API token, fallback to DEEPSEEK_TOKEN
|
||||
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: string, # Your GitHub token, GITHUB_TOKEN by default
|
||||
--gh-token: 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 = $DEFAULT_OPTIONS.MODEL, # Model name, deepseek-chat by default
|
||||
--base-url: string = $DEFAULT_OPTIONS.BASE_URL,
|
||||
--sys-prompt(-s): string = $DEFAULT_OPTIONS.SYS_PROMPT,
|
||||
--user-prompt(-u): string = $DEFAULT_OPTIONS.USER_PROMPT,
|
||||
] {
|
||||
]: nothing -> nothing {
|
||||
$env.config.table.mode = 'psql'
|
||||
let is_action = ($env.GITHUB_ACTIONS? == 'true')
|
||||
let token = $token | default $env.DEEPSEEK_TOKEN?
|
||||
let token = $token | default $env.CHAT_TOKEN?
|
||||
let repo = $repo | default $env.DEFAULT_GITHUB_REPO?
|
||||
let header = [Authorization $'Bearer ($token)']
|
||||
let url = $'($base_url)/chat/completions'
|
||||
let local_repo = $env.DEFAULT_LOCAL_REPO? | default (pwd)
|
||||
let max_length = $max_length | default ($env.MAX_LENGTH? | default 0 | into int)
|
||||
let setting = {
|
||||
repo: $repo,
|
||||
diff_to: $diff_to,
|
||||
diff_from: $diff_from,
|
||||
pr_number: $pr_number,
|
||||
max_length: $max_length,
|
||||
local_repo: $local_repo,
|
||||
}
|
||||
$env.GH_TOKEN = $gh_token | default $env.GITHUB_TOKEN?
|
||||
if ($token | is-empty) {
|
||||
print $'(ansi r)Please provide your Deepseek API token by setting `DEEPSEEK_TOKEN` or passing it as an argument.(ansi reset)'
|
||||
return
|
||||
print $'(ansi r)Please provide your Deepseek API token by setting `CHAT_TOKEN` or passing it as an argument.(ansi reset)'
|
||||
exit $ECODE.INVALID_PARAMETER
|
||||
}
|
||||
if $is_action and not (is-installed gh) {
|
||||
print $'(ansi r)Please install GitHub CLI from https://cli.github.com (ansi reset)'
|
||||
return
|
||||
exit $ECODE.MISSING_BINARY
|
||||
}
|
||||
let hint = if not $is_action and ($pr_number | is-empty) {
|
||||
$'🚀 Initiate the code review by Deepseek AI for local changes ...'
|
||||
@@ -84,6 +90,12 @@ export def --env deepseek-review [
|
||||
if ($pr_number | is-empty) { $setting | compact-record | reject repo | print }
|
||||
|
||||
let diff_content = get-diff --pr-number $pr_number --repo $repo --diff-to $diff_to --diff-from $diff_from
|
||||
let length = $diff_content | str stats | get unicode-width
|
||||
if ($max_length != 0) and ($length > $max_length) {
|
||||
print $'(char nl)(ansi r)The content length ($length) exceeds the maximum limit ($max_length), review skipped.(ansi reset)'
|
||||
exit $ECODE.SUCCESS
|
||||
}
|
||||
print $'Review content length: (ansi g)($length)(ansi reset), current max length: (ansi g)($max_length)(ansi reset)'
|
||||
let payload = {
|
||||
model: $model,
|
||||
stream: false,
|
||||
@@ -98,13 +110,11 @@ export def --env deepseek-review [
|
||||
if ($response | is-empty) {
|
||||
print $'(ansi r)Oops, No response returned from Deepseek API.(ansi reset)'
|
||||
exit $ECODE.SERVER_ERROR
|
||||
return
|
||||
}
|
||||
if $debug { print $'Deepseek Response:'; hr-line; $response | table -e | print }
|
||||
if ($response | describe) == 'string' {
|
||||
print $'❌ Code review failed!Error: '; hr-line; print $response
|
||||
exit $ECODE.SERVER_ERROR
|
||||
return
|
||||
}
|
||||
let review = $response | get -i choices.0.message.content
|
||||
if not $is_action {
|
||||
@@ -119,10 +129,10 @@ export def --env deepseek-review [
|
||||
|
||||
# Get the diff content from GitHub PR or local git changes
|
||||
export def get-diff [
|
||||
--pr-number: string, # GitHub PR number
|
||||
--repo: string, # GitHub repository name
|
||||
--diff-to: string, # Diff to git ref
|
||||
--diff-from: string, # Diff from git ref
|
||||
--pr-number: string, # GitHub PR number
|
||||
--diff-to: string, # Diff to git ref
|
||||
--diff-from: string, # Diff from git ref
|
||||
] {
|
||||
let local_repo = $env.DEFAULT_LOCAL_REPO? | default (pwd)
|
||||
if not ($local_repo | path exists) {
|
||||
@@ -135,6 +145,12 @@ export def get-diff [
|
||||
print $'(ansi r)Please provide the GitHub repository name by `--repo` option.(ansi reset)'
|
||||
exit $ECODE.INVALID_PARAMETER
|
||||
}
|
||||
# TODO: Ignore keywords checking when triggering by mentioning the bot
|
||||
let description = gh pr view $pr_number --repo $repo --json title,body
|
||||
if ($IGNORE_REVIEW_KEYWORDS | any {|it| $description =~ $it }) {
|
||||
print $'(ansi r)The PR title or body contains keywords to skip the review, bye...(ansi reset)'
|
||||
exit $ECODE.SUCCESS
|
||||
}
|
||||
gh pr diff $pr_number --repo $repo | str trim
|
||||
} else if ($diff_from | is-not-empty) {
|
||||
if not (has-ref $diff_from) {
|
||||
@@ -152,14 +168,13 @@ export def get-diff [
|
||||
} else { git diff }
|
||||
|
||||
if ($diff_content | is-empty) {
|
||||
print $'(ansi g)Nothing to review.(ansi reset)'
|
||||
exit $ECODE.SUCCESS
|
||||
print $'(ansi g)Nothing to review.(ansi reset)'; exit $ECODE.SUCCESS
|
||||
}
|
||||
$diff_content
|
||||
}
|
||||
|
||||
# Compact the record by removing empty columns
|
||||
export def compact-record [] {
|
||||
export def compact-record []: record -> record {
|
||||
let record = $in
|
||||
let empties = $record | columns | filter {|it| $record | get $it | is-empty }
|
||||
$record | reject ...$empties
|
||||
@@ -204,9 +219,9 @@ export def has-ref [
|
||||
|
||||
export def hr-line [
|
||||
width?: int = 90,
|
||||
--color(-c): string = 'g',
|
||||
--blank-line(-b),
|
||||
--with-arrow(-a),
|
||||
--color(-c): string = 'g',
|
||||
] {
|
||||
# Create a line by repeating the unit with specified times
|
||||
def build-line [
|
||||
|
||||
Reference in New Issue
Block a user