Deepseek review
π Sharpen Your Code, Ship with Confidence β Elevate Your Workflow with DeepSeek Code Review π
- Automate PR Reviews with DeepSeek via GitHub Action - Add `skip cr` or `skip review` to the PR title or body to disable code review in GitHub Actions - Cross-platform Support: Compatible with GitHub Runners across `macOS`, `Ubuntu`, and `Windows`. - Allows interactive pull request author (must be included within `$allowed-associations`) to model conversation by appending a message after mentioning `$watch-mention` in a pull request comment. > [!IMPORTANT] > Contents retrieved from a comment wi... The project is written primarily in Nushell, distributed under the MIT License license, first published in 2025. Key topics include: cli, codereview, deepseek.
DeepSeek Code Review
Features
GitHub Action
- Automate PR Reviews with DeepSeek via GitHub Action
- Add
skip crorskip reviewto the PR title or body to disable code review in GitHub Actions - Cross-platform Support: Compatible with GitHub Runners across
macOS,Ubuntu, andWindows. - Allows interactive pull request author (must be included within
$allowed-associations) to model conversation by appending a message after mentioning$watch-mentionin a pull request comment.
[!IMPORTANT]
Contents retrieved from a comment with$watch-mentionhas lower priority than$sys-prompt. Therefore, it might be overridden by$sys-promptand ignored by model.
Local Code Review
- Streaming output support for local code review
- Review remote GitHub PRs directly from your local CLI
- Review commit changes with DeepSeek for any local repository via CLI
- Support on-demand change generation via
git show/git diffcommands for further code review - Output code review results to a specified file in Markdown format
- Cross-platform compatibility: Designed to function seamlessly across all platforms capable of running Nushell
Both GH Action & Local
- Support both DeepSeek's
V4andR1models - Fully customizable: Choose models, base URLs, and prompts
- Support self-hosted DeepSeek models for enhanced flexibility
- Perform code reviews for changes that either include or exclude specific files
Planned Features
- Trigger Code Review on Mention: Automatically initiate code review when the
github-actionsbot is mentioned in a PR comment. - Generate Commit Message Locally: Generate a commit message for the code changes in any local repository.
Code Review with GitHub Action
Initiate Code Review When a PR is Created
Add a GitHub workflow with the following contents:
<details> <summary>CHAT_TOKEN Config</summary>yamlname: Code Review on: pull_request_target: 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: pull-requests: write jobs: setup-deepseek-review: runs-on: ubuntu-latest name: Code Review steps: - name: DeepSeek Code Review uses: hustcer/deepseek-review@v1 with: chat-token: ${{ secrets.CHAT_TOKEN }}
Follow these steps to config your CHAT_TOKEN:
- Click on the "Settings" tab in your repository navigation bar.
- In the left sidebar, click on "Secrets and variables" under "Security".
- Click on "Actions" -> "New repository secret" button.
- Enter
CHAT_TOKENin the "Name" field. - Enter the value of your
CHAT_TOKENin the "Secret" field. - Finally, click the "Add secret" button to save the secret.
When a PR is created, DeepSeek code review will be automatically triggered, and the review results (depending on your prompt) will be posted as a formal review on the corresponding PR. For example:
- Example 1 with default prompts & Run Log.
- Example 2 with this prompt
Trigger Code Review When a Specific Label is Added
If you don't want automatic code review on PR creation, you can choose to trigger code review by adding a label. For example, create the following workflow:
yamlname: Code Review on: pull_request_target: types: - labeled # Triggers when a label is added to the PR # fix: GraphQL: Resource not accessible by integration (addComment) error permissions: pull-requests: write jobs: setup-deepseek-review: runs-on: ubuntu-latest name: Code Review # Make sure the code review happens only when the PR has the label 'ai review' if: contains(github.event.pull_request.labels.*.name, 'ai review') steps: - name: DeepSeek Code Review uses: hustcer/deepseek-review@v1 with: chat-token: ${{ secrets.CHAT_TOKEN }}
With this setup, DeepSeek code review will not run automatically upon PR creation. Instead, it will only be triggered when you manually add the ai review label.
Trigger Code Review via PR Comment Mention
You can trigger code review by mentioning a specific string (e.g. @github-actions) in a PR comment. First, add issue_comment to your workflow events, then configure the watch-mention input:
yamlname: Code Review on: pull_request_target: types: - opened - reopened - synchronize issue_comment: types: - created # Triggers when a comment is created on a PR permissions: pull-requests: write jobs: setup-deepseek-review: runs-on: ubuntu-latest name: Code Review steps: - name: DeepSeek Code Review uses: hustcer/deepseek-review@v1 with: model: "deepseek-ai/DeepSeek-R1" base-url: "https://api.siliconflow.cn/v1" watch-mention: "@github-actions" chat-token: ${{ secrets.CHAT_TOKEN }} allowed-associations: "OWNER,MEMBER,COLLABORATOR"
PRECAUTIONS:
- Every qualifying mention triggers a new review run; the results are submitted as a new review on the same PR.
- Bot comments (users ending with
[bot]) are ignored. - The triggering PR comment body is included as additional model input for that review run.
- Comments on issues without an associated PR are ignored.
[!NOTE]
By default, only COLLABORATORs, OWNER, MEMBERs can trigger the code review by mentioning$watch-mention.
Other users without write access will be ignored.
You can change this by appending or removing roles in$allowed-associations. For example, if you want to enable contributors to trigger code reviews, set it as follows:
allowed-associations: 'OWNER,MEMBER,COLLABORATOR,CONTRIBUTOR'
Input Parameters
| Name | Type | Description |
|---|---|---|
| chat-token | String | Required, DeepSeek API Token |
| model | String | Optional, The model used for code review, defaults to deepseek-v4-flash |
| 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 |
| temperature | Number | Optional, The temperature for the model to generate the response, between 0 and 2. Default value is 0.3 |
| include-patterns | String | Optional, Comma-separated file patterns to include in the code review. No default |
| exclude-patterns | String | Optional, Comma-separated file patterns to exclude from the code review. Defaults 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 }}. |
| watch-mention | String | Optional, Trigger code review when this string is mentioned in a PR comment, e.g. @github-actions. Requires issue_comment event in the workflow. |
| allowed-associations | String | Optional, Comma-separated author_association values allowed to trigger review via PR comment. Defaults to OWNER,MEMBER,COLLABORATOR. |
DeepSeek API Call Payload:
js{ // `$model` default value: deepseek-v4-flash model: $model, stream: false, temperature: $temperature, messages: [ // `$sys_prompt` default value: 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. { role: 'system', content: $sys_prompt }, // `$user_prompt` default value: Please review the following code changes // `diff_content` will be the code changes of current PR { role: 'user', content: $"($user_prompt):\n($diff_content)" } ] }
[!NOTE]
You can control the language of the code review results through the language of the
prompt. The default prompt language is currently English. When you use a Chinese
prompt, the generated code review results will be in Chinese.
Local Code Review
Required Tools
To perform code reviews locally (works on macOS, Ubuntu, and Windows), you need to install the following tools:
Nushell. It is recommended to install the latest version (minimum version required:0.113.1).- The latest version of
awkorgawkis required, withgawkbeing preferred. - 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:
consoleUse DeepSeek AI to review code changes locally or in GitHub Actions Usage: > nu cr {flags} (token) Flags: -d, --debug: Debug mode -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 -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-v4-flash` by default -b, --base-url <string>: DeepSeek API base URL, fallback to BASE_URL env var -U, --chat-url <string>: DeepSeek Model chat full API URL, e.g. http://localhost:11535/api/chat -s, --sys-prompt <string>: Default to $DEFAULT_OPTIONS.SYS_PROMPT, -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 `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 Parameters: token <string>: Your DeepSeek API token, fallback to CHAT_TOKEN env var (optional)
Environment Configuration
To perform code reviews locally, you need to modify the configuration file. The repository provides a configuration example config.example.yml. Copy it to config.yml and modify it according to your needs. Read the comments in the configuration file carefully, as they explain the purpose of each configuration item.
[!WARNING]
The
config.ymlconfiguration file is only used locally and will not be utilized in GitHub Workflows. Sensitive information in this file should be properly secured and never committed to the code repository.
Create a Command Alias
For convenience when performing code reviews across any local repository, create a command alias. For example:
sh# For Nushell: Modify config.nu and add: alias cr = nu /absolute/path/to/deepseek-review/cr --config /absolute/path/to/deepseek-review/config.yml # Modify ~/.zshrc for zsh, ~/.bashrc for bash, or ~/.config/fish/config.fish for fish and add: alias cr="nu /absolute/path/to/deepseek-review/cr --config /absolute/path/to/deepseek-review/config.yml" # After sourcing the modified profile, use `cr` for code reviews # For Windows PowerShell users, set the cr alias by editing $PROFILE and add: function cr { nu D:\absolute\path\to\deepseek-review\cr --config D:\absolute\path\to\deepseek-review\config.yml @args } # Then restart the terminal or run `. $PROFILE` in pwsh to make `cr` work
Review Local Repository
To review a local repository:
- Navigate to the Git repository directory.
- Use the
crcommand to review current modifications, provided thatconfig.ymlis correctly configured.
Usage Examples
sh# Perform code review on the `git diff` changes in the current directory cr # Perform code review on the `git diff f536acc` changes in the current directory cr --diff-from f536acc # Perform code review on the `git diff f536acc` changes and output the result to review.md cr --diff-from f536acc --output review.md # Perform code review on the `git diff f536acc 0dd0eb5` changes in the current directory cr --diff-from f536acc --diff-to 0dd0eb5 # Review the changes in the current directory using the `--patch-cmd` flag cr --patch-cmd 'git diff head~3' cr -c 'git show head~3' cr -c 'git diff 2393375 71f5a31' cr -c 'git diff 2393375 71f5a31 nu/*' cr -c 'git diff 2393375 71f5a31 :!nu/*' # Dangerous commands like `cr -c 'git show head~3; rm ./*'` will not be allowed
Review Remote GitHub PR Locally
When reviewing a remote GitHub PR locally:
- Always specify the PR number via
--pr-number. - Use
--repoto indicate the target repository (e.g.,hustcer/deepseek-review). If--repois omitted, the tool readssettings.default-github-repofromconfig.yml.
Usage Examples
sh# Perform code review on PR #31 in the remote DEFAULT_GITHUB_REPO repository cr --pr-number 31 # Perform code review on PR #31 in the remote hustcer/deepseek-review repository cr --pr-number 31 --repo hustcer/deepseek-review # Perform code review on PR #31 and exclude changes in pnpm-lock.yaml cr --pr-number 31 --exclude pnpm-lock.yaml
License
Licensed under:
- MIT license (LICENSE or http://opensource.org/licenses/MIT)
Contributors
Showing top 2 contributors by commit count.
