有多种方式可以自定义 Dependabot 拉取请求,使其更符合您内部的流程。
例如,为了将 Dependabot 的拉取请求集成到您的 CI/CD 流水线中,它可以对拉取请求应用 自定义标签,随后您可以使用这些标签来触发动作工作流。
有多种不同的自定义选项,可组合使用,并可针对每个软件包生态系统进行定制。
自动添加受理人
默认情况下,Dependabot 会创建没有受理人的拉取请求。
要自动将拉取请求分配给指定的安全团队,可使用 assignees 为每个软件包生态系统设置这些值。
下面的示例 dependabot.yml 文件更改了 npm 的配置,使所有针对 npm 的版本和安全更新所打开的拉取请求
- 自动分配给个人("
user-name")的拉取请求。
# `dependabot.yml` file with
# assignee for all npm pull requests
version: 2
updates:
# Keep npm dependencies up to date
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
# Raise all npm pull requests with assignees
assignees:
- "user-name"
# `dependabot.yml` file with
# assignee for all npm pull requests
version: 2
updates:
# Keep npm dependencies up to date
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
# Raise all npm pull requests with assignees
assignees:
- "user-name"
自动添加审阅者
默认情况下,Dependabot 会创建没有审阅者的拉取请求。
为确保项目的安全更新能够及时得到相应团队的处理,您可以通过 CODEOWNERS 文件自动为 Dependabot 拉取请求添加审阅者。参见 关于代码所有者。
使用自定义标签标记拉取请求
默认情况下,Dependabot 会为拉取请求打上 dependencies 标签。
Dependabot 还会对拉取请求应用生态系统标签,例如 java、npm 或 github-actions。Dependabot 会为所有拉取请求(包括单一生态系统更新)同时添加 dependencies 标签和生态系统标签,以提升过滤和分流的效率。
Dependabot 会在仓库中不存在时创建其默认的拉取请求标签。如果您想使用自定义标签而非默认标签,可在 dependabot.yml 文件中为每个软件包生态系统设置 labels 选项;这将覆盖默认设置。更多信息,请参见 管理标签 和 labels。
如果仓库中存在语义化版本(SemVer)标签,Dependabot 也会自动应用这些标签,以指示版本更新的类型(major、minor 或 patch)。这些标签会在您自定义的标签之外额外添加。
您可以使用 labels 来覆盖默认标签,并为每个软件包生态系统指定自己的自定义标签。如果例如您想要
- 使用标签为特定拉取请求分配优先级。
- 使用标签触发其他工作流,如自动将拉取请求添加到项目看板。
下面的示例 dependabot.yml 文件更改了 npm 的配置,使所有针对 npm 的版本和安全更新所打开的拉取请求拥有自定义标签。
# `dependabot.yml` file with
# customized npm configuration
version: 2
updates:
# Keep npm dependencies up to date
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
# Raise all npm pull requests with custom labels
labels:
- "npm dependencies"
- "triage-board"
# `dependabot.yml` file with
# customized npm configuration
version: 2
updates:
# Keep npm dependencies up to date
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
# Raise all npm pull requests with custom labels
labels:
- "npm dependencies"
- "triage-board"
设置此选项还会影响对该包管理器的清单文件的安全更新拉取请求,除非您使用 target-branch 在非默认分支上检查版本更新。
另见 labels。
为提交信息添加前缀
默认情况下,Dependabot 会尝试检测您的提交信息偏好并使用相似的模式。此外,Dependabot 会根据提交信息为拉取请求生成标题。
您可以为特定软件包生态系统的 Dependabot 提交信息(以及拉取请求标题)指定自己的前缀。如果例如您运行的自动化会处理提交信息或拉取请求标题,这会非常有用。
要显式指定您的偏好,请使用 commit-message 并结合以下受支持的选项
prefix:- 为所有提交信息指定前缀。
- 该前缀也会被添加到拉取请求标题的开头。
prefix-development:- 为所有更新开发依赖的提交信息指定单独的前缀,开发依赖由包管理器或生态系统定义。
- 支持
bundler、composer、mix、maven、npm与pip。
include: "scope":- 指定在任何前缀之后追加提交中更新的依赖类型(
deps或deps-dev)。
- 指定在任何前缀之后追加提交中更新的依赖类型(
以下示例展示了针对不同软件包生态系统的多种选项
# Customize commit messages
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
commit-message:
# Prefix all commit messages with "npm: "
prefix: "npm"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
commit-message:
# Prefix all commit messages with "[docker] " (no colon, but a trailing whitespace)
prefix: "[docker] "
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "weekly"
# Prefix all commit messages with "Composer" plus its scope, that is, a
# list of updated dependencies
commit-message:
prefix: "Composer"
include: "scope"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
# Include a list of updated dependencies
# with a prefix determined by the dependency group
commit-message:
prefix: "pip prod"
prefix-development: "pip dev"
# Customize commit messages
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
commit-message:
# Prefix all commit messages with "npm: "
prefix: "npm"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
commit-message:
# Prefix all commit messages with "[docker] " (no colon, but a trailing whitespace)
prefix: "[docker] "
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "weekly"
# Prefix all commit messages with "Composer" plus its scope, that is, a
# list of updated dependencies
commit-message:
prefix: "Composer"
include: "scope"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
# Include a list of updated dependencies
# with a prefix determined by the dependency group
commit-message:
prefix: "pip prod"
prefix-development: "pip dev"
设置此选项还会影响对该包管理器的清单文件的安全更新拉取请求,除非您使用 target-branch 在非默认分支上检查版本更新。
另见 commit-message。
将拉取请求关联到里程碑
里程碑可以帮助您跟踪一组拉取请求(或议题)相对于项目目标或发布的进度。使用 Dependabot 时,您可以通过 milestone 选项将依赖更新的拉取请求关联到特定里程碑。
必须使用里程碑的数字标识符,而不是其标签。要查找数字标识符,请查看页面 URL 中 milestone 之后的部分。例如,对于 https://github.com/<org>/<repo>/milestone/3,"3" 即为里程碑的数字标识符。
# Specify a milestone for pull requests
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
# Associate pull requests with milestone "4"
milestone: 4
# Specify a milestone for pull requests
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
# Associate pull requests with milestone "4"
milestone: 4
设置此选项还会影响对该包管理器的清单文件的安全更新拉取请求,除非您使用 target-branch 在非默认分支上检查版本更新。
更改拉取请求分支名称中的分隔符
Dependabot 为每个拉取请求生成一个分支。分支名称包含 dependabot、包管理器名称以及要更新的依赖项。默认情况下,这些部分之间使用 / 符号分隔,例如
dependabot/npm_and_yarn/next_js/acorn-6.4.1
为保持可维护性或与现有流程的一致性,您可能需要确保分支名称符合团队的命名约定。在这种情况下,您可以使用 pull-request-branch-name.separator 指定不同的分隔符,可选 _、/ 或 "-"。
下面的示例将 npm 配置中的默认分隔符从 / 改为 "-",因此显示为:
- 默认 (
/):dependabot/npm_and_yarn/next_js/acorn-6.4.1 - 自定义 (
"-"):dependabot-npm_and_yarn-next_js-acorn-6.4.1
请注意,连字符 ("-") 必须用引号包裹,以免被解析为 YAML 空列表的起始符号。
# Specify a different separator for branch names
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
pull-request-branch-name:
# Change the default separator (/) to a hyphen (-)
separator: "-"
# Specify a different separator for branch names
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
pull-request-branch-name:
# Change the default separator (/) to a hyphen (-)
separator: "-"
设置此选项还会影响对该包管理器的清单文件的安全更新拉取请求,除非您使用 target-branch 在非默认分支上检查版本更新。
另见 pull-request-branch-name.separator。
针对非默认分支的拉取请求
默认情况下,Dependabot 会在默认分支上检查清单文件,并针对默认分支创建更新的拉取请求。
通常情况下,最好将 Dependabot 的检查和更新保持在默认分支上。但在某些情况下,您可能需要指定其他目标分支。例如,如果团队流程要求先在非生产分支上测试和验证更新,则可以使用 target-branch 指定 Dependabot 提交拉取请求的目标分支。
注意
Dependabot 仅会对默认分支的安全更新创建拉取请求。如果使用 target-branch,则该包管理器的所有配置设置将仅适用于版本更新,而不再适用于安全更新。
# Specify a non-default branch for pull requests for pip
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
# Raise pull requests for version updates
# to pip against the `develop` branch
target-branch: "develop"
# Labels on pull requests for version updates only
labels:
- "pip dependencies"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
# Check for npm updates on Sundays
day: "sunday"
# Labels on pull requests for security and version updates
labels:
- "npm dependencies"
# Specify a non-default branch for pull requests for pip
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
# Raise pull requests for version updates
# to pip against the `develop` branch
target-branch: "develop"
# Labels on pull requests for version updates only
labels:
- "pip dependencies"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
# Check for npm updates on Sundays
day: "sunday"
# Labels on pull requests for security and version updates
labels:
- "npm dependencies"
另见 target-branch。