关于自定义安全更新的拉取请求
你可以自定义 Dependabot 如何提出安全更新的拉取请求,使其最适合项目的安全优先级和流程。 例如:
-
通过将多个更新分组到单个拉取请求中,**优化 Dependabot 拉取请求,优先处理有意义的更新。** - 应用自定义标签,将 Dependabot 的拉取请求集成到现有工作流中。
与版本更新类似,安全更新的自定义选项在 dependabot.yml 文件中定义。 如果已经为版本更新自定义了 dependabot.yml,则你定义的许多配置选项可能也会自动应用于安全更新。 但是,有几个重要事项需要注意:
- Dependabot security updates 始终由安全公告触发,而不是按照你在
schedule中为版本更新设置的dependabot.yml运行。 - Dependabot 仅针对默认分支提出安全更新的拉取请求。 如果你的配置为
target-branch设置了值,则该包生态系统的自定义默认情况下仅适用于版本更新。
如果尚未为存储库配置 dependabot.yml 文件,但想要自定义安全更新的拉取请求,必须首先:
- 将
dependabot.yml文件签入到存储库的.github目录中。 有关详细信息,请参阅“配置 Dependabot 版本更新”。 - 设置所有必需的密钥。 有关更多信息,请参阅必需密钥。
- 如果希望包生态系统的自定义仅适用于安全更新(排除版本更新),请将
open-pull-requests-limit密钥设置为0。
然后,可以考虑安全更新的需求和优先级,并应用下面概述的自定义选项组合。
优先处理有意义的更新
要创建更有针对性的评审流程,优先处理有意义的更新,请使用 groups 将多个依赖项的安全更新合并到单个拉取请求中。
有关详细指导,请参阅优先处理有意义的更新。
自动添加被分派人
使用 assignees 自动将个人或团队作为被分派人添加到拉取请求。
有关详细指南,请参阅自动添加被分派人。
自动添加审阅者
为了确保项目的安全更新得到相应团队的及时处理,请使用 CODEOWNERS 文件自动将审阅者添加为 Dependabot 拉取请求。 请参阅“关于代码所有者”。
使用自定义标签标记拉取请求
要优先处理特定拉取请求或将其集成到 CI/CD 管道中,请使用 labels 为每个拉取请求应用自己的自定义标签。
有关详细指导,请参阅使用自定义标签标记拉取请求。
为提交消息添加前缀
要与处理提交消息或拉取请求标题的自动化工具集成,请使用 commit-message 指定要用于提交消息和拉取请求标题的前缀。
有关详细指导,请参阅为提交消息添加前缀。
将拉取请求与里程碑关联
要跟踪项目目标或版本的进度,请使用 milestone 将 Dependabot 的拉取请求与里程碑关联。
有关详细指导,请参阅将拉取请求与里程碑关联。
更改拉取请求分支名称中的分隔符
要确保分支名称符合团队现有的约定,请使用 pull-request-branch-name.separator 指定希望 Dependabot 用于分支名称的分隔符。
有关详细指导,请参阅更改拉取请求分支名称中的分隔符。
示例 1:仅适用于安全更新的配置
在本示例中,dependabot.yml 文件:
- 使用专用注册表更新 npm 依赖项。
- 禁用依赖项的版本更新,使任何自定义项都仅应用于安全更新。
- 经过自定义,Dependabot 会向拉取请求应用自定义标签,并自动添加 被分派人。
- 将 golang 依赖项的安全更新分组到单个拉取请求中。
# 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"
groups:
# Group security updates for golang dependencies
# into a single pull request
golang:
applies-to: security-updates
patterns:
- "golang.org*"
# 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"
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),以便将多个更新分组到单个拉取请求中。 - 指定
groups的angular自定义项仅应用于安全更新。 - 指定
groups的production-dependencies自定义项仅应用于版本更新。
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"
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"
延伸阅读
-
[AUTOTITLE](/code-security/dependabot/working-with-dependabot/dependabot-options-reference) -
[AUTOTITLE](/code-security/dependabot/working-with-dependabot/configuring-access-to-private-registries-for-dependabot)