{"meta":{"title":"自定义 Dependabot 拉取请求以适应你的流程","intro":"了解如何定制你的 Dependabot 拉取请求以更好地适应你自己的内部工作流。","product":"安全性和代码质量","breadcrumbs":[{"href":"/zh/code-security","title":"安全性和代码质量"},{"href":"/zh/code-security/tutorials","title":"Tutorials"},{"href":"/zh/code-security/tutorials/secure-your-dependencies","title":"保护依赖项"},{"href":"/zh/code-security/tutorials/secure-your-dependencies/customizing-dependabot-prs","title":"自定义 Dependabot 拉取请求"}],"documentType":"article"},"body":"# 自定义 Dependabot 拉取请求以适应你的流程\n\n了解如何定制你的 Dependabot 拉取请求以更好地适应你自己的内部工作流。\n\n可通过多种方式自定义你的 Dependabot 拉取请求，以便它们更好地适应你自己的内部流程。\n\n例如，为了将 Dependabot 的拉取请求集成到 CI/CD 管道中，它可以将自定义标签应用于拉取请求，你随后可以使用拉取请求来触发操作工作流。\\*\\*\\*\\*\n\n可以组合使用几种不同的自定义选项，并根据包生态系统进行定制。\n\n## 自动添加被分派人\n\n默认情况下，Dependabot 会提出没有任何被分派人的拉取请求。\n\n若要自动将拉取请求分配给指定的安全团队，可以使用 `assignees` 为每个包生态系统设置这些值。\n\n下面的示例 `dependabot.yml` 文件更改了 npm 配置，使所有因版本更新和安全更新而打开的拉取请求都具有：\n\n* 被自动分配到拉取请求的个人（“`user-name`”）。\n\n```yaml copy\n# `dependabot.yml` file with\n#  assignee for all npm pull requests\n\nversion: 2\nupdates:\n  # Keep npm dependencies up to date\n  - package-ecosystem: \"npm\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n    # Raise all npm pull requests with assignees\n    assignees:\n      - \"user-name\"\n```\n\n## 自动添加审阅者\n\n默认情况下，Dependabot 会提出没有任何审阅者的拉取请求。\n\n为了确保项目的安全更新得到相应团队的及时处理，可以使用 CODEOWNERS 文件自动将审阅者添加到 Dependabot 拉取请求。 请参阅“[关于代码所有者](/zh/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners)”。\n\n## 使用自定义标签标记拉取请求\n\n默认情况下，Dependabot 会提出带有 `dependencies` 标签的拉取请求。\n\nDependabot 还会为拉取请求应用生态系统标签，例如 `java`、`npm` 或 `github-actions`。 Dependabot 将 `dependencies` 标签和生态系统标签添加到所有拉取请求中，包括单个生态系统更新，以改进筛选和分类的效率。\n\nDependabot 会创建应用于拉取请求的默认标签（如果它们在存储库中不存在）。 如果要使用自定义标签而不是默认值，可以在每个包生态系统的文件中`labels`设置`dependabot.yml`选项;这将替代默认值。 有关详细信息，请参阅 [管理标签](/zh/issues/using-labels-and-milestones-to-track-work/managing-labels) 和 [`labels`](/zh/code-security/dependabot/working-with-dependabot/dependabot-options-reference#labels--)。\n\n如果存储库中存在语义版本 (SemVer) 标签，Dependabot 也会自动应用它们以指示版本更新的类型（`major`、`minor` 或 `patch`）。 除了您定义的任何自定义标签外，还会应用这些标签。\n\n可以使用 `labels` 替代默认标签，并为每个包生态系统指定自己的自定义标签。 例如，如果你想要执行以下操作，这将非常有用：\n\n* 使用标签将优先级分配给某些拉取请求。\n* 使用标签触发另一个工作流，例如自动将拉取请求添加到项目板上。\n\n下面的示例 `dependabot.yml` 文件更改了 npm 配置，使所有针对 npm 的版本和安全更新打开的拉取请求都具有自定义标签。\n\n```yaml copy\n# `dependabot.yml` file with\n# customized npm configuration\n\nversion: 2\nupdates:\n  # Keep npm dependencies up to date\n  - package-ecosystem: \"npm\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n    # Raise all npm pull requests with custom labels\n    labels:\n      - \"npm dependencies\"\n      - \"triage-board\"\n```\n\n数据重用.dependabot.选项影响安全更新 %}\n\n另请参阅[`labels`](/zh/code-security/dependabot/working-with-dependabot/dependabot-options-reference#labels--)。\n\n## 为提交消息添加前缀\n\n默认情况下，Dependabot 会尝试检测您的提交消息首选项并使用类似的模式。 此外，Dependabot 会根据提交消息填充拉取请求的标题。\n\n可以为特定包生态系统的 Dependabot 的提交消息（以及拉取请求标题）指定你自己的前缀。 例如，如果您正在运行处理提交消息或拉取请求标题的自动化程序，这可能会非常有用。\n\n若要显式指定首选项，请将 `commit-message` 与以下受支持的选项一起使用：\n\n* `prefix`:\n  * 指定所有提交消息的前缀。\n  * 前缀也会添加到 pull request 标题的开头。\n* `prefix-development`:\n  * 为更新开发依赖项的所有提交消息指定单独的前缀，由包管理器或生态系统定义。\n  * 支持 `bundler`、`composer`、`mix`、`maven`、`npm` 和 `pip`。\n* `include: \"scope\"`:\n  * 指定任何前缀后面跟随在提交中更新的依赖项类型（`deps` 或 `deps-dev`）。\n\n下面的示例展示了根据包生态系统定制的几个不同的选项：\n\n```yaml copy\n# Customize commit messages\n\nversion: 2\nupdates:\n  - package-ecosystem: \"npm\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n    commit-message:\n      # Prefix all commit messages with \"npm: \"\n      prefix: \"npm\"\n\n  - package-ecosystem: \"docker\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n    commit-message:\n      # Prefix all commit messages with \"[docker] \" (no colon, but a trailing whitespace)\n      prefix: \"[docker] \"\n\n  - package-ecosystem: \"composer\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n    # Prefix all commit messages with \"Composer\" plus its scope, that is, a\n    # list of updated dependencies\n    commit-message:\n      prefix: \"Composer\"\n      include: \"scope\"\n\n  - package-ecosystem: \"pip\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n    # Include a list of updated dependencies\n    # with a prefix determined by the dependency group\n    commit-message:\n      prefix: \"pip prod\"\n      prefix-development: \"pip dev\"\n```\n\n数据重用.dependabot.选项影响安全更新 %}\n\n另请参阅[`commit-message`](/zh/code-security/dependabot/working-with-dependabot/dependabot-options-reference#commit-message--)。\n\n## 将拉取请求与里程碑关联\n\n里程碑可帮助你跟踪拉取请求（或问题）组实现项目目标或发布的进度。 借助 Dependabot，你可以使用 `milestone` 选项将依赖项更新的拉取请求与特定里程碑相关联。\n\n必须指定里程碑的数字标识符，而不是其标签。 若要查找数字标识符，请查看页面 URL 的最后一部分，在 `milestone` 之后。 例如，对于 `https://github.com/<org>/<repo>/milestone/3`，“`3`”即是里程碑的数字标识符。\n\n```yaml copy\n# Specify a milestone for pull requests\n\nversion: 2\nupdates:\n  - package-ecosystem: \"npm\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n    # Associate pull requests with milestone \"4\"\n    milestone: 4\n```\n\n数据重用.dependabot.选项影响安全更新 %}\n\n另请参阅“[`milestone`](/zh/code-security/dependabot/working-with-dependabot/dependabot-options-reference#milestone--)”和“[关于里程碑](/zh/issues/using-labels-and-milestones-to-track-work/about-milestones)”。\n\n## 更改拉取请求分支名称中的分隔符\n\nDependabot 为每个拉取请求生成一个分支。 每个分支名称都包括 `dependabot`，以及要更新的包管理器和依赖项的名称。 默认情况下，分支名称的这些部分由 `/` 符号分隔，例如：\n\n* `dependabot/npm_and_yarn/next_js/acorn-6.4.1`\n\n为了保持可支持性或与你现有流程的一致性，可能需要确保你的分支名称与你团队的现有约定保持一致。 在这种情况下，可以使用 `pull-request-branch-name.separator` 来指定不同的分隔符，选择 `_`、 `/`或 `\"-\"`。\n\n在下面的示例中，npm 配置将默认分隔符从 `/` 更改为 `\"-\"`，以便如下所示：\n\n* 默认 (`/`)：`dependabot/npm_and_yarn/next_js/acorn-6.4.1`\n* 自定义 (`\"-\"`)：`dependabot-npm_and_yarn-next_js-acorn-6.4.1`\n\n请注意，连字符符号 (`\"-\"`) 必须用引号括起来，以免它被解释为启动空 YAML 列表。\n\n```yaml copy\n# Specify a different separator for branch names\n\nversion: 2\nupdates:\n  - package-ecosystem: \"npm\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n    pull-request-branch-name:\n      # Change the default separator (/) to a hyphen (-)\n      separator: \"-\"\n```\n\n数据重用.dependabot.选项影响安全更新 %}\n\n另请参阅[`pull-request-branch-name.separator`](/zh/code-security/dependabot/working-with-dependabot/dependabot-options-reference#pull-request-branch-nameseparator--)。\n\n## 针对非默认分支定向拉取请求\n\n默认情况下，Dependabot 会检查默认分支上的清单文件，并对默认分支提出更新的拉取请求。\n\n通常情况下，保留 Dependabot 针对默认分支的检查和更新是有意义的。 但是，在某些情况下，你可能需要指定不同的目标分支。 例如，如果你的团队流程要求你首先在非生产分支上测试和验证更新，你则可以使用 `target-branch` 来指定不同的分支，让 Dependabot 对其提出拉取请求。\n\n> \\[!NOTE]\n> Dependabot **仅针对默认分支**提出安全更新的拉取请求。 如果使用 `target-branch`，那么该包管理器的所有配置设置将仅适用于版本更新，而不适用于安全更新。\\_\\_\n\n```yaml copy\n# Specify a non-default branch for pull requests for pip\n\nversion: 2\nupdates:\n  - package-ecosystem: \"pip\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n    # Raise pull requests for version updates\n    # to pip against the `develop` branch\n    target-branch: \"develop\"\n    # Labels on pull requests for version updates only\n    labels:\n      - \"pip dependencies\"\n\n  - package-ecosystem: \"npm\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n      # Check for npm updates on Sundays\n      day: \"sunday\"\n    # Labels on pull requests for security and version updates\n    labels:\n      - \"npm dependencies\"\n```\n\n另请参阅[`target-branch`](/zh/code-security/dependabot/working-with-dependabot/dependabot-options-reference#target-branch-)。"}