工作流快速开始
本教程将创建一个自动化 GitHub Pull Request 审查的工作流,展示如何结合 CLI 工具、文件分析和用户交互。
前置条件
- 已安装 Careti
- 已安装并认证 GitHub CLI(
gh) - 打开一个包含待测试 PR 的 Git 仓库
创建 PR 审查工作流
该工作流会获取 PR 信息、分析改动并生成审查评论。
创建工作流文件
创建项目级工作流目录。
- 在项目根目录创建
.agents/context/workflows - 在该目录下创建
pr-review.md
编写工作流内容
将以下内容写入 pr-review.md。
# Pull Request Reviewer
This workflow helps me review a pull request by analyzing the changes and drafting a review.
## 1. Gather PR Information
First, I need to understand what this PR is about. I'll fetch the title, description, and list of changed files.
```bash
gh pr view PR_NUMBER --json title,body,files
```
## 2. Examine Modified Files
Now I will examine the diff to understand the specific code changes.
```bash
gh pr diff PR_NUMBER
```
## 3. Analyze Changes
I will analyze the code changes for:
* **Bugs:** Logic errors or edge cases.
* **Performance:** Inefficient loops or operations.
* **Security:** Vulnerabilities or unsafe practices.
## 4. Confirm Assessment
Based on my analysis, I will present my findings and ask how you want to proceed.
```xml
<ask_followup_question>
<question>I've reviewed PR #PR_NUMBER. Here is my assessment:
[Insert Analysis Here]
Do you want me to approve this PR, request changes, or just leave a comment?</question>
<options>["Approve", "Request Changes", "Comment", "Do nothing"]</options>
</ask_followup_question>
```
## 5. Execute Review
Finally, I will execute the review command based on your decision.
```bash
# If approving:
gh pr review PR_NUMBER --approve --body "Looks good to me! [Summary of analysis]"
# If requesting changes:
gh pr review PR_NUMBER --request-changes --body "Please address the following: [Issues list]"
# If commenting:
gh pr review PR_NUMBER --comment --body "[Comments]"
```
Note
运行时请将 PR_NUMBER 替换为实际 PR 编号(例如:/pr-review.md 123)。
运行工作流
现在可以运行该工作流了。
- 打开 Careti 聊天面板
- 输入
/pr-review.md+ PR 编号(例如:/pr-review.md 42) - Careti 会获取 PR 信息、分析代码并展示结果
Tip
当 Careti 执行 gh pr view 等命令时可能会暂停显示输出,请点击 Proceed While Running 继续。
其他常见用法
这只是一个示例。你还可以为很多任务创建工作流:
- 创建组件: 自动生成 React 组件或 API 端点的模板
- 运行测试: 执行测试并汇总结果
- 自动部署: 使用
docker、kubectl等工具 - 分步重构: 引导完成复杂重构
在你的项目中寻找重复性工作,并将它们转化为高效的 Careti 工作流。