---
title: Récupérer le résumé de couverture de code pour un commit
description: Récupérer des statistiques agrégées de couverture de code pour un commit spécifique dans un référentiel.
breadcrumbs: Documentation > API > Récupérer le résumé de couverture de code pour un commit
---

> For the complete documentation index, see [llms.txt](https://dnd37xeb23o8n.cloudfront.net/jen.gilbert/astro-base/llms.txt).

# Récupérer le résumé de couverture de code pour un commit

## v2 (latest)

| Datadog site      | API endpoint                                                           |
| ----------------- | ---------------------------------------------------------------------- |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/code-coverage/commit/summary     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/code-coverage/commit/summary |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/code-coverage/commit/summary |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/code-coverage/commit/summary      |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/code-coverage/commit/summary |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/code-coverage/commit/summary |
| uk1.datadoghq.com | POST https://api.uk1.datadoghq.com/api/v2/code-coverage/commit/summary |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/code-coverage/commit/summary      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/code-coverage/commit/summary  |

### Overview

Récupérer des statistiques agrégées de couverture de code pour un commit spécifique dans un référentiel.
Cet endpoint fournit des métriques de couverture globales ainsi que des ventilations par service
et par propriétaire de code.

Le SHA du commit doit être une chaîne hexadécimale de 40&nbsp;caractères (hash SHA-1).

This endpoint requires the `code_coverage_read` permission.

OAuth apps require the `code_coverage_read` authorization [scope](https://dnd37xeb23o8n.cloudfront.net/jen.gilbert/astro-base/fr/api/latest/scopes.md#code-coverage) to access this endpoint.

### Request

#### Body Data (required)

{% tabs %}
{% tab label="Model" %}
| Parent field | Field                   | Type   | Description                                                                                                                                                                          |
| ------------ | ----------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|              | data [*required*]       | object | Objet de requête pour la récupération du résumé de couverture de code pour un commit.                                                                                                |
| data         | attributes [*required*] | object | Attributes for requesting code coverage summary for a commit.                                                                                                                        |
| attributes   | commit_sha [*required*] | string | The commit SHA (40-character hexadecimal string).                                                                                                                                    |
| attributes   | repository_id           | string | **DEPRECATED**: Deprecated: use `repository_url` instead. The repository URL.                                                                                                        |
| attributes   | repository_url          | string | The repository URL. Accepts a full URL with or without a scheme (for example, `https://github.com/org/repo` or `github.com/org/repo`).                                               |
| data         | type [*required*]       | enum   | JSON:API type for commit coverage summary request. The value must always be `ci_app_coverage_commit_summary_request`. Allowed enum values: `ci_app_coverage_commit_summary_request`. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "commit_sha": "66adc9350f2cc9b250b69abddab733dd55e1a588",
      "repository_id": "github.com/datadog/shopist",
      "repository_url": "https://github.com/datadog/shopist"
    },
    "type": "ci_app_coverage_commit_summary_request"
  }
}
```
{% /tab %}
{% /tabs %}

### Response

{% tabs %}
{% tab label="200" %}
OK

{% tabs %}
{% tab label="Model" %}
Response object containing code coverage summary.

| Parent field         | Field                   | Type   | Description                                                                                                                                      |
| -------------------- | ----------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|                      | data                    | object | Data object for coverage summary response.                                                                                                       |
| data                 | attributes              | object | Attributes object for code coverage summary response.                                                                                            |
| attributes           | codeowners              | object | Coverage statistics broken down by code owner.                                                                                                   |
| additionalProperties | <any-key>               | object | Coverage statistics for a specific code owner.                                                                                                   |
| <any-key>            | evaluated_flags_count   | int64  | Number of coverage flags evaluated for the code owner.                                                                                           |
| <any-key>            | evaluated_reports_count | int64  | Number of coverage reports evaluated for the code owner.                                                                                         |
| <any-key>            | patch_coverage          | double | Patch coverage percentage for the code owner.                                                                                                    |
| <any-key>            | total_coverage          | double | Total coverage percentage for the code owner.                                                                                                    |
| attributes           | evaluated_flags_count   | int64  | Total number of coverage flags evaluated.                                                                                                        |
| attributes           | evaluated_reports_count | int64  | Total number of coverage reports evaluated.                                                                                                      |
| attributes           | patch_coverage          | double | Overall patch coverage percentage.                                                                                                               |
| attributes           | services                | object | Coverage statistics broken down by service.                                                                                                      |
| additionalProperties | <any-key>               | object | Coverage statistics for a specific service.                                                                                                      |
| <any-key>            | evaluated_flags_count   | int64  | Number of coverage flags evaluated for the service.                                                                                              |
| <any-key>            | evaluated_reports_count | int64  | Number of coverage reports evaluated for the service.                                                                                            |
| <any-key>            | patch_coverage          | double | Patch coverage percentage for the service.                                                                                                       |
| <any-key>            | total_coverage          | double | Total coverage percentage for the service.                                                                                                       |
| attributes           | total_coverage          | double | Overall total coverage percentage.                                                                                                               |
| data                 | id                      | string | Unique identifier for the coverage summary (base64-hashed).                                                                                      |
| data                 | type                    | enum   | JSON:API type for coverage summary response. The value must always be `ci_app_coverage_summary`. Allowed enum values: `ci_app_coverage_summary`. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "codeowners": {
        "<any-key>": {
          "evaluated_flags_count": 2,
          "evaluated_reports_count": 4,
          "patch_coverage": 75.2,
          "total_coverage": 88.7
        }
      },
      "evaluated_flags_count": 8,
      "evaluated_reports_count": 12,
      "patch_coverage": 70.1,
      "services": {
        "<any-key>": {
          "evaluated_flags_count": 3,
          "evaluated_reports_count": 5,
          "patch_coverage": 72.3,
          "total_coverage": 85.5
        }
      },
      "total_coverage": 82.4
    },
    "id": "ZGQxMjM0NV9tYWluXzE3MDk1NjQwMDA=",
    "type": "ci_app_coverage_summary"
  }
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="400" %}
Bad Request

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="403" %}
Not Authorized

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="404" %}
Not Found

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="429" %}
Too many requests

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="500" %}
Internal server error

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}
{% /tabs %}

### Code Example

{% tabs %}
{% tab label="Curl" %}
```bash
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com" # Or us3.datadoghq.com, us5.datadoghq.com, datadoghq.eu, ap1.datadoghq.com, ap2.datadoghq.com, uk1.datadoghq.com, ddog-gov.com, us2.ddog-gov.com
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/code-coverage/commit/summary" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "commit_sha": "66adc9350f2cc9b250b69abddab733dd55e1a588",
      "repository_url": "https://github.com/datadog/test-service"
    },
    "type": "ci_app_coverage_commit_summary_request"
  }
}
EOF
```
{% /tab %}

{% tab label="Go" %}
```go
// Get code coverage summary for a commit returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	body := datadogV2.CommitCoverageSummaryRequest{
		Data: datadogV2.CommitCoverageSummaryRequestData{
			Attributes: datadogV2.CommitCoverageSummaryRequestAttributes{
				CommitSha:     "66adc9350f2cc9b250b69abddab733dd55e1a588",
				RepositoryId:  datadog.PtrString("github.com/datadog/shopist"),
				RepositoryUrl: datadog.PtrString("https://github.com/datadog/shopist"),
			},
			Type: datadogV2.COMMITCOVERAGESUMMARYREQUESTTYPE_CI_APP_COVERAGE_COMMIT_SUMMARY_REQUEST,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewCodeCoverageApi(apiClient)
	resp, r, err := api.GetCodeCoverageCommitSummary(ctx, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `CodeCoverageApi.GetCodeCoverageCommitSummary`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `CodeCoverageApi.GetCodeCoverageCommitSummary`:\n%s\n", responseContent)
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"
```
{% /tab %}

{% tab label="Java" %}
```java
// Get code coverage summary for a commit returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.CodeCoverageApi;
import com.datadog.api.client.v2.model.CommitCoverageSummaryRequest;
import com.datadog.api.client.v2.model.CommitCoverageSummaryRequestAttributes;
import com.datadog.api.client.v2.model.CommitCoverageSummaryRequestData;
import com.datadog.api.client.v2.model.CommitCoverageSummaryRequestType;
import com.datadog.api.client.v2.model.CoverageSummaryResponse;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
    CodeCoverageApi apiInstance = new CodeCoverageApi(defaultClient);

    CommitCoverageSummaryRequest body =
        new CommitCoverageSummaryRequest()
            .data(
                new CommitCoverageSummaryRequestData()
                    .attributes(
                        new CommitCoverageSummaryRequestAttributes()
                            .commitSha("66adc9350f2cc9b250b69abddab733dd55e1a588")
                            .repositoryId("github.com/datadog/shopist")
                            .repositoryUrl("https://github.com/datadog/shopist"))
                    .type(CommitCoverageSummaryRequestType.CI_APP_COVERAGE_COMMIT_SUMMARY_REQUEST));

    try {
      CoverageSummaryResponse result = apiInstance.getCodeCoverageCommitSummary(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling CodeCoverageApi#getCodeCoverageCommitSummary");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"
```
{% /tab %}

{% tab label="Python" %}
```python
"""
Get code coverage summary for a commit returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.code_coverage_api import CodeCoverageApi
from datadog_api_client.v2.model.commit_coverage_summary_request import CommitCoverageSummaryRequest
from datadog_api_client.v2.model.commit_coverage_summary_request_attributes import (
    CommitCoverageSummaryRequestAttributes,
)
from datadog_api_client.v2.model.commit_coverage_summary_request_data import CommitCoverageSummaryRequestData
from datadog_api_client.v2.model.commit_coverage_summary_request_type import CommitCoverageSummaryRequestType

body = CommitCoverageSummaryRequest(
    data=CommitCoverageSummaryRequestData(
        attributes=CommitCoverageSummaryRequestAttributes(
            commit_sha="66adc9350f2cc9b250b69abddab733dd55e1a588",
            repository_id="github.com/datadog/shopist",
            repository_url="https://github.com/datadog/shopist",
        ),
        type=CommitCoverageSummaryRequestType.CI_APP_COVERAGE_COMMIT_SUMMARY_REQUEST,
    ),
)

configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
with ApiClient(configuration) as api_client:
    api_instance = CodeCoverageApi(api_client)
    response = api_instance.get_code_coverage_commit_summary(body=body)

    print(response)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"
```
{% /tab %}

{% tab label="Ruby" %}
```ruby
# Get code coverage summary for a commit returns "OK" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
  config.access_token = ENV["DD_BEARER_TOKEN"]
end
api_instance = DatadogAPIClient::V2::CodeCoverageAPI.new

body = DatadogAPIClient::V2::CommitCoverageSummaryRequest.new({
  data: DatadogAPIClient::V2::CommitCoverageSummaryRequestData.new({
    attributes: DatadogAPIClient::V2::CommitCoverageSummaryRequestAttributes.new({
      commit_sha: "66adc9350f2cc9b250b69abddab733dd55e1a588",
      repository_id: "github.com/datadog/shopist",
      repository_url: "https://github.com/datadog/shopist",
    }),
    type: DatadogAPIClient::V2::CommitCoverageSummaryRequestType::CI_APP_COVERAGE_COMMIT_SUMMARY_REQUEST,
  }),
})
p api_instance.get_code_coverage_commit_summary(body)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"
```
{% /tab %}

{% tab label="Rust" %}
```rust
// Get code coverage summary for a commit returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_code_coverage::CodeCoverageAPI;
use datadog_api_client::datadogV2::model::CommitCoverageSummaryRequest;
use datadog_api_client::datadogV2::model::CommitCoverageSummaryRequestAttributes;
use datadog_api_client::datadogV2::model::CommitCoverageSummaryRequestData;
use datadog_api_client::datadogV2::model::CommitCoverageSummaryRequestType;

#[tokio::main]
async fn main() {
    let body = CommitCoverageSummaryRequest::new(CommitCoverageSummaryRequestData::new(
        CommitCoverageSummaryRequestAttributes::new(
            "66adc9350f2cc9b250b69abddab733dd55e1a588".to_string(),
        )
        .repository_id("github.com/datadog/shopist".to_string())
        .repository_url("https://github.com/datadog/shopist".to_string()),
        CommitCoverageSummaryRequestType::CI_APP_COVERAGE_COMMIT_SUMMARY_REQUEST,
    ));
    let configuration = datadog::Configuration::new();
    let api = CodeCoverageAPI::with_config(configuration);
    let resp = api.get_code_coverage_commit_summary(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
```
{% /tab %}

{% tab label="TypeScript" %}
```typescript
/**
 * Get code coverage summary for a commit returns "OK" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration({
  authMethods: {
    AuthZ: {
      accessToken: process.env.DD_BEARER_TOKEN as string,
    },
  },
});
const apiInstance = new v2.CodeCoverageApi(configuration);

const params: v2.CodeCoverageApiGetCodeCoverageCommitSummaryRequest = {
  body: {
    data: {
      attributes: {
        commitSha: "66adc9350f2cc9b250b69abddab733dd55e1a588",
        repositoryId: "github.com/datadog/shopist",
        repositoryUrl: "https://github.com/datadog/shopist",
      },
      type: "ci_app_coverage_commit_summary_request",
    },
  },
};

apiInstance
  .getCodeCoverageCommitSummary(params)
  .then((data: v2.CoverageSummaryResponse) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"
```
{% /tab %}
{% /tabs %}
