跳过主要内容
在本教程中,您将创建一个功能强大的工作流,该工作流可自动执行 GitHub 拉取请求的审查过程。此示例演示了如何将 CLI 工具、文件分析和用户交互结合到一个无缝的过程中。

先决条件

  • 您已安装 Cline。
  • 您已安装并认证 GitHub CLI (gh)
  • 您已打开一个 Git 存储库,其中包含一个您要测试的拉取请求。

创建拉取请求审查工作流

此工作流将自动获取 PR 详细信息、分析代码更改中的问题,并起草审查评论。
1

创建工作流文件

首先,为您的项目特定工作流创建目录结构。
  1. 在项目的根目录中,创建一个名为 .clinerules 的新文件夹。
  2. .clinerules 中,创建另一个名为 workflows 的文件夹。
  3. 最后,在 workflows 文件夹中创建一个名为 pr-review.md 的新文件。
2

编写工作流内容

打开 pr-review.md 文件并添加以下内容。此工作流将收集 PR 详细信息、分析更改,并帮助您提交审查。
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]"
```
运行此工作流时,您将把 PR_NUMBER 替换为要审查的拉取请求的实际编号(例如,/pr-review.md 123)。
3

运行工作流

现在您已准备好运行新工作流。
  1. 打开 Cline 聊天面板。
  2. 键入 /pr-review.md,后跟 PR 编号(例如,/pr-review.md 42),然后按 Enter。
  3. Cline 将获取 PR 详细信息,分析代码,并在提交审查之前向您展示其发现。
当 Cline 执行命令(例如 gh pr view)时,它可能会显示输出并暂停。您需要单击运行期间继续按钮,以允许 Cline 分析内容并继续执行工作流。

其他常见用例

这只是一个示例。您可以为各种任务创建工作流,例如:
  • 创建组件: 自动生成新文件(如 React 组件或 API 端点)的样板文件。
  • 运行测试: 创建一个运行测试套件并总结结果的工作流。
  • 部署您的应用程序: 使用 dockerkubectl 等工具自动执行部署管道。
  • 重构代码: 指导 Cline 一步一步完成复杂的重构过程。
探索 Cline 的功能和您自己的开发流程,以找到可以将重复性任务转化为高效工作流的地方。