MCPcopy Index your code
hub / github.com/buxuku/ai-code-reviewer

github.com/buxuku/ai-code-reviewer @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
20 symbols 33 edges 5 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

@buxuku/ai-code-reviewer

介绍

@buxuku/ai-code-reviewer 是一款应用于 GitLab Merge Request 代码审查的小工具,支持调用私有化部署的 GitLab API,并使用 OpenAI API 获取审查结果。请注意,在使用它时,需要确保符合公司合规要求。😉

特点

  • 🛠️ 支持配置 GitLab API 地址
  • 🌍 支持配置 OpenAI 代理 API 地址,解决国内可能无法访问 OpenAI API 的问题
  • 🆔 支持配置 OpenAI 组织 ID
  • ⚙️ 支持配置多个 OpenAI API Key 实现接口调用的负载均衡(多个 Key 以逗号分隔)
  • 🚦 超过速率限制时,自动等待并重试
  • 💬 审查结果以评论的方式追加到对应的代码块所在位置

安装

npm i @buxuku/ai-code-reviewer
`````

## 使用

### 通过 Shell 脚本使用

```shell
Usage: ai-code-reviewer [options]

Options:
  -g, --gitlab-api-url <string>       GitLab API URL (default: " https://gitlab.com/api/v4")
  -t, --gitlab-access-token <string>  GitLab Access Token
  -o, --openai-api-url <string>       OpenAI API URL (default: "https://api.openai.com")
  -a, --openai-access-token <string>  OpenAI Access Token
  -p, --project-id <number>           GitLab Project ID
  -m, --merge-request-id <string>     GitLab Merge Request ID
  -org, --organization-id <number>    organization ID
  -h, --help                          display help for command

示例:

ai-code-reviewer -g https://gitlab.com/api/v4 -t glpat-xxxxxxx -o https://api.openai.com -a skxxxxxxx,skxxxxxxx -p 432288 -m 8

在 CI 中使用

在 GitLab CI/CD 中设置 GITLAB_TOKENCHATGPT_KEY 变量,.gitlab-ci.yml 如下:

stages:
  - merge-request

Code Review:
  stage: merge-request  
  image: node:latest
  script:
    - npm i @buxuku/ai-code-reviewer -g
    - ai-code-reviewer -t "$GITLAB_TOKEN" -a "$CHATGPT_KEY"  -p "$CI_MERGE_REQUEST_PROJECT_ID" -m "$CI_MERGE_REQUEST_IID"
  only:
    - merge_requests
  when: on_success

贡献

欢迎贡献代码,提出问题和建议!👏

许可证

本项目基于 MIT 许可证。详细信息请参见 LICENSE 文件。📜

Extension points exported contracts — how you extend this code

ICompletion (Interface)
(no doc)
src/openai.ts
IGitLabConfig (Interface)
(no doc)
src/gitlab.ts
IMergeRequestInfo (Interface)
(no doc)
src/gitlab.ts

Core symbols most depended-on inside this repo

reviewCodeChange
called by 1
src/openai.ts
run
called by 1
src/index.ts
parseLastDiff
called by 1
src/gitlab.ts
init
called by 1
src/gitlab.ts
getMergeRequestInfo
called by 1
src/gitlab.ts
getMergeRequestChanges
called by 1
src/gitlab.ts
addReviewComment
called by 1
src/gitlab.ts
delay
called by 1
src/utils.ts

Shape

Method 8
Function 5
Class 4
Interface 3

Languages

TypeScript100%

Modules by API surface

src/gitlab.ts11 symbols
src/openai.ts5 symbols
src/utils.ts3 symbols
src/index.ts1 symbols

For agents

$ claude mcp add ai-code-reviewer \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact