About using rulesets for code scanning merge protection
メモ
- Merge protection with rulesets is not related to status checks. For more information about status checks, see ステータスチェックについて.
- Merge protection with rulesets will not apply to merge queue groups or Dependabot pull requests analyzed by default setup.
- All the lines of code identified by an alert must exist in the pull request diff. For more information, see Code scanningの SARIF サポート.
You can use rulesets to prevent pull requests from being merged when one of the following conditions is met:
- 必要なツールで、ルール セットで定義している重大度の code scanning アラートが見つかりました。
- 必要な code scanning ツールはまだ分析中です。
- 必要な code scanning ツールはリポジトリ用に構成されていません。
Typically you should use rulesets target long-lived feature branches, where you would like to guarantee that code has been analyzed before pull requests can be merged.
Configuring a code scanning rule will not automatically enable code scanning. For more information about how to enable code scanning, see Configuring default setup for code scanning.
For more information about code scanning alerts, see Code scanningアラートについて.
You can set merge protection with rulesets at the repository level, and for repositories configured with either default setup or advanced setup. You can also use the REST API to set merge protection with rulesets.
For more information about rulesets, see ルールセットについて.
Creating a merge protection ruleset for a repository
-
GitHub で、リポジトリのメイン ページに移動します。
-
リポジトリ名の下にある [Settings] をクリックします。 [設定] タブが表示されない場合は、 [] ドロップダウン メニューを選び、 [設定] をクリックします。
![タブを示すリポジトリ ヘッダーのスクリーンショット。 [設定] タブが濃いオレンジ色の枠線で強調表示されています。](/assets/cb-28260/images/help/repository/repo-actions-settings.png)
-
左側のサイド バーの [コードと自動化] の下で、 [ルール] をクリックし、 [ルールセット] をクリックします。
![リポジトリの [設定] ページのサイド バーのスクリーンショット。 [ルール] サブメニューが展開され、[ルールセット] オプションの枠線がオレンジ色で表示されています。](/assets/cb-80504/images/help/repository/rulesets-settings.png)
-
Click New ruleset.
-
To create a ruleset targeting branches, click New branch ruleset.
-
[ルールセット名] に、ルールセットの名前を入力します。
-
必要に応じて、既定の適用状態を変更するには、 [Disabled] をクリックして、新しい適用状態を選びます。
-
[ブランチ保護] で、[Require code scanning results] を選択します。
-
[Required tools and alert thresholds] の [Add tool] をクリックして、ドロップダウンで code scanning ツールを選びます。 たとえば、"CodeQL"。
-
code scanning ツールの名前の隣
- [アラート] をクリックし、[なし]、[エラー]、[エラーと警告]、または [すべて] のいずれかを選択します。
- [セキュリティ アラート] をクリックし、[なし]、[重大]、[高以上]、[中以上]、または [すべて] のいずれかを選択します。
![[ルールセット] 設定の [必要なツールとアラートのしきい値] セクションのスクリーンショット。](/assets/cb-42772/images/help/repository/rulesets-require-code-scanning.png)
アラートの重大度とセキュリティの重大度レベルの詳細については、「Code scanningアラートについて」を参照してください。
For more information about managing rulesets in a repository, 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 エンドポイント.