> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qlty.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Get pull request coverage

> Retrieve a pull request's coverage, as the pull request's Coverage page shows it: total line coverage at the base and head, and the diff coverage of the lines the pull request adds or modifies. Coverage from every tag is combined, and the diff is the pull request's current diff. Every section keeps its shape. When a section can't be computed, its values are null and `unavailableReason` says why, while the other sections still return: `no_coverage` (no coverage has been processed for the pull request: none was uploaded, or it is still processing), `selective_coverage` (the head coverage is a selective upload, which has no total), `diff_too_large` (GitHub can't return the diff because it is too large), or `no_changed_files` (GitHub reports no changed files, which can mean it hasn't computed the diff yet). As on the pull request's Coverage page, the pull request's author needs a Qlty seat when the project is private; otherwise the response is a 403 that links to seat management. See https://docs.qlty.sh/cloud/billing/seats. Requires a user access token from someone who signs in to Qlty with GitHub, because the pull request and its diff are read from GitHub as that user. When the GitHub organization enforces SAML single sign-on and the user's authorization has lapsed, the response is a 403 that links to https://docs.qlty.sh/cloud/troubleshooting#saml-re-authentication-required; re-authorize, then retry.



## OpenAPI

````yaml https://api.qlty.sh/openapi.json get /gh/{ownerKeyOrId}/projects/{projectKeyOrId}/pulls/{number}/coverage
openapi: 3.1.0
info:
  title: Qlty API
  version: 1.0.0
  description: >-
    The Qlty API is organized around REST. It provides predictable,
    resource-oriented URLs, accepts JSON-encoded request bodies, and returns
    JSON-encoded responses.
servers:
  - url: https://api.qlty.sh
security:
  - Bearer: []
tags:
  - name: Service
    description: Service status and API discovery operations
  - name: User
    description: Operations for the authenticated user
  - name: Workspaces
    description: Operations for managing workspaces
  - name: Projects
    description: Operations for managing projects
  - name: Issues
    description: Operations for managing issues
  - name: Builds
    description: Operations for retrieving builds
  - name: Metrics
    description: Operations for retrieving metrics
  - name: Components
    description: Operations for retrieving components
  - name: Applications
    description: Operations for managing applications, which group a workspace's projects
  - name: Coverage
    description: Operations for retrieving code coverage data
  - name: Pull Requests
    description: Operations for retrieving pull request coverage
