diff --git a/src/devstar/ai-code-reveiw.md b/src/devstar/ai-code-reveiw.md index bb6dc28..9e6b5c3 100644 --- a/src/devstar/ai-code-reveiw.md +++ b/src/devstar/ai-code-reveiw.md @@ -30,3 +30,106 @@ DevStar代码托管平台中项目设置、用户设置和后台管理中都可 ### AI Code Review详解 +## **一、核心工作流程说明** + +AI Code Review 的执行过程如下: + +1. **触发条件** + - 当有人新建 PR(pull_request/opened) + - 或更新了 PR(pull_request/synchronize) + → 工作流自动开始执行。 +2. **代码检出(Checkout)** + 使用 actions/checkout 拉取 PR 的代码差异,为审查准备上下文。 +3. **调用 AiReviewPR Action** + - Action 会读取 PR 的 diff、文件内容与上下文。 + - 将这些内容组装为审查提示(prompt)。 + - 调用你配置的大模型(Ollama、OpenAI 兼容接口等)。 + - 获得模型输出后,自动写入 PR 评论区或输出到日志。 +4. **输出结果** + - 如果 `REVIEW_PULL_REQUEST=true` → 自动在 PR 下评论。 + - 如果为 false → 只在日志输出,便于本地验证。 + +------ + +## **二、AiReviewPR 的内部实现机制** + +以下是 Action 的实际工作方式(代码见 GitHub): + +### **1. 自动收集 PR 信息** + +Action 会自动读取: + +- PR 编号、作者、提交信息 +- diff 内容(新增、删除、修改) +- 受影响的文件内容 + +### **读取 PR Diff** + +``` +const diff = await octokit.pulls.get({ + ...github.context.issue, + mediaType: { format: "diff" }, +}).then(r => r.data); +``` + +### 2. 构建审查 Prompt + +Prompt 会自动包含: + +- 代码变更摘要 + +- 修改前/修改后的代码片段 + +- 模型需要回答的格式,例如: + + ``` + 1. 潜在Bug + 2. 代码风格问题 + 3. 性能优化 + 4. 安全风险 + 5. 重构建议 + ``` + +### **3. 调用大模型 API** + +AiReviewPR 支持任意 OpenAI API 兼容模型,例如: + +- 本地 **Ollama** +- OpenAI、DeepSeek、Qwen 公开服务 +- 私有化模型服务 + +只需提供: + +``` +vars.MODEL +vars.OLLAMA_HOST +``` + +Action 会自动发送: + +``` +{ + "model": "qwen2.5:14b", + "messages": [ + {"role": "system", "content": "..."}, + {"role": "user", "content": "这是PR的代码修改内容..."} + ] +} +``` + +### **4. 返回数据解析** + +Action 提取模型的回答内容,将其转换为 Markdown,并根据配置输出为: + +- GitHub/Gitea PR 评论 + 或 +- 工作流日志(便于调试) + +### **发布评论** + +``` +await octokit.issues.createComment({ + ...github.context.issue, + body: review, +}); +``` \ No newline at end of file diff --git a/src/devstar/ai-devops.md b/src/devstar/ai-devops.md index 0ab0abe..65ee067 100644 --- a/src/devstar/ai-devops.md +++ b/src/devstar/ai-devops.md @@ -1,3 +1,5 @@ + + # DevStar AI+ DevOps DevStar AI+ DevOps 是一个完整的AI驱动研发平台解决方案,通过集成 DevStar平台、代码大语言模型、Gitea MCP Server和 AI Code Tools(Cursor、Claude Code、iFlow等),为开发者提供智能化研发支撑体系。 @@ -13,12 +15,11 @@ wget -c https://devstar.cn/assets/install.sh && chmod +x install.sh && sudo ./in sudo devstar start ``` -安装完成后,我们得到DevStar代码托管平台的URL,比如http://172.16.94.26:80 +安装完成后,我们得到DevStar代码托管平台的URL,比如http://172.16.94.26:80 ,之后作为 `GITEA_HOST`(给 MCP Server 用) ### 二、Ollama私有部署代码大模型 -> 如您使用第三方大模型开放API可以跳过这一部分。 -> 比如从[智谱AI开放平台](https://bigmodel.cn/usercenter/proj-mgmt/apikeys) 上注册申请并添加新的API Key,以Claude Code为例URL使用https://open.bigmodel.cn/api/anthropic +> 如您使用第三方API及Token,比如从注册申请,可以跳过这一部分。 Ubuntu-20.04下完成安装: ``` @@ -53,7 +54,15 @@ systemctl daemon-reload systemctl restart ollama ``` -安装完成后,我们得到API URL,比如http://172.16.94.26:11434/api/tags model比如qwen2.5-coder:32b token比如TOKEN*************** +**产出** + +- 模型服务地址,例如:`http://172.16.94.26:11434` +- 模型名,例如:`qwen2.5-coder:32b` +- (如有)访问 Token,例如:`TOKEN***************` + +**后面用在哪里** + +- CI/CD 里的 AI Code Review(作为 `vars.MODEL` / `vars.OLLAMA_HOST`) ### 三、在项目中使用代码大模型 @@ -82,8 +91,14 @@ jobs: model: ${{ vars.MODEL }} host: ${{ vars.OLLAMA_HOST }} REVIEW_PULL_REQUEST: false + //如果用ai token 则需配置 + //ai_token: ${{ vars.AI_TOKEN }} ``` -DevStar代码托管平台中项目设置、用户设置和后台管理中都可以设置变量vars.MODEL、vars.OLLAMA_HOST等。 +然后在 DevStar(项目设置 / 用户设置 / 后台管理)里设置变量: + +- `vars.MODEL`:填入 **第二步中的模型名**,例如 `qwen2.5-coder:32b` +- `vars.OLLAMA_HOST`:填入 **第二步中得到的模型服务地址** 例如 `http://172.16.94.26:11434` +- `vars.AI_TOKEN`:填入 **第二步中第三方获取的token** #### 安装配置MCP Server @@ -95,7 +110,6 @@ DevStar代码托管平台中项目设置、用户设置和后台管理中都可 ``` { - "mcp": { "inputs": [ { "type": "promptString", @@ -118,20 +132,37 @@ DevStar代码托管平台中项目设置、用户设置和后台管理中都可 "docker.gitea.com/gitea-mcp-server" ], "env": { - "GITEA_HOST": "--host http://172.16.94.26", + "GITEA_HOST": "", "GITEA_ACCESS_TOKEN": "${input:gitea_token}" } } } - } } ``` +`GITEA_HOST`:**第一步中得到的 DevStar 代码托管平台地址** + +`gitea_token`:来自 DevStar / Gitea 的「个人访问令牌」 + +获取方式: + +1. 登录 DevStar(`GITEA_HOST` 对应的网站) +2. 进入:**设置 → 应用 ** +3. 点击「生成新的令牌」,给予仓库读取等必要权限 +4. 复制生成的一串字符串,这就是你的 `gitea_token` + #### 配置AI IDE/CLI使用私有大模型及MCP Server -* Copilot,简要文字描述,不要上太多图,可以提供官方配置链接 -* Cursor -* Continue +* Copilot,点击提示框里的“管理模型”,选择ollama;将mcp配置添加到 .vscode/mcp.json下 + +* Cursor,不支持私有模型,需要本地部署后做代理;点击Cursor Settings -> Tools & MCP + + -> New MCP Server 将mcp配置添加到mcp.json中 + +* Continue,点击Add Chat model,Provider选择ollama;设置->Tools->MCP Servers配置yaml文件 + + 也可以将cursor的json文件放到.continue/mcpServers/mcp.json中 + * ... ## 🚀 DevStar AI+ DevOps演示 @@ -142,20 +173,29 @@ DevStar代码托管平台中项目设置、用户设置和后台管理中都可 使用ai-develops项目模板创建项目 -todo +![](./static/template.png) ### AI生成代码 -todo +1.请在 Gitea 仓库 owner/repo 中读取 issue #123,帮我用自己的话总结问题、预期行为,并给出一个简单的解决思路。 + +2.请根据你对 issue #123 的理解实现这个功能 + +3.请为这次修复 issue #123 的改动补充或更新测试代码,遵循项目的现有测试风格,并说明每个测试在验证什么行为。 + + ### 提交PR -todo +1.请使用 Gitea MCP 为 issue #123 创建一个新分支(如 fix/issue-123),将本次所有相关修改提交为一个清晰的 commit + +2.请使用 Gitea MCP 从你刚才创建的分支向 main 分支发起一个 PR,标题中包含 “#123”,描述中简要说明问题、解决方案、主要改动和测试情况,并把 PR 的链接或编号发给我。 + +![](./static/pr.png) ### AI Code Review -todo +![](./static/code-review.png) -### 合并PR +![](./static/review.png) -todo \ No newline at end of file diff --git a/src/devstar/mcp-server.md b/src/devstar/mcp-server.md index f1de90f..55b781a 100644 --- a/src/devstar/mcp-server.md +++ b/src/devstar/mcp-server.md @@ -45,7 +45,22 @@ ### MCP Server使用注意事项 -* Copilot,简要文字描述,不要上太多图,可以提供官方配置链接 -* Cursor -* Continue -* ... +#### Copilot(VS Code) + +- 配置放在 `.vscode/mcp.json`。重启 VS Code → Copilot 自动加载。 +- [官方文档](https://vscode.js.cn/docs/copilot/customization/mcp-servers) + + + +#### Cursor + +- 配置放在 `.cursor/mcp.json` 或 `.vscode/mcp.json`。 +- 打开 Cursor → 会提示“检测到 MCP Server”。点 Enable 即可。 +- [官方文档](https://cursor.com/cn/docs/context/mcp) + + + +#### Continue + +- 配置放在 `.continue/mcpServers/mcp.json` +- [官方文档](https://docs.continue.dev/customize/deep-dives/mcp) \ No newline at end of file diff --git a/src/devstar/static/code-review.png b/src/devstar/static/code-review.png new file mode 100644 index 0000000..7d557dc Binary files /dev/null and b/src/devstar/static/code-review.png differ diff --git a/src/devstar/static/code.png b/src/devstar/static/code.png new file mode 100644 index 0000000..08465b3 Binary files /dev/null and b/src/devstar/static/code.png differ diff --git a/src/devstar/static/feature-2.png b/src/devstar/static/feature-2.png new file mode 100644 index 0000000..567839f Binary files /dev/null and b/src/devstar/static/feature-2.png differ diff --git a/src/devstar/static/feature.png b/src/devstar/static/feature.png new file mode 100644 index 0000000..1c4f257 Binary files /dev/null and b/src/devstar/static/feature.png differ diff --git a/src/devstar/static/issue.png b/src/devstar/static/issue.png new file mode 100644 index 0000000..9d5882a Binary files /dev/null and b/src/devstar/static/issue.png differ diff --git a/src/devstar/static/mcp.png b/src/devstar/static/mcp.png new file mode 100644 index 0000000..a6050fb Binary files /dev/null and b/src/devstar/static/mcp.png differ diff --git a/src/devstar/static/ollama-llm.png b/src/devstar/static/ollama-llm.png new file mode 100644 index 0000000..9e58f90 Binary files /dev/null and b/src/devstar/static/ollama-llm.png differ diff --git a/src/devstar/static/port.png b/src/devstar/static/port.png new file mode 100644 index 0000000..26e19dd Binary files /dev/null and b/src/devstar/static/port.png differ diff --git a/src/devstar/static/pr.png b/src/devstar/static/pr.png new file mode 100644 index 0000000..6a31e81 Binary files /dev/null and b/src/devstar/static/pr.png differ diff --git a/src/devstar/static/review.png b/src/devstar/static/review.png new file mode 100644 index 0000000..d7b9f99 Binary files /dev/null and b/src/devstar/static/review.png differ diff --git a/src/devstar/static/template.png b/src/devstar/static/template.png new file mode 100644 index 0000000..a2ac1df Binary files /dev/null and b/src/devstar/static/template.png differ diff --git a/src/devstar/static/vars.png b/src/devstar/static/vars.png new file mode 100644 index 0000000..bc90b8c Binary files /dev/null and b/src/devstar/static/vars.png differ