セキュリティ更新プログラム用に pull request をカスタマイズする
プロジェクトのセキュリティの優先順位とプロセスにとって最適になるように、Dependabot からセキュリティ更新プログラムの pull request を生成する方法をカスタマイズできます。 次に例を示します。
- Dependabot の pull request を最適化し、重要な更新プログラムを優先するには、複数の更新プログラムを 1 つの pull request にグループ化します。
- カスタム ラベルを適用して、Dependabot の pull request を既存のワークフローに統合します。
バージョン更新プログラムと同様に、セキュリティ更新プログラム用のカスタマイズ オプションは dependabot.yml ファイルで定義します。 dependabot.yml をバージョン更新プログラム用に既にカスタマイズしている場合、定義済み構成オプションの多くがセキュリティ更新プログラムにも自動的に適用されます。 ただし、注意すべき重要な点がいくつかあります。
- Dependabot security updates は、バージョン更新プログラム用の dependabot.ymlで設定したscheduleに従って実行されるのではなく、常にセキュリティ アドバイザリによってトリガーされます。
- Dependabot により、既定のブランチのみに対してセキュリティ更新プログラム用の pull request が生成されます。 構成で target-branchの値を設定している場合、そのパッケージ エコシステムのカスタマイズは、既定でバージョン更新プログラムにのみ適用されます。
リポジトリの dependabot.yml ファイルをまだ構成しておらず、セキュリティ更新プログラム用の pull request をカスタマイズする場合は、まず次のことを行う必要があります。
- dependabot.ymlファイルをリポジトリの- .githubディレクトリにチェックインします。 詳しくは、「Dependabot のバージョン アップデートの設定」をご覧ください。
- 必要なキーをすべて設定します。 詳細については、「必須のキー」を参照してください。
- パッケージ エコシステムのカスタマイズをセキュリティ更新プログラムにのみ適用する (バージョン更新プログラムを除外する) 場合は、open-pull-requests-limitキーを0に設定します。
その後、セキュリティ更新プログラムのニーズと優先順位を検討し、以下で説明するカスタマイズ オプションの組み合わせを適用できます。
重要な更新プログラムを優先する
重要なプログラムを優先する、より対象を絞ったレビュー プロセスを作成するには、groups を使って複数の依存関係のセキュリティ更新プログラムを 1 つの pull request に結合します。
詳細なガイダンスについては、「重要なプログラムを優先する」を参照してください。
担当者の自動追加
assignees を使って、個人またはチームを pull request の割り当て先として自動的に追加します。
詳細なガイダンスについては、「レビュー担当者の自動追加」を参照してください。
レビュー担当者の自動追加
プロジェクトのセキュリティ更新プログラムが適切なチームによって速やかに対処されるように、CODEOWNERS ファイルを使って、Dependabot pull request にレビュー担当者を自動的に追加できます。 「コードオーナーについて」を参照してください。
カスタム ラベルを使って pull request にラベルを付ける
特定の pull request に優先する、またはそれらを CI/CD パイプラインに統合するには、labels を使って独自のカスタム ラベルを各 pull request に適用します。
詳細なガイダンスについては、「カスタム ラベルを使って pull request にラベルを付ける」を参照してください。
コミット メッセージにプレフィックスを追加する
コミット メッセージや pull request のタイトルを処理する自動化と統合するには、commit-message を使ってコミット メッセージと pull request のタイトルに必要なプレフィックスを指定します。
詳細なガイダンスについては、「コミット メッセージにプレフィックスを追加する」を参照してください。
Pull request とマイルストーンを関連付ける
プロジェクトの目標またはリリースに向けて進行状況を追跡するには、milestone を使って Dependabot の pull request をマイルストーンに関連付けます。
詳細なガイダンスについては、「pull request をマイルストーンに関連付ける」を参照してください。
Pull request ブランチ名の区切り記号を変更する
チームの既存の規約にブランチ名を合わせるには、pull-request-branch-name.separator を使って、Dependabot がブランチ名に使う区切り記号を指定します。
詳細なガイダンスについては、「pull request ブランチ名の区切り記号を変更する」を参照してください。
例 1: セキュリティ更新プログラムのみの構成
この例では、dependabot.yml ファイルは次のようになります。
- npm 依存関係の更新にはプライベート レジストリを使います。
- 依存関係のバージョン更新プログラムを無効にして、カスタマイズがセキュリティ更新プログラムにのみ適用されるようにします。
- Dependabot がカスタム ラベルを pull request に適用し、担当者を自動的に追加するようにカスタマイズされています。
- Golang 依存関係のセキュリティ更新プログラムを、1 つの pull request にグループ化します。
# 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 がバージョン更新プログラムとセキュリティ更新プログラムの両方にカスタム ラベルを追加するようにカスタマイズされています。
- 複数の更新プログラムを 1 つの pull request にグループ化するために、groupsカスタマイズ オプションを使って 2 つのグループ ("angular" と "production-dependencies") を作成します。
- angularの- groupsカスタマイズがセキュリティ更新プログラムのみに適用されるように指定します。
- production-dependenciesの- groupsカスタマイズをバージョン更新プログラムのみに適用することを指定します。
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"