可通过多种方式自定义你的 Dependabot 拉取请求,以便它们更好地适应你自己的内部流程。
例如:
- 为了最大限度地提高效率,Dependabot 可以自动将特定个人或团队添加为其针对特定包生态系统的拉取请求的审阅者。****
- 为了将 Dependabot 的拉取请求集成到你的 CI/CD 管道中,它可以将自定义标签应用于拉取请求,你随后可以使用拉取请求来触发操作工作流。****
可以组合使用几种不同的自定义选项,并根据包生态系统进行定制。
自动添加审阅者和被分配者
默认情况下,Dependabot 会提出没有任何审查者或受理人的拉取请求。
但是,你可能希望拉取请求能够由在该包生态系统方面具有专业知识的特定个人或团队进行一致地审查或处理,或者自动分配给指定的安全团队。 在这种情况下,可以使用 reviewers 和 assignees 为每个包生态系统设置这些值。
下面的示例 dependabot.yml 文件更改了 npm 配置,使所有针对 npm 的版本和安全更新打开的拉取请求都具有:
- 自动作为审阅者被添加到拉取请求的团队(“
my-org/team-name”)或个人(“octocat”)。 - 自动分配给拉取请求的个人(“
user-name”)。
# `dependabot.yml` file with
# reviews and an 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 reviewers
reviewers:
- "my-org/team-name"
- "octocat"
# Raise all npm pull requests with assignees
assignees:
- "user-name"
# `dependabot.yml` file with
# reviews and an 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 reviewers
reviewers:
- "my-org/team-name"
- "octocat"
# Raise all npm pull requests with assignees
assignees:
- "user-name"
设置此选项还会影响此包管理器的清单文件安全更新拉取请求,除非使用 target-branch 检查非默认分支上的版本更新。
使用自定义标签标记拉取请求
默认情况下,Dependabot 会提出所有带有 dependencies 标签的拉取请求。
如果定义了多个包管理器,Dependabot 在每个拉取请求上都会包含一个附加标签,用于指示拉取请求更新的语言或生态系统。 例如,为 Gradle 更新添加 java,或为 git 子模块更新添加 submodules。
Dependabot 会创建它应用于拉取请求的默认标签(如果仓库中尚不存在)。 如果要使用自定义标签,则需要自行创建这些标签。 有关详细信息,请参阅“管理标签”。
可以使用 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 检查非默认分支上的版本更新。
另请参阅“milestones”和“关于里程碑”。
更改拉取请求分支名称中的分隔符
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 对其提出拉取请求。
Note
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。