mirror of
https://github.com/hustcer/deepseek-review.git
synced 2026-05-13 05:16:05 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
000000090a | ||
|
|
052182c5de | ||
|
|
e8e5bc99ff | ||
|
|
272fb2244e | ||
|
|
6dc9fc6f1d | ||
|
|
35a8ded25b | ||
|
|
00000006e0 | ||
|
|
88e0011fbf | ||
|
|
18450d75e8 | ||
|
|
8e67d7be7e | ||
|
|
28505c4767 | ||
|
|
4c4defaaca | ||
|
|
f536accea4 | ||
|
|
b527650ce1 | ||
|
|
40b98c9c16 | ||
|
|
8c99ac926e | ||
|
|
f962bbb88d |
20
.env.example
Normal file
20
.env.example
Normal file
@@ -0,0 +1,20 @@
|
||||
# Description: Environment variables for Local Code Review Only
|
||||
# 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'
|
||||
# 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'
|
||||
# Default GitHub repository name to fetch PR changes
|
||||
DEFAULT_GITHUB_REPO='hustcer/deepseek-review'
|
||||
# Default local repository absolute path to query commit changes
|
||||
DEFAULT_LOCAL_REPO='/Users/hustcer/deepseek-review'
|
||||
# BASE_URL: Deepseek API base URL
|
||||
# Replace with the actual API base URL if different
|
||||
BASE_URL='https://api.deepseek.ai'
|
||||
# USER_PROMPT: User prompt message, customize as needed
|
||||
USER_PROMPT='Please review the following code changes'
|
||||
# SYSTEM_PROMPT: System prompt message, customize as needed
|
||||
SYSTEM_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.'
|
||||
2
.github/workflows/basic.yml
vendored
2
.github/workflows/basic.yml
vendored
@@ -14,8 +14,6 @@ permissions:
|
||||
|
||||
jobs:
|
||||
setup-deepseek-review:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
runs-on: ubuntu-latest
|
||||
name: Code Review
|
||||
steps:
|
||||
|
||||
27
CHANGELOG.md
27
CHANGELOG.md
@@ -1,6 +1,33 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [1.1.0] - 2025-01-30
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Do not override `GITHUB_TOKEN` env var (#30)
|
||||
- Check `gh` installation status in GitHub Action (#31)
|
||||
- Add git repo and git ref checking (#32)
|
||||
- Add repo checking for GitHub PR review (#34)
|
||||
- Polish CLI output for local code review (#44)
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add features description to README (#29)
|
||||
- Add CLI help doc (#36)
|
||||
- Add planed features to doc (#39)
|
||||
- Add local code review guide (#41)
|
||||
|
||||
### Features
|
||||
|
||||
- Add dot env conf for local code review (#33)
|
||||
- Add more CLI short flags (#35)
|
||||
- Add `DEFAULT_GITHUB_REPO` & `DEFAULT_LOCAL_REPO` config for local code review (#42)
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Use `v1` in README docs (#17)
|
||||
|
||||
## [1.0.0] - 2025-01-29
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
75
README.md
75
README.md
@@ -2,6 +2,20 @@
|
||||
|
||||
[中文说明](README.zh-CN.md)
|
||||
|
||||
## Features
|
||||
|
||||
- Automate PR Reviews with Deepseek via GitHub Action
|
||||
- Review Remote GitHub PRs Directly from Your Local CLI
|
||||
- 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
|
||||
|
||||
## 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
|
||||
|
||||
```yaml
|
||||
@@ -20,7 +34,7 @@ jobs:
|
||||
name: Code Review
|
||||
steps:
|
||||
- name: Deepseek Code Review
|
||||
uses: hustcer/deepseek-review@develop
|
||||
uses: hustcer/deepseek-review@v1
|
||||
with:
|
||||
deepseek-token: ${{ secrets.DEEPSEEK_TOKEN }}
|
||||
```
|
||||
@@ -32,10 +46,10 @@ jobs:
|
||||
| deepseek-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` |
|
||||
| sys-prompt | String | Optional, system prompt corresponding to `$sys_prompt` in the input, default value see note below |
|
||||
| user-prompt | String | Optional, system prompt corresponding to `$user_prompt` in the input, default value see note below |
|
||||
| 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 |
|
||||
|
||||
**API Call Input**:
|
||||
**Deepseek API Call Payload**:
|
||||
|
||||
```js
|
||||
{
|
||||
@@ -55,6 +69,59 @@ jobs:
|
||||
}
|
||||
```
|
||||
|
||||
## Local Code Review
|
||||
|
||||
### Required Tools
|
||||
|
||||
To perform code reviews locally, 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
|
||||
|
||||
Usage:
|
||||
> deepseek-review {flags} (token)
|
||||
|
||||
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
|
||||
-t, --diff-to <string>: Diff to git REF
|
||||
-f, --diff-from <string>: Diff from git REF
|
||||
-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.')
|
||||
-u, --user-prompt <string> (default: 'Please review the following code changes:')
|
||||
-h, --help: Display the help message for this command
|
||||
|
||||
Parameters:
|
||||
token <string>: Your Deepseek API token, fallback to DEEPSEEK_TOKEN (optional)
|
||||
|
||||
```
|
||||
|
||||
### Environment Configuration
|
||||
|
||||
To perform code reviews locally, you need to modify the configuration file. A sample configuration file `.env.example` is already provided in the repository. Copy it to `.env` and adjust it according to your actual setup.
|
||||
|
||||
### Usage Examples
|
||||
|
||||
```sh
|
||||
# Perform code review on the `git diff` changes in the local DEFAULT_LOCAL_REPO repo
|
||||
just cr
|
||||
# Perform code review on the `git diff f536acc` changes in the local DEFAULT_LOCAL_REPO repo
|
||||
just 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
|
||||
# Perform code review on PR #31 in the remote DEFAULT_GITHUB_REPO repo
|
||||
just 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
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Licensed under:
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
# Deepseek Code Review
|
||||
# Deepseek 代码审核
|
||||
|
||||
## 特性
|
||||
|
||||
- 通过 GitHub Action 使用 Deepseek 进行自动化 PR 审查
|
||||
- 通过本地 CLI 直接审查远程 GitHub PR
|
||||
- 通过本地 CLI 使用 Deepseek 分析任何本地仓库的提交变更
|
||||
- 完全可定制:选择模型、基础 URL 和提示词
|
||||
- 支持自托管 Deepseek 模型,提供更强的灵活性
|
||||
|
||||
## 计划支持特性
|
||||
|
||||
- [ ] **通过提交信息跳过代码审查**:在提交信息中添加 `skip cr` 或 `skip review` 以跳过该 PR 的代码审查
|
||||
- [ ] **通过提及触发代码审查**:当 PR 评论中提及 `github-actions bot` 时,自动触发代码审查
|
||||
- [ ] **忽略指定文件变更**:忽略对指定文件的更改,例如 `Cargo.lock`、`pnpm-lock.yaml` 等
|
||||
|
||||
## 通过 GitHub Action 进行代码审核
|
||||
|
||||
@@ -18,7 +32,7 @@ jobs:
|
||||
name: Code Review
|
||||
steps:
|
||||
- name: Deepseek Code Review
|
||||
uses: hustcer/deepseek-review@develop
|
||||
uses: hustcer/deepseek-review@v1
|
||||
with:
|
||||
deepseek-token: ${{ secrets.DEEPSEEK_TOKEN }}
|
||||
```
|
||||
@@ -33,7 +47,7 @@ jobs:
|
||||
| sys-prompt | String | 可选,系统 Prompt 对应入参中的 `$sys_prompt`, 默认值见后文注释 |
|
||||
| user-prompt | String | 可选,用户 Prompt 对应入参中的 `$user_prompt`, 默认值见后文注释 |
|
||||
|
||||
接口调用入参:
|
||||
Deepseek 接口调用入参:
|
||||
|
||||
```js
|
||||
{
|
||||
@@ -53,6 +67,59 @@ jobs:
|
||||
}
|
||||
```
|
||||
|
||||
## 本地代码审核
|
||||
|
||||
### 依赖工具
|
||||
|
||||
在本地进行代码审核需要安装以下工具:
|
||||
|
||||
- [`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
|
||||
|
||||
Usage:
|
||||
> deepseek-review {flags} (token)
|
||||
|
||||
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
|
||||
-t, --diff-to <string>: Diff to git REF
|
||||
-f, --diff-from <string>: Diff from git REF
|
||||
-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.')
|
||||
-u, --user-prompt <string> (default: 'Please review the following code changes:')
|
||||
-h, --help: Display the help message for this command
|
||||
|
||||
Parameters:
|
||||
token <string>: Your Deepseek API token, fallback to DEEPSEEK_TOKEN (optional)
|
||||
|
||||
```
|
||||
|
||||
### 环境配置
|
||||
|
||||
在本地进行代码审核需要先修改配置文件,仓库里已经有了 `.env.example` 配置文件示例,将其拷贝到 `.env` 然后根据自己的实际情况进行修改即可。
|
||||
|
||||
### 使用举例
|
||||
|
||||
```sh
|
||||
# 对本地 DEFAULT_LOCAL_REPO 仓库 `git diff` 修改内容进行代码审核
|
||||
just cr
|
||||
# 对本地 DEFAULT_LOCAL_REPO 仓库 `git diff f536acc` 修改内容进行代码审核
|
||||
just cr --diff-from f536acc
|
||||
# 对本地 DEFAULT_LOCAL_REPO 仓库 `git diff f536acc 0dd0eb5` 修改内容进行代码审核
|
||||
just cr --diff-from f536acc --diff-to 0dd0eb5
|
||||
# 对远程 DEFAULT_GITHUB_REPO 仓库编号为 31 的 PR 进行代码审核
|
||||
just cr --pr-number 31
|
||||
# 对远程 hustcer/deepseek-review 仓库编号为 31 的 PR 进行代码审核
|
||||
just cr --pr-number 31 --repo hustcer/deepseek-review
|
||||
```
|
||||
|
||||
## 许可
|
||||
|
||||
Licensed under:
|
||||
|
||||
@@ -49,12 +49,12 @@ runs:
|
||||
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 repo = '${{ github.repository }}'
|
||||
let token = '${{inputs.deepseek-token}}'
|
||||
let sysPrompt = '${{inputs.sys-prompt}}'
|
||||
let userPrompt = '${{inputs.user-prompt}}'
|
||||
let ghToken = '${{ github.token }}'
|
||||
let repo = '${{ github.repository }}'
|
||||
let pr = '${{ github.event.pull_request.number }}'
|
||||
(deepseek-review $token
|
||||
--model $model
|
||||
|
||||
@@ -4,11 +4,14 @@
|
||||
# npx cspell --no-progress .
|
||||
|
||||
words:
|
||||
- psql
|
||||
- ECODE
|
||||
- endfor
|
||||
- dotenv
|
||||
- hustcer
|
||||
- Nushell
|
||||
- justfile
|
||||
- lefthook
|
||||
- deepseek
|
||||
- hustcer
|
||||
- endfor
|
||||
- dotenv
|
||||
- linewise
|
||||
ignorePaths:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "deepseek-review",
|
||||
"version": "1.0.0",
|
||||
"actionVer": "v1.0",
|
||||
"version": "1.1.0",
|
||||
"actionVer": "v1.1",
|
||||
"author": "hustcer",
|
||||
"license": "MIT",
|
||||
"github": "https://github.com/hustcer/deepseek-review",
|
||||
|
||||
170
nu/review.nu
170
nu/review.nu
@@ -11,11 +11,26 @@
|
||||
# Env vars:
|
||||
# GITHUB_TOKEN: Your GitHub API token
|
||||
# DEEPSEEK_TOKEN: Your Deepseek API token
|
||||
# BASE_URL: Deepseek API base URL
|
||||
# SYSTEM_PROMPT: System prompt message
|
||||
# USER_PROMPT: User prompt message
|
||||
# Usage:
|
||||
# 1. Local: just cr
|
||||
# 2. Local: just cr -f HEAD~1 --debug
|
||||
#
|
||||
|
||||
# Commonly used exit codes
|
||||
const ECODE = {
|
||||
SUCCESS: 0,
|
||||
OUTDATED: 1,
|
||||
MISSING_BINARY: 2,
|
||||
MISSING_DEPENDENCY: 3,
|
||||
CONDITION_NOT_SATISFIED: 5,
|
||||
SERVER_ERROR: 6,
|
||||
INVALID_PARAMETER: 7,
|
||||
AUTH_FAILED: 8,
|
||||
}
|
||||
|
||||
const DEFAULT_OPTIONS = {
|
||||
MODEL: 'deepseek-chat',
|
||||
BASE_URL: 'https://api.deepseek.com',
|
||||
@@ -24,42 +39,51 @@ const DEFAULT_OPTIONS = {
|
||||
}
|
||||
|
||||
# Use Deepseek AI to review code changes
|
||||
export def deepseek-review [
|
||||
token?: string, # Your Deepseek API token, fallback to DEEPSEEK_TOKEN
|
||||
--debug(-d), # Debug mode
|
||||
--repo: string, # GitHub repository name, e.g. hustcer/deepseek-review
|
||||
--pr-number: string, # GitHub PR number
|
||||
--gh-token: string, # Your GitHub token, GITHUB_TOKEN by default
|
||||
--diff-to(-t): string, # Diff to git ref
|
||||
--diff-from(-f): string, # Diff from git ref
|
||||
--model: string = $DEFAULT_OPTIONS.MODEL, # Model name, deepseek-chat by default
|
||||
export def --env deepseek-review [
|
||||
token?: string, # Your Deepseek API token, fallback to DEEPSEEK_TOKEN
|
||||
--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
|
||||
--diff-to(-t): string, # Diff to git REF
|
||||
--diff-from(-f): string, # Diff from git REF
|
||||
--model(-m): string = $DEFAULT_OPTIONS.MODEL, # Model name, deepseek-chat by default
|
||||
--base-url: string = $DEFAULT_OPTIONS.BASE_URL,
|
||||
--sys-prompt: string = $DEFAULT_OPTIONS.SYS_PROMPT,
|
||||
--user-prompt: string = $DEFAULT_OPTIONS.USER_PROMPT,
|
||||
--sys-prompt(-s): string = $DEFAULT_OPTIONS.SYS_PROMPT,
|
||||
--user-prompt(-u): string = $DEFAULT_OPTIONS.USER_PROMPT,
|
||||
] {
|
||||
|
||||
$env.config.table.mode = 'psql'
|
||||
let is_action = ($env.GITHUB_ACTIONS? == 'true')
|
||||
let token = $token | default $env.DEEPSEEK_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 setting = {
|
||||
repo: $repo,
|
||||
diff_to: $diff_to,
|
||||
diff_from: $diff_from,
|
||||
pr_number: $pr_number,
|
||||
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
|
||||
}
|
||||
let hint = if ($env.GITHUB_ACTIONS? != 'true') {
|
||||
if $is_action and not (is-installed gh) {
|
||||
print $'(ansi r)Please install GitHub CLI from https://cli.github.com (ansi reset)'
|
||||
return
|
||||
}
|
||||
let hint = if not $is_action and ($pr_number | is-empty) {
|
||||
$'🚀 Initiate the code review by Deepseek AI for local changes ...'
|
||||
} else {
|
||||
$'🚀 Initiate the code review by Deepseek AI for PR (ansi g)#($pr_number)(ansi reset) in (ansi g)($repo)(ansi reset) ...'
|
||||
}
|
||||
print $hint; print -n (char nl)
|
||||
$env.GITHUB_TOKEN = $gh_token | default $env.GITHUB_TOKEN?
|
||||
let diff_content = if ($pr_number | is-not-empty) {
|
||||
gh pr diff $pr_number --repo $repo | str trim
|
||||
} else if ($diff_from | is-not-empty) {
|
||||
git diff $diff_from ($diff_to | default HEAD)
|
||||
} else { git diff }
|
||||
if ($diff_content | is-empty) {
|
||||
print $'(ansi r)Please provide the diff content by passing `--pr-number`.(ansi reset)'
|
||||
return
|
||||
}
|
||||
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 payload = {
|
||||
model: $model,
|
||||
stream: false,
|
||||
@@ -68,31 +92,23 @@ export def deepseek-review [
|
||||
{ role: 'user', content: $"($user_prompt):\n($diff_content)" }
|
||||
]
|
||||
}
|
||||
if $debug {
|
||||
print $'Code Changes:'; hr-line; print $diff_content
|
||||
}
|
||||
let header = [Authorization $'Bearer ($token)']
|
||||
let url = $'($base_url)/chat/completions'
|
||||
if $debug { print $'Code Changes:'; hr-line; print $diff_content }
|
||||
print $'(char nl)(ansi g)Waiting for response from Deepseek ...(ansi reset)'
|
||||
let response = http post -e -H $header -t application/json $url $payload
|
||||
if ($response | is-empty) {
|
||||
print $'(ansi r)Oops, No response returned from Deepseek API.(ansi reset)'
|
||||
exit 1
|
||||
exit $ECODE.SERVER_ERROR
|
||||
return
|
||||
}
|
||||
if $debug {
|
||||
print $'Deepseek Response:'; hr-line
|
||||
$response | table -e | print
|
||||
}
|
||||
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 1
|
||||
exit $ECODE.SERVER_ERROR
|
||||
return
|
||||
}
|
||||
let review = $response | get -i choices.0.message.content
|
||||
if ($env.GITHUB_ACTIONS? != 'true') {
|
||||
print $'Code Review Result:'; hr-line
|
||||
print $review
|
||||
if not $is_action {
|
||||
print $'Code Review Result:'; hr-line; print $review
|
||||
} else {
|
||||
gh pr comment $pr_number --body $review --repo $repo
|
||||
print $'✅ Code review finished!PR (ansi g)#($pr_number)(ansi reset) review result was posted as a comment.'
|
||||
@@ -101,11 +117,91 @@ export def deepseek-review [
|
||||
$response.usage | table -e | print
|
||||
}
|
||||
|
||||
# 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
|
||||
] {
|
||||
let local_repo = $env.DEFAULT_LOCAL_REPO? | default (pwd)
|
||||
if not ($local_repo | path exists) {
|
||||
print $'(ansi r)The directory ($local_repo) does not exist.(ansi reset)'
|
||||
exit $ECODE.CONDITION_NOT_SATISFIED
|
||||
}
|
||||
cd $local_repo
|
||||
let diff_content = if ($pr_number | is-not-empty) {
|
||||
if ($repo | is-empty) {
|
||||
print $'(ansi r)Please provide the GitHub repository name by `--repo` option.(ansi reset)'
|
||||
exit $ECODE.INVALID_PARAMETER
|
||||
}
|
||||
gh pr diff $pr_number --repo $repo | str trim
|
||||
} else if ($diff_from | is-not-empty) {
|
||||
if not (has-ref $diff_from) {
|
||||
print $'(ansi r)The specified git ref ($diff_from) does not exist, please check it again.(ansi reset)'
|
||||
exit $ECODE.INVALID_PARAMETER
|
||||
}
|
||||
if ($diff_to | is-not-empty) and not (has-ref $diff_to) {
|
||||
print $'(ansi r)The specified git ref ($diff_to) does not exist, please check it again.(ansi reset)'
|
||||
exit $ECODE.INVALID_PARAMETER
|
||||
}
|
||||
git diff $diff_from ($diff_to | default HEAD)
|
||||
} else if not (git-check $local_repo --check-repo=1) {
|
||||
print $'Current directory ($local_repo) is (ansi r)NOT(ansi reset) a git repo, bye...(char nl)'
|
||||
exit $ECODE.CONDITION_NOT_SATISFIED
|
||||
} else { git diff }
|
||||
|
||||
if ($diff_content | is-empty) {
|
||||
print $'(ansi g)Nothing to review.(ansi reset)'
|
||||
exit $ECODE.SUCCESS
|
||||
}
|
||||
$diff_content
|
||||
}
|
||||
|
||||
# Compact the record by removing empty columns
|
||||
export def compact-record [] {
|
||||
let record = $in
|
||||
let empties = $record | columns | filter {|it| $record | get $it | is-empty }
|
||||
$record | reject ...$empties
|
||||
}
|
||||
|
||||
# Check if some command available in current shell
|
||||
export def is-installed [ app: string ] {
|
||||
(which $app | length) > 0
|
||||
}
|
||||
|
||||
# Check if git was installed and if current directory is a git repo
|
||||
export def git-check [
|
||||
dest: string, # The dest dir to check
|
||||
--check-repo: int, # Check if current directory is a git repo
|
||||
] {
|
||||
cd $dest
|
||||
if not (is-installed git) {
|
||||
print $'You should (ansi r)INSTALL git(ansi reset) first to run this command, bye...'
|
||||
exit $ECODE.MISSING_BINARY
|
||||
}
|
||||
# If we don't need repo check just quit now
|
||||
if ($check_repo != 0) {
|
||||
let checkRepo = (do -i { git rev-parse --is-inside-work-tree } | complete)
|
||||
if not ($checkRepo.stdout =~ 'true') {
|
||||
print $'Current directory is (ansi r)NOT(ansi reset) a git repo, bye...(char nl)'
|
||||
exit $ECODE.CONDITION_NOT_SATISFIED
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
# Check if a git repo has the specified ref: could be a branch or tag, etc.
|
||||
export def has-ref [
|
||||
ref: string # The git ref to check
|
||||
] {
|
||||
let checkRepo = (do -i { git rev-parse --is-inside-work-tree } | complete)
|
||||
if not ($checkRepo.stdout =~ 'true') { return false }
|
||||
# Brackets were required here, or error will occur
|
||||
let parse = (do -i { git rev-parse --verify -q $ref } | complete)
|
||||
if ($parse.stdout | is-empty) { false } else { true }
|
||||
}
|
||||
|
||||
export def hr-line [
|
||||
width?: int = 90,
|
||||
--color(-c): string = 'g',
|
||||
|
||||
Reference in New Issue
Block a user