From bb0a5d2e763ac4f11945dd88faba8293e0262dee Mon Sep 17 00:00:00 2001 From: hustcer Date: Wed, 29 Jan 2025 13:46:34 +0800 Subject: [PATCH] chore: Add basic code skeleton --- .github/workflows/basic.yml | 62 ++++++------------------------------- Justfile | 11 +++++-- README.md | 42 +------------------------ README.zh-CN.md | 41 +----------------------- action.yaml | 39 +++++++++++++++++------ lefthook.yml | 2 +- nu/review.nu | 16 +++++++++- 7 files changed, 65 insertions(+), 148 deletions(-) diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index d30a3f6..3f56185 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -3,71 +3,27 @@ # REF: # - https://github.com/marketplace/actions/checkout -name: Setup-Moonbit@Dev +name: Code Review@Dev on: + pull_request_target: + types: [opened] push: branches: - - develop - - paths-ignore: - - '**.md' + - main jobs: - setup-moonbit: - strategy: - fail-fast: false - matrix: - os: [windows-latest, ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} - name: Setup MoonBit@${{ matrix.os }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Moonbit - uses: hustcer/setup-moonbit@develop - - - name: Check Moonbit Version - run: | - moon version --all - - setup-moonbit-of-version: - strategy: - fail-fast: false - matrix: - os: [windows-latest, ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} - name: Setup MoonBit with Version@${{ matrix.os }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Moonbit with Version - uses: hustcer/setup-moonbit@develop - with: - setup-core: false - version: 0.1.20250108+7a6b9ab0e - - - name: Check Moonbit Version - run: | - moon version --all - - setup-moonbit-bleeding: + setup-deepseek-review: strategy: fail-fast: false matrix: os: [macos-latest] runs-on: ${{ matrix.os }} - name: Setup MoonBit Bleeding@${{ matrix.os }} + name: Deepseek Code Review@${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v4 - - name: Setup Moonbit Bleeding - uses: hustcer/setup-moonbit@develop + - name: Setup Deepseek Code Review + uses: hustcer/deepseek-review@main with: - version: bleeding - - - name: Check Moonbit Version - run: | - moon version --all + deepseek-token: ${{ secrets.DEEPSEEK_TOKEN }} diff --git a/Justfile b/Justfile index 6cc6858..3203a31 100644 --- a/Justfile +++ b/Justfile @@ -1,7 +1,7 @@ # Author: hustcer -# Create: 2023/10/29 18:05:20 +# Create: 2025/01/29 13:05:20 # Description: -# Some helper task for setup-moonbit +# Some helper task for deepseek-review # Ref: # 1. https://github.com/casey/just # 2. https://www.nushell.sh/book/ @@ -21,7 +21,7 @@ set dotenv-load := true set positional-arguments := true # Just commands aliases -alias f := fetch +alias cr := code-review # Use `just --evaluate` to show env vars @@ -43,6 +43,11 @@ release *OPTIONS: @overlay use {{ join(DEEPSEEK_REIVEW_PATH, 'nu', 'release.nu') }}; \ make-release {{OPTIONS}} +# Code review for GitHub PRs or local changes +code-review *OPTIONS: + @overlay use {{ join(DEEPSEEK_REIVEW_PATH, 'nu', 'review.nu') }}; \ + deepseek-review {{OPTIONS}} + # Plugins need to be registered only once after nu v0.61 _setup: @register -e json {{ join(NU_DIR, _query_plugin) }} diff --git a/README.md b/README.md index c3399e8..1043dff 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,7 @@ -# Setup MoonBit Action +# Deepseek Code Review [中文说明](README.zh-CN.md) -[![Setup-Moonbit@Dev](https://github.com/hustcer/setup-moonbit/actions/workflows/basic.yml/badge.svg)](https://github.com/hustcer/setup-moonbit/actions/workflows/basic.yml) -[![Daily Checking](https://github.com/hustcer/setup-moonbit/actions/workflows/daily.yml/badge.svg)](https://github.com/hustcer/setup-moonbit/actions/workflows/daily.yml) - -This GitHub Action will setup a [MoonBit](https://www.moonbitlang.com/) environment for you. It should work on Github `macOS` , `Ubuntu` , and `Windows` runners. - -## Usage - -### Basic - -It's quite simple to use `hustcer/setup-moonbit` , just follow the example below: - -```yaml -steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Moonbit - uses: hustcer/setup-moonbit@v1 - - - name: Check Moonbit Version - run: | - moon version --all -``` - -Or, check the [test.yaml](https://github.com/hustcer/setup-moonbit/blob/main/.github/workflows/test.yml) example. - -In rare circumstances you might get rate limiting errors, if this happens you can set the `GITHUB_TOKEN` environment variable. - -```yaml -- uses: hustcer/setup-moonbit@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -``` - -### Inputs - -| Name | Required | Description | Type | Default | -| ------------ | -------- | ------------ | ------ | --------- | -| `version` | no | A valid moonbit tool chain version, such as `0.1.20250108+7a6b9ab0e`, `nightly`, `latest`, etc. or even `bleeding` | string | `latest`| -| `setup-core` | no | `true` to download and bundle Moonbit Core, `false` to ignore it | bool | `true` | ## License diff --git a/README.zh-CN.md b/README.zh-CN.md index 1c66c90..aa5284d 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,44 +1,5 @@ -# Setup MoonBit Action +# Deepseek Code Review -[![Setup-Moonbit@Dev](https://github.com/hustcer/setup-moonbit/actions/workflows/basic.yml/badge.svg)](https://github.com/hustcer/setup-moonbit/actions/workflows/basic.yml) - -本 GitHub Action 将为你配置一个 [MoonBit](https://www.moonbitlang.com/) 开发环境。适用于 Github `macOS` , `Ubuntu` 和 `Windows` 工作流运行时镜像。 - -## 使用 - -### 基础使用 - -使用 `hustcer/setup-moonbit` 非常简单,只需要按照下面示例即可: - -```yaml -steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Moonbit - uses: hustcer/setup-moonbit@v1 - - - name: Check Moonbit Version - run: | - moon version --all -``` - -或者也可以参考下本仓库的 [test.yaml](https://github.com/hustcer/setup-moonbit/blob/main/.github/workflows/test.yml) 例子。 - -在极少数情况下,你可能会看到速率限制之类的错误。如果发生这种情况,你可以通过设置 `GITHUB_TOKEN` 环境变量来避免该问题: - -```yaml -- uses: hustcer/setup-moonbit@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -``` - -### 输入 - -| 参数名 | 必填 | 描述 | 类型 | 默认值 | -| ---------------- | -------- | --- | ------ | --------- | -| `version` | 否 | 合法的 Moonbit 工具链版本,比如: `0.1.20250108+7a6b9ab0e`, `nightly`, `latest` 或者 `bleeding` | string | `latest` | -| `setup-core` | 否 | 设置为 `true` 则下载并打包 Moonbit Core, `false` 则忽略 | bool | `true` | ## 许可 diff --git a/action.yaml b/action.yaml index d83c4b1..a91c851 100644 --- a/action.yaml +++ b/action.yaml @@ -15,14 +15,25 @@ branding: color: 'purple' inputs: - version: + deepseek-token: + required: true + description: 'Your deepseek API token.' + model: required: false - default: 'latest' - description: 'The moonbit toolchain version to setup.' - setup-core: + default: 'deepseek-chat' + description: 'The deepseek model to choose for code review.' + base-url: required: false - default: true - description: 'Set to `true` if you want to setup moonbit core.' + default: 'https://api.deepseek.com' + description: 'The base url of deepseek API.' + sys-prompt: + required: false + default: '你是一个专业的代码审查助手,负责分析GitHub Pull Request的代码变更,指出潜在的问题,如代码风格、逻辑错误、安全漏洞,并提供改进建议。请用简洁明了的语言列出问题及建议。' + description: 'The system prompt for deepseek API.' + user-prompt: + required: false + default: '请分析以下代码变更:' + description: 'The user prompt for deepseek API.' runs: using: 'composite' @@ -36,7 +47,17 @@ runs: shell: nu {0} run: | use ${{ github.action_path }}/nu/review.nu * - let version = '${{inputs.version}}' - let setupCore = '${{inputs.setup-core}}' | into bool - deepseek-review $version --setup-core=$setupCore + let model = '${{inputs.model}}' + let baseUrl = '${{inputs.base-url}}' + let token = '${{inputs.deepseek-token}}' + let sysPrompt = '${{inputs.sys-prompt}}' + let ghToken = '${{secrets.GITHUB_TOKEN}}' + let userPrompt = '${{inputs.user-prompt}}' + (deepseek-review $token + --model $model + --base-url $baseUrl + --gh-token $ghToken + --sys-prompt $sysPrompt + --user-prompt $userPrompt + ) diff --git a/lefthook.yml b/lefthook.yml index c2e9d5b..cba5a45 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -11,7 +11,7 @@ # tags: backend security # run: bundle audit # -min_version: 1.8.0 +min_version: 1.10.0 no_tty: false skip_output: - meta # Skips lefthook version printing diff --git a/nu/review.nu b/nu/review.nu index 3cb8378..3c0d1ca 100644 --- a/nu/review.nu +++ b/nu/review.nu @@ -8,7 +8,21 @@ # Usage: # -export def deepseek-review [] { +const DEFAULT_OPTIONS = { + MODEL: 'deepseek-chat', + BASE_URL: 'https://api.deepseek.com', + USER_PROMPT: '请分析以下代码变更:', + SYS_PROMPT: '你是一个专业的代码审查助手,负责分析GitHub Pull Request的代码变更,指出潜在的问题,如代码风格、逻辑错误、安全漏洞,并提供改进建议。请用简洁明了的语言列出问题及建议。', +} + +export def deepseek-review [ + token: string, # Your Deepseek API token + --gh-token: string, # Your Github token, GITHUB_TOKEN by default + --model: 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, +] { }