paths:
  /gh/{ownerKeyOrId}/projects/{projectKeyOrId}/pulls/{number}/coverage:
    get:
      tags:
        - Pull Requests
      summary: Get pull request coverage
      description: >-
        Retrieve a pull request's coverage, as the pull request's Coverage page
        shows it: total line coverage at the base and head, and the diff
        coverage of the lines the pull request adds or modifies. Coverage from
        every tag is combined, and the diff is the pull request's current diff.
        Every section keeps its shape. When a section can't be computed, its
        values are null and `unavailableReason` says why, while the other
        sections still return: `no_coverage` (no coverage has been processed for
        the pull request: none was uploaded, or it is still processing),
        `selective_coverage` (the head coverage is a selective upload, which has
        no total), `diff_too_large` (GitHub can't return the diff because it is
        too large), or `no_changed_files` (GitHub reports no changed files,
        which can mean it hasn't computed the diff yet). As on the pull
        request's Coverage page, the pull request's author needs a Qlty seat
        when the project is private; otherwise the response is a 403 that links
        to seat management. See https://docs.qlty.sh/cloud/billing/seats.
        Requires a user access token from someone who signs in to Qlty with
        GitHub, because the pull request and its diff are read from GitHub as
        that user. When the GitHub organization enforces SAML single sign-on and
        the user's authorization has lapsed, the response is a 403 that links to
        https://docs.qlty.sh/cloud/troubleshooting#saml-re-authentication-required;
        re-authorize, then retry.
      operationId: getPullRequestCoverage
      parameters:
        - schema:
            type: string
            minLength: 3
            example: acme-corp
            description: Repository owner name (login) or workspace ID
          required: true
          description: Repository owner name (login) or workspace ID
          name: ownerKeyOrId
          in: path
        - schema:
            type: string
            minLength: 3
            example: my-repo
            description: Repository name or project ID
          required: true
          description: Repository name or project ID
          name: projectKeyOrId
          in: path
        - schema:
            type: integer
            minimum: 0
            exclusiveMinimum: true
            example: 123
            description: Pull request number
          required: true
          description: Pull request number
          name: number
          in: path
      responses:
        '200':
          description: Retrieve the pull request's coverage
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PullRequestCoverage'
              example:
                head:
                  reference: refs/pull/123
                  commitSha: 4f0c2d1e9b8a7c6d5e4f3a2b1c0d9e8f7a6b5c4d
                  coverageCommits:
                    - tag: unit
                      commitSha: 4f0c2d1e9b8a7c6d5e4f3a2b1c0d9e8f7a6b5c4d
                base:
                  reference: refs/heads/main
                  commitSha: 9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b
                  coverageCommits:
                    - tag: unit
                      commitSha: 9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b
                comparisons:
                  - metric:
                      key: LCOV
                      name: Line Coverage
                      description: Percentage of lines covered by tests
                      category: coverage
                      inverted: false
                      valueType: percentage
                    base: 87.5
                    head: 87.8
                    change: 0.3
                    unavailableReason: null
                diffCoverage:
                  key: DCOV
                  name: Diff Coverage
                  description: >-
                    Line coverage of the lines this pull request added or
                    modified
                  category: coverage
                  inverted: false
                  valueType: percentage
                  value: 84.21
                  coveredLines: 16
                  missedLines: 3
                  unavailableReason: null
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate Limit Exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    PullRequestCoverage:
      type: object
      properties:
        head:
          type: object
          properties:
            reference:
              type: string
              example: refs/pull/123
            commitSha:
              type: string
              example: 4f0c2d1e9b8a7c6d5e4f3a2b1c0d9e8f7a6b5c4d
            coverageCommits:
              type: array
              items:
                $ref: '#/components/schemas/PullRequestCoverageCommit'
          required:
            - reference
            - commitSha
            - coverageCommits
        base:
          type: object
          properties:
            reference:
              type: string
              example: refs/heads/main
            commitSha:
              type: string
              example: 9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b
            coverageCommits:
              type: array
              items:
                $ref: '#/components/schemas/PullRequestCoverageCommit'
              description: >-
                The commit each of the head's tags got its base coverage from.
                Empty when the base has no coverage for any of the head's tags.
                Fewer tags than `head.coverageCommits` means the pull request's
                tags changed, so total coverage isn't compared.
          required:
            - reference
            - commitSha
            - coverageCommits
        comparisons:
          type: array
          items:
            $ref: '#/components/schemas/PullRequestCoverageComparison'
        diffCoverage:
          $ref: '#/components/schemas/PullRequestDiffCoverage'
      required:
        - head
        - base
        - comparisons
        - diffCoverage
    Error:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              status:
                type: string
                example: '400'
              title:
                type: string
                example: Bad Request
              detail:
                type: string
                example: The request was invalid.
            required:
              - status
              - title
              - detail
      required:
        - errors
    PullRequestCoverageCommit:
      type: object
      properties:
        tag:
          type: string
          nullable: true
          example: unit
          description: Coverage tag, or null for coverage uploaded without one
        commitSha:
          type: string
          example: 4f0c2d1e9b8a7c6d5e4f3a2b1c0d9e8f7a6b5c4d
          description: >-
            Commit the tag's coverage came from. It is older than the head or
            base commit when no coverage was uploaded for that commit.
      required:
        - tag
        - commitSha
    PullRequestCoverageComparison:
      type: object
      properties:
        metric:
          $ref: '#/components/schemas/MetricDescriptor'
        base:
          type: number
          nullable: true
          example: 87.5
          description: >-
            Null unless the base has coverage for every one of the head's tags;
            `base.coverageCommits` shows which case applies
        head:
          type: number
          nullable: true
          example: 87.8
        change:
          type: number
          nullable: true
          example: 0.3
          description: >-
            Null unless base and head are both numbers. On large test suites,
            total coverage can move between identical runs, so a small change
            may not come from the pull request. See
            https://docs.qlty.sh/coverage/unexpected-changes#unexpected-code-coverage-changes.
        unavailableReason:
          $ref: '#/components/schemas/PullRequestCoverageUnavailableReason'
      required:
        - metric
        - base
        - head
        - change
        - unavailableReason
    PullRequestDiffCoverage:
      allOf:
        - $ref: '#/components/schemas/MetricDescriptor'
        - type: object
          properties:
            value:
              type: number
              nullable: true
              example: 84.21
              description: >-
                Percentage rounded to two decimal places, or null when the diff
                changes no executable lines or `unavailableReason` is set
            coveredLines:
              type: integer
              nullable: true
              example: 16
            missedLines:
              type: integer
              nullable: true
              example: 3
            unavailableReason:
              $ref: '#/components/schemas/PullRequestCoverageUnavailableReason'
          required:
            - value
            - coveredLines
            - missedLines
            - unavailableReason
    MetricDescriptor:
      type: object
      properties:
        key:
          type: string
          example: CMPLX
          description: >-
            One of the keys described in `MetricKey`, or `DCOV` (Diff Coverage:
            line coverage of the lines a pull request added or modified), which
            only pull request coverage returns
        name:
          type: string
          example: Cognitive Complexity
        description:
          type: string
          example: Measures how hard the code is to understand
        category:
          type: string
          enum:
            - maintainability
            - reliability
            - security
            - size
            - coverage
            - quality
          example: maintainability
        inverted:
          type: boolean
          example: true
          description: When true, higher values are worse
        valueType:
          type: string
          enum:
            - number
            - percentage
            - grade
            - size
            - duration
            - count
          example: number
          description: How the metric's value should be interpreted
      required:
        - key
        - name
        - category
        - inverted
        - valueType
    PullRequestCoverageUnavailableReason:
      type: string
      nullable: true
      enum:
        - no_coverage
        - selective_coverage
        - diff_too_large
        - no_changed_files
        - null
      description: Why the values are null, or null when they were computed
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer
      description: Generate an API token at https://qlty.sh/user/settings/tokens

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.