跳至主要内容

为 Dependabot 安全更新定制拉取请求

了解如何为安全更新定制 Dependabot 拉取请求,以符合您项目的安全优先级和工作流程。

谁可以使用此功能?

具有 写入 访问权限的用户

准备定制拉取请求

如果您尚未为仓库配置 dependabot.yml 文件,并且希望为安全更新定制拉取请求,则必须先

  1. dependabot.yml 文件提交到仓库的 .github 目录中。更多信息,请参见 Configuring Dependabot version updates
  2. 设置所有必需的键。更多信息,请参见 Required keys
  3. 如果您希望对某个软件包生态系统的定制仅适用于安全更新(并排除版本更新),请将 open-pull-requests-limit 键设为 0

之后,您可以根据安全更新的需求与优先级,结合以下列出的定制选项使用。

优先考虑有意义的更新

要创建更有针对性的审查流程并优先处理有意义的更新,可使用 groups 将多个依赖的安全更新合并为单个拉取请求。

详细指南请参见 Prioritizing meaningful updates

自动添加受理人

使用 assignees 可自动将个人或团队添加为拉取请求的受理人。

详细指南请参见 Automatically adding assignees

自动添加审阅人

为确保项目的安全更新能够及时由相应团队处理,您可以使用 CODEOWNERS 文件自动为 Dependabot 拉取请求添加审阅人。参见 About code owners

使用自定义标签标记拉取请求

优先处理特定的拉取请求,或将其集成到 CI/CD 流水线中,请使用 labels 为每个拉取请求应用您自己的自定义标签

详细指南请参见 Labeling pull requests with custom labels

为提交信息添加前缀

集成处理提交信息或拉取请求标题的自动化工具,请使用 commit-message 指定您希望的提交信息和拉取请求标题前缀。

详细指南请参见 Adding a prefix to commit messages

将拉取请求关联到里程碑

跟踪进度以实现项目目标或发布,请使用 milestone 将 Dependabot 的拉取请求关联到里程碑。

详细指南请参见 Associating pull requests with a milestone

更改拉取请求分支名称中的分隔符

为确保您的分支名称与团队已有约定保持一致,请使用 pull-request-branch-name.separator 指定 Dependabot 在分支名称中使用的分隔符。

详细指南请参见 Changing the separator in the pull request branch name

示例 1:仅针对安全更新的配置

在此示例中,dependabot.yml 文件

  • 使用私有注册表来更新 npm 依赖。
  • 禁用依赖的版本更新,以便所有定制仅适用于安全更新。
  • 已定制,使 Dependabot 为拉取请求添加自定义标签并自动添加受理人。
  • 将 golang 依赖的安全更新合并为单个拉取请求。
YAML
# Example configuration file that:
#  - Uses a private registry for npm updates
#  - Ignores lodash dependency
#  - Disables version-updates
#  - Applies custom labels
#  - Adds assignees
#  - Group security updates for golang dependencies into a single pull request

version: 2
registries:
  # Define a private npm registry with the name `example`
  example:
    type: npm-registry
    url: https://example.com
    token: ${{secrets.NPM_TOKEN}}
updates:
  - package-ecosystem: "npm"
    directory: "/src/npm-project"
    schedule:
      interval: "daily"
    # For Lodash, ignore all updates
    ignore:
      - dependency-name: "lodash"
    # Disable version updates for npm dependencies
    open-pull-requests-limit: 0
    registries:
      # Ask Dependabot to use the private registry for npm
      - example
    # Raise all npm pull requests for security updates with custom labels
    labels:
      - "npm dependencies"
      - "triage-board"
    # Raise all npm pull requests for security updates with assignees
    assignees:
      - "user-name"
  - package-ecosystem: "gomod"
    directories:
      - "**/*"
    schedule:
      interval: "weekly"
    open-pull-requests-limit: 0
    groups:
      # Group security updates for golang dependencies
      # into a single pull request
      golang:
        applies-to: security-updates
        patterns:
          - "golang.org*"

示例 2:版本更新和安全更新的配置

在此示例中,dependabot.yml 文件

  • 已定制,使 Dependabot 为版本更新和安全更新均添加自定义标签。
  • 使用 groups 定制选项创建两个分组(“angular” 和 “production‑dependencies”),以便将多个更新合并为单个拉取请求。
  • 指定 groupsangular 的定制仅适用于安全更新。
  • 指定 groupsproduction‑dependencies 的定制仅适用于版本更新。
YAML
version: 2
updates:
  # Keep npm dependencies up to date
  - package-ecosystem: "npm"
    directory: "/"
    schedule:
      interval: "weekly"
# Raise all npm pull requests for security and version updates with custom labels
    labels:
      - "npm dependencies"
      - "triage-board"
    groups:
      angular:
        # Group security updates for Angular dependencies into a single pull request
        applies-to: security-updates
        patterns:
          - "@angular*"
      production-dependencies:
        # Group version updates for dependencies of type "production" into a single pull request
        applies-to: version-updates
        dependency-type: "production"

延伸阅读

© . This site is unofficial and not affiliated with GitHub, Inc.