> ## 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.

# 通过 Linear 自动分级 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="通过 Linear 自动分诊 Bug" description="一旦在 Linear 中打上标签，Devin 就会自动对 Bug 进行调查。" prompt="阅读此 Linear 工单中的缺陷报告。在代码库中搜索相关代码路径，并定位根本原因。" category="项目管理" features="集成, 操作手册" devinUrl="https://app.devin.ai/settings/connections/linear" />

<div className="uc-detail-wrapper">
  <Tip>不想手动完成这些设置？将本页链接粘贴到 Devin 会话中，让它帮你完成所有配置。</Tip>

  <Steps>
    <Step title="编写分诊手册">
      自动化需要一个 playbook，来告诉 Devin 你的团队是*如何*对 bug 进行分诊的——不仅仅是“修复 bug”，而是工程师实际会遵循的具体步骤。

      先复制 `!triage` [模板 playbook](https://app.devin.ai/settings/playbooks/14fed18b89d44713a26e673cf258f548?utm_source=docs\&utm_medium=use-case-gallery)，并根据你的技术栈进行自定义。或者前往 [**Settings > Playbooks**](https://app.devin.ai/settings/playbooks?utm_source=docs\&utm_medium=use-case-gallery)，使用宏 `!triage-bug` 创建一个新的 playbook。下面是一个示例：

      <PromptBlock type="playbook">
        ```txt Triage playbook example theme={null}
        阅读这个 Linear 工单中的 bug 报告。然后：

        1. 在代码库中搜索报告中提到的相关代码路径
        2. 查看 git log，检查这些文件最近的变更
        3. 找出根本原因并总结你的结论：根本原因、受影响的文件、
           可能导致问题的近期改动，以及一个建议的修复思路
        ```
      </PromptBlock>

      你的 playbook 越具体，Devin 的分诊效果就越好。参考你团队的实际做法——错误日志规范、测试框架、分支命名规则。有关如何编写高效 playbook 的更多信息，请参阅 [playbook 文档](/zh/product-guides/creating-playbooks)，或者让 Devin 为你生成一个 playbook。

      <Tip>连接 [Datadog MCP](/zh/work-with-devin/mcp#datadog) (或其他日志/监控服务) ，并为 Devin 提供数据库只读访问权限，以便它在排查过程中检查日志、指标和查询数据。</Tip>
    </Step>

    <Step title="设置自动化触发器">
      现在将该 playbook 连接到 Linear，这样在 bug 被加上标签时就会自动触发。

      1. 前往 [**Settings > Connections > Linear**](https://app.devin.ai/settings/connections/linear?utm_source=docs\&utm_medium=use-case-gallery) (如果尚未连接该集成，请先完成连接 — 参见[设置指南](/zh/integrations/linear))
      2. 在 **Synced playbook labels** 下，点击 **Add playbook** 并选择 `!triage-bug` —— 这会在 Linear 的 **"Devin Playbooks"** 标签组中创建一个对应的标签
      3. 向下滚动到 **Automation triggers** 并点击 **Add trigger**：
         * **Teams**：选择提交 bug 的团队 (例如 "Engineering")
         * **Labels**：选择 `Bug` (或你的团队用于缺陷报告的标签)
         * **Playbook**：选择 `!triage-bug`
      4. 保存该触发器

      触发器使用 **edge detection** —— 它们只会在工单*转换为*匹配状态时触发 (例如，当有人新增 `Bug` 标签时) ，而不会对已经具有该标签的工单触发。这样就不会不小心在你现有的整个 backlog 上触发 Devin。

      <Note>要让 playbook 标签自动同步到 Linear，你的 Linear workspace 必须将 **Manage workspace labels** 设置为 **All members** (位于 Linear 的 **Settings > Security** 中) 。如果未启用该设置，你需要在 Linear 中手动创建这些标签。</Note>
    </Step>

    <Step title="给 bug 打上标签，看看 Devin 如何排查">
      当一名工程师像这样在 Linear 工单上添加 `Bug` 标签时：

      > **ENG-487**：用户在 /contact 页面上提交联系表单时看到 500 错误。问题从上周五的部署之后开始出现。堆栈跟踪指向 `src/lib/forms.ts` 中的 `validateEmail()`。

      Devin 会自动启动一次会话，并按照你的分诊 playbook 行动：

      * **阅读工单** —— 从 Linear 中拉取标题、描述和所有评论
      * **搜索代码库** —— 找到 `src/lib/forms.ts`、`src/routes/contact.ts` 中的路由处理器，以及表单校验测试
      * **检查最近变更** —— 运行 `git log --since="last Friday" -- src/lib/forms.ts`，发现一个重构邮箱正则的提交

      Devin 的分析结果会通过集成自动同步回 Linear 工单。整个过程无需任何人将工单指派给 Devin——仅凭这个标签就能触发完整的工作流。

      <Tip>安装 Linear 集成后，Devin 原生就能访问 Linear 的工具——因此你的 playbook 可以指示 Devin 根据调查结果更新工单标签。比如，你的分诊 playbook 可以让 Devin 根据结论添加 `Clear Fix`、`Needs Review` 或 `Lacking Context` 等标签。由于标签可以触发其他自动化流程，你可以将多个工作流串联起来——例如，一个 `Clear Fix` 标签可以启动第二个 Devin 会话来编写修复代码。</Tip>
    </Step>

    <Step title="优化闭环">
      在进行了几轮分诊之后，根据 Devin 做得好的部分以及仍然需要更多指引的地方来优化这一流程。

      **基于真实会话改进 playbook。** 如果 Devin 总是漏掉某些步骤 (例如不检查日志或遗漏相关服务) ，就把这一步添加到你的 `!triage-bug` playbook 中。你可以让 Devin 分析过去的会话，自动改进你的 playbook，或者为 Devin 在所有会话中都应该遵循的模式创建 [Knowledge](/zh/product-guides/knowledge) 条目——比如「always check the error tracking dashboard first」或「our auth service logs are in CloudWatch, not Datadog.」。

      **在准备好时添加修复 playbook。** 一旦你信任 Devin 的分诊结果，创建第二个类似 `!fix-bug` 的 playbook，进一步推进流程——编写修复、添加回归测试并创建一个 PR。把它关联到单独的标签，这样你的团队就可以在「just tell me what's wrong」和「fix it for me」之间进行选择：

      <PromptBlock type="playbook">
        ```txt Fix playbook 示例 theme={null}
        阅读这个 Linear 工单中的 bug 报告。然后：

        1. 在代码库中搜索报告中提到的相关代码路径
        2. 检查这些文件的 git log，关注最近的变更
        3. 找出根本原因
        4. 编写一个针对根本原因的修复
        5. 添加一个本应能捕获该 bug 的回归测试
        6. 运行现有测试套件，确保没有引入其他问题
        7. 创建一个与该 Linear 工单关联的 PR —— 在 PR 描述中包含
           "Fixes ENG-XXX"
        ```
      </PromptBlock>
    </Step>
  </Steps>
</div>
