Skip to main content

Set code scanning merge protection

Secure your codebase by blocking pull requests that fail code scanning checks.

この機能を使用できるユーザーについて

管理者 ロールを持つ組織の所有者、セキュリティ マネージャー、および組織メンバー

Code scanning は、次のリポジトリの種類で使用できます。

  • GitHub.com 上のパブリックリポジトリ
  • GitHub Team、GitHub Enterprise Cloud、または GitHub Enterprise Server 上の組織所有リポジトリ。 GitHub Advanced Security が 有効になっています。

Creating a merge protection ruleset for a repository

  1. GitHub で、リポジトリのメイン ページに移動します。

  2. リポジトリ名の下にある [Settings] をクリックします。 [設定] タブが表示されない場合は、 [] ドロップダウン メニューを選び、 [設定] をクリックします。

    タブを示すリポジトリ ヘッダーのスクリーンショット。 [設定] タブが濃いオレンジ色の枠線で強調表示されています。

  3. 左側のサイド バーの [コードと自動化] の下で、 [ルール] をクリックし、 [ルールセット] をクリックします。

    リポジトリの [設定] ページのサイド バーのスクリーンショット。 [ルール] サブメニューが展開され、[ルールセット] オプションの枠線がオレンジ色で表示されています。

  4. Click New ruleset.

  5. To create a ruleset targeting branches, click New branch ruleset.

  6. [ルールセット名] に、ルールセットの名前を入力します。

  7. 必要に応じて、既定の適用状態を変更するには、 [Disabled] をクリックして、新しい適用状態を選びます。

  8. [ブランチ保護] で、[Require code scanning results] を選択します。

  9. [Required tools and alert thresholds] の [Add tool] をクリックして、ドロップダウンで code scanning ツールを選びます。 たとえば、"CodeQL"。

  10. code scanning ツールの名前の隣

    • [アラート] をクリックし、[なし]、[エラー]、[エラーと警告]、または [すべて] のいずれかを選択します。
    • [セキュリティ アラート] をクリックし、[なし]、[重大]、[高以上]、[中以上]、または [すべて] のいずれかを選択します。

    [ルールセット] 設定の [必要なツールとアラートのしきい値] セクションのスクリーンショット。

アラートの重大度とセキュリティの重大度レベルの詳細については、「Code scanningアラートについて」を参照してください。

For more information about managing rulesets in a repository, see リポジトリのルールセットの管理.

Creating a merge protection ruleset for all repositories in an organization

  1. GitHub の右上隅にあるプロフィール画像をクリックしてから、[ Your organizations] をクリックします。

  2. 組織の隣の [設定] をクリックします。

  3. 左側のサイドバーの [Code, planning, and automation] セクションで、[ Repository] をクリックし、[Rulesets] をクリックします。

    組織の設定ページのスクリーンショット。 サイド バーで、[ルールセット] というラベルの付いたリンクがオレンジ色の枠線で囲まれています。

  4. Click New ruleset.

  5. To create a ruleset targeting branches, click New branch ruleset.

  6. [ルールセット名] に、ルールセットの名前を入力します。

  7. 必要に応じて、既定の適用状態を変更するには、 [Disabled] をクリックして、新しい適用状態を選びます。

  8. [ブランチ保護] で、[Require code scanning results] を選択します。

  9. [Required tools and alert thresholds] の [Add tool] をクリックして、ドロップダウンで code scanning ツールを選びます。 たとえば、"CodeQL"。

  10. code scanning ツールの名前の隣

    • [アラート] をクリックし、[なし]、[エラー]、[エラーと警告]、または [すべて] のいずれかを選択します。
    • [セキュリティ アラート] をクリックし、[なし]、[重大]、[高以上]、[中以上]、または [すべて] のいずれかを選択します。

    [ルールセット] 設定の [必要なツールとアラートのしきい値] セクションのスクリーンショット。

アラートの重大度とセキュリティの重大度レベルの詳細については、「Code scanningアラートについて」を参照してください。

For more information about managing rulesets for repositories in an organization, see 組織内のリポジトリのルールセットを管理する.

Creating a merge protection ruleset with the REST API

You can use the REST API to create a ruleset with the code_scanning rule, which allows you to define specific tools and set alert thresholds. For more information, see ルールの REST API エンドポイント.