> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 在合并前自动修复 PR 中的 Bug

export const UseCaseHero = ({title, description, prompt, category, features, devinUrl, agent, intent, playbookId, type}) => {
  const encodedPrompt = encodeURIComponent(prompt || '');
  const tag = 'docs-use-case-gallery';
  const utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=hero-cta';
  const agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  const devinHref = type === 'schedule' ? 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + (prompt ? '&prompt=' + encodedPrompt : '') : type === 'review' ? 'https://app.devin.ai/review?' + utm : agent === 'ada' ? 'https://app.devin.ai/search?' + utm + '&noSubmit=true' + (prompt ? '&prompt=' + encodedPrompt : '') : devinUrl ? devinUrl.includes('?') ? devinUrl + '&' + utm + agentParams : devinUrl + '?' + utm + agentParams : prompt ? 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encodedPrompt : 'https://app.devin.ai/?' + utm + agentParams;
  const buttonLabel = type === 'schedule' ? 'Schedule in Devin ↗' : type === 'review' ? 'Set Up Devin Review ↗' : agent === 'advanced' ? 'Try in Devin ↗' : agent === 'dana' ? 'Try in Dana ↗' : agent === 'ada' ? 'Try in Ask Devin ↗' : 'Try in Devin ↗';
  const featureList = features ? features.split(',').map(f => f.trim()) : [];
  return <div className="uc-hero">
      <div className="uc-hero-inner">
        <div className="uc-hero-left">
          <h1 className="uc-hero-title">{title}</h1>
          <p className="uc-hero-desc">{description}</p>
          <div>
            <a href={devinHref} target="_blank" rel="noopener noreferrer" className="try-in-devin-btn">
              {buttonLabel}
            </a>
          </div>
        </div>
        <div className="uc-hero-meta">
          <div className="uc-meta-item">
            <span className="uc-meta-label">Author</span>
            <span className="uc-meta-value">Cognition</span>
          </div>
          <div className="uc-meta-item">
            <span className="uc-meta-label">Category</span>
            <span className="uc-meta-value">{category}</span>
          </div>
          {featureList.length > 0 && <div className="uc-meta-item">
              <span className="uc-meta-label">Features</span>
              <span className="uc-meta-value">{featureList.join(', ')}</span>
            </div>}
        </div>
      </div>
    </div>;
};

export const PromptBlock = ({children, type, agent, intent, playbookId}) => {
  var utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=prompt-block';
  var tag = 'docs-use-case-gallery';
  var agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  var label = type === 'schedule' ? 'Schedule in Devin' : type === 'playbook' ? 'Create Playbook' : type === 'knowledge' ? 'Add to Knowledge' : agent === 'advanced' ? 'Try in Devin' : agent === 'dana' ? 'Try in Dana' : agent === 'ada' ? 'Try in Ask Devin' : 'Try in Devin';
  var buildUrl = function (text) {
    var encoded = encodeURIComponent(text);
    if (type === 'schedule') return 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + '&prompt=' + encoded;
    if (type === 'playbook') return 'https://app.devin.ai/settings/playbooks/create?' + utm + '&body=' + encoded;
    if (type === 'knowledge') return 'https://app.devin.ai/knowledge?' + utm + '&body=' + encoded;
    if (agent === 'ada') return 'https://app.devin.ai/search?' + utm + '&noSubmit=true&prompt=' + encoded;
    return 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encoded;
  };
  const ref = React.useRef(null);
  const [href, setHref] = React.useState('#');
  React.useEffect(() => {
    if (!ref.current) return;
    var codeEl = ref.current.querySelector('pre code');
    if (codeEl) {
      var text = codeEl.textContent.trim();
      if (text) setHref(buildUrl(text));
    }
    var header = ref.current.querySelector('[data-component-part="code-block-header"]');
    if (header && !header.querySelector('.prompt-block-devin-link')) {
      var link = document.createElement('a');
      link.href = href;
      link.target = '_blank';
      link.rel = 'noopener noreferrer';
      link.className = 'prompt-block-devin-link';
      link.style.cssText = 'display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:#fff;font-size:11px;font-weight:500;padding:4px 10px;border-radius:6px;white-space:nowrap;background:#317CFF;transition:background 0.2s;margin-left:8px;';
      link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> ' + label;
      link.onmouseenter = function () {
        link.style.background = '#2968D9';
      };
      link.onmouseleave = function () {
        link.style.background = '#317CFF';
      };
      header.appendChild(link);
    }
    var existingLink = ref.current.querySelector('.prompt-block-devin-link');
    if (existingLink && href !== '#') existingLink.href = href;
  });
  return <div className="prompt-block" ref={ref}>{children}</div>;
};

<UseCaseHero title="在合并前自动修复 PR 中的 Bug" description="Devin 会检查每个 PR 是否存在 Bug，并自动将修复推送到对应分支。" category="代码质量" features="集成" type="review" />

