> For the complete documentation index, see [llms.txt](https://help.aikido.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.aikido.dev/docs/docs-ja/kdo/code-coverage/pr-gating-on-code-coverage.md).

# コードカバレッジのPRゲーティング

アップロードされたテストカバレッジが最小しきい値を下回った場合、GitHubのプルリクエストチェックを失敗させます。

{% hint style="info" %}
カバレッジゲーティングは現在 GitHub で利用できます。GitLab、Bitbucket、Azure DevOps のサポートは近日提供予定です。
{% endhint %}

CI がアップロードするカバレッジレポートが選択した割合を下回ると、GitHub の pull request を失敗にします。Aikido は別のチェックを投稿し、 **Aikido Security: コードカバレッジ**、カバレッジがしきい値を下回ると失敗としてマークします。

これは、次の機能と同じカバレッジアップロードを使用します。 [コードカバレッジ](/docs/docs-ja/kdo/code-coverage.md) ダッシュボード。Aikido が比較する割合は、pull request のコミットに対して、そのレポート内の行数に対するカバー済み行数です。

## 前提条件

これを有効にする前に：

* ご利用中のプランは **Basic**, **Pro**, **Advanced**、または **Enterprise** プランです。
* リポジトリは GitHub リポジトリです [Aikido に接続されている](/docs/docs-ja/kdosukyan/connect-your-source-code.md)で始まり、 [GitHub PR チェック](/docs/docs-ja/pr-torirsugtingu/github-ci-pr-gating-via-aikido-dashboard.md) がインストールされています。
* 少なくとも 1 つのスキャンが **脆弱性スキャン** でそのリポジトリに対して有効になっています（依存関係、SAST、IaC、シークレット、マルウェア、またはライセンス）。Aikido は、カバレッジで pull request を失敗させる前に、これらのスキャンのいずれか 1 つを必要とします。
* pull request ワークフローは、そのコミットのカバレッジを次のものでアップロードします。 [Aikido Code Coverage GitHub Action](https://github.com/AikidoSec/code-coverage-github-action)。そのアップロードによってチェックが完了します。

## しきい値を設定

1. 次を開きます： [GitHub PR チェック](https://app.aikido.dev/settings/integrations/github/checks).
2. リポジトリを選択して次を開きます **構成を管理**.
3. 次の場所で **コード品質スキャン**を有効にし、 **コードカバレッジのチェックを失敗にする**.
4. 次の項目を設定します： **必要最小テストカバレッジ** を 1 から 100 の整数で指定します。初期値は 50 です。
5. 保存。

カバレッジゲートは次の項目とは独立しています。 **PR でコード品質スキャンを実行** と **未解決コメントがある場合にチェックを失敗にする**。コード品質コメントを投稿せずに、カバレッジのみで pull request を失敗にできます。

<div data-with-frame="true"><figure><img src="https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-3a073360fa10dd2445552fb6fe916ed880ec5644%2Fcode-coverage-pr-gating.jpg?alt=media" alt="Code Quality Scanning settings with Fail check for Code Coverage enabled and a 50% minimum."><figcaption><p>カバレッジチェックを有効にし、リポジトリの最小割合を設定します。</p></figcaption></figure></div>

{% hint style="info" %}
もし **アクション** → **詳細設定** → **PRチェックを常に成功にする** がオンの場合、カバレッジがしきい値を下回っていても、このチェックは合格します。
{% endhint %}

## チェックの仕組み

各 pull request ごとに、Aikido は **Aikido Security: コードカバレッジ** を開き、そのコミットのカバレッジアップロードを待ちます。

| 結果     | 次の場合                                                                                             |
| ------ | ------------------------------------------------------------------------------------------------ |
| **成功** | アップロードされたカバレッジがしきい値以上です。チェックの概要には割合としきい値が表示されます。                                                 |
| **失敗** | アップロードされたカバレッジがしきい値を下回っています。                                                                     |
| **中立** | 30 分以内にカバレッジレポートが届きません。Aikido は pull request を失敗にしません。概要には、Aikido が時間内にカバレッジレポートを受信しなかったと表示されます。 |

Aikido は、そのコミットについて CI がアップロードしたレポートのカバレッジ割合を読み取ります。その割合はレポート内のファイルに基づきます。参照： [テストが収集したファイルを確認できます](/docs/docs-ja/kdo/code-coverage.md#you-see-the-files-your-tests-collected).

チェックは、そのコミットのアップロード割合を使用します。すべてのアプリを実行し、すべてのレポートをアップロードしてください。実行したアプリだけを含むレポートでは、そのアプリにしきい値が適用されます。変更のないアプリを除外するには、最新のレポートを引き継いで、すべてのレポートをまとめてアップロードしてください。参照 [変更されたパスのみをテストするモノレポ](/docs/docs-ja/kdo/code-coverage/monorepos-that-test-only-changed-paths.md).

## マージをブロック

Aikido はチェックを失敗にできます。その失敗がマージをブロックするかどうかは GitHub が決定します。次を追加してください。 **Aikido Security: コードカバレッジ** 保護したいブランチの必須ステータスチェックとして

参照 [失敗した PR チェックでマージをブロックする](/docs/docs-ja/pr-torirsugtingu/github-ci-pr-gating-via-aikido-dashboard.md#make-failed-pr-checks-block-merges).

## トラブルシューティング

* **チェックは保留のままで、その後中立で終了します：** pull request ワークフローが、そのコミットのレポートを 30 分以内にアップロードしませんでした。Aikido に接続されているリポジトリで、head コミットの pull request に対してアップロード手順が実行されていることを確認してください。
* **チェックは失敗し、割合が想定より低く見えます：** しきい値はアップロードされたレポートに適用されます。レポートがリポジトリの一部しか含まない場合、Aikido はその割合を使用します。テストランナーの collect または include パスを広げるか、すべてのアプリのレポートをまとめてアップロードして、もう一度アップロードしてください。参照 [変更されたパスのみをテストするモノレポ](/docs/docs-ja/kdo/code-coverage/monorepos-that-test-only-changed-paths.md).
* **構成の保存に失敗します：** 次のいずれかのスキャンを少なくとも 1 つ有効にしてから **脆弱性スキャン**、もう一度保存してください。
* **設定に「Upgrade:」と表示されます：** このチェックを含む Code Coverage は、Basic、Pro、Advanced、Enterprise の各プランで利用できます。

## ヘルプが必要ですか？

を開き、 **Intercomチャット** が右下隅に表示されます。私たちのチームがお手伝いします。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.aikido.dev/docs/docs-ja/kdo/code-coverage/pr-gating-on-code-coverage.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