<div className="uc-detail-wrapper">
  <Tip>不想手动设置？将此页面的链接粘贴到一个 Devin 会话中，并让它为你完成全部设置。</Tip>

  <Steps>
    <Step title="为自动审查加入代码仓库和用户">
      Devin Review 可以自动审查你代码仓库中的每一个 PR —— 无需手动触发。先将你希望覆盖的代码仓库和用户加入自动审查。

      1. 在 Devin Web 应用中前往 [Settings > Review](https://app.devin.ai/settings/review?utm_source=docs\&utm_medium=use-case-gallery)
      2. 在 **Repositories** 下，使用 **Add repo** 搜索并添加你希望由 Devin 自动审查的代码仓库 (例如：`acme/frontend`、`acme/api-server`)
      3. 在 **Users** 下，查看哪些用户已加入 —— 每位用户都通过设置自己的个人审查触发方式来自行加入

      加入后，当 PR 被打开、推送了新的提交，或草稿被标记为准备审查时，Devin 会自动进行审查。

      <Tip>
        任何已连接 GitHub 账号的团队成员都可以自行加入自动审查 —— 无需管理员权限。前往 [Settings > Preferences](https://app.devin.ai/settings/preferences?utm_source=docs\&utm_medium=use-case-gallery) 并在 **Devin Review** 下设置你的 **Review trigger**。
      </Tip>
    </Step>

    <Step title="启用自动修复，让 Devin 不只评论还能直接推送修复">
      默认情况下，[Devin Review](/zh/work-with-devin/devin-review) 会将缺陷发现作为行内评论发布。自动修复更进一步 —— Devin 会提出代码修改方案，并可直接将修复提交推送到 PR 分支。

      要启用它，请前往 **Settings > Customization > Pull requests > Responding to bots** 并选择以下其中一项：

      * **Selected only** —— 将 `devin-ai-integration[bot]` 添加到允许列表 allowlist (推荐)
      * **All bots** —— Devin 会对所有 bot 评论作出响应，而不仅是它自己的评论

      你也可以在任何由 Devin 创建的 PR 上，从审查侧边栏的 **自动修复** 部分启用自动修复 (仅限组织管理员)。

      <Warning>
        当其他 bot 也会对 Devin 的更改发表评论时，"All bots" 可能导致无限循环。请使用 **Selected only** 模式，只添加 `devin-ai-integration[bot]` 以确保安全。
      </Warning>
    </Step>

    <Step title="查看 Devin 发现并修复了哪些问题">
      当在已加入的仓库上打开 PR 时，Devin Review 会自动运行并生成：

      * 在 Analysis 侧边栏中的**缺陷发现**，按严重程度 (Severe 或 Non-severe) 和置信度标记
      * **Flags**，用于标记值得进一步排查但不一定有误的模式
      * 当开启自动修复时，针对 Devin 能解决的问题，直接推送到 PR 分支的**修复提交**

      例如，在一个添加新用户设置页面的 PR 上，Devin Review 可能会发现：

      ```
      Bug (Severe): Null reference in UserSettings.tsx:38

      `user.preferences.theme` throws if `preferences` is undefined,
      which happens for accounts created before v2.3.

      Fix pushed — commit e4a1b2c:
        const theme = user.preferences?.theme ?? 'system';
      ```

      你可以在 diff 视图中审查每一条发现，将缺陷标记为已解决，或使用内置的[代码库感知型聊天](/zh/work-with-devin/devin-review)提出后续问题 —— Devin 拥有整个仓库的上下文，而不仅仅是 diff。
    </Step>

    <Step title="让 Devin Review 学习你团队的标准">
      Devin Review 会读取仓库中的 `AGENTS.md` 和 `REVIEW.md` 文件来学习你团队的约定。使用这些文件来定义审查偏好、需要重点关注的常见缺陷模式，以及你希望强制执行的编码规范：

      ```markdown theme={null}
      <!-- REVIEW.md -->
      ## Review guidelines

      - All API route handlers in src/routes/* must validate request body
        with zod schemas before accessing properties. Flag any handler
        that reads req.body fields without validation.
      - The useUnsafeEffect hook in src/hooks/useUnsafeEffect.ts is
        intentional — do not flag it as a missing-deps issue.
      - Check for unhandled error cases in API calls.
      - Ensure new database queries have appropriate indexes.
      ```

      将此文件提交到你的仓库后，Devin Review 会在每个 PR 上遵循这些指南。随着团队发现新的模式，可以随时更新它 —— 例如，在一次生产故障后，将本可以捕获该问题的模式添加进去，以便 Devin 在后续审查中标记类似问题。

      你也可以在任意 PR 上使用 [Review chat](/zh/work-with-devin/devin-review)，让 Devin 在整个 diff 中检查特定模式 —— 例如，“Are there any API calls in this PR that don't handle the error case?”。
    </Step>
  </Steps>
</div>
