These docs are for v5.0. Click to read the latest docs for v2023.

Pull Request Comments

Detailed report commented directly into your pull request

The Codecov pull request comment is a quick overview of how a pull request (and relevant commits) will affect the code coverage. This simple integration allows developers to see the effects of their work, without having to leave the familiar Github UI. The PR comment provides details on the coverage changes in the pull request that help with speeding up code reviews, and ensuring that all incoming features and fixes are well tested. The comment is customizable to adjust the behavior and logic, as well as the actual output, please see below for configuration details.

🚧

Codecov Delta

It is important to understand what absolute <relative> (impact) represents. Learn all about the Codecov Delta.

Configuration

comment:                  # this is a top-level key
  layout: " diff, flags, files"
  behavior: default
  require_changes: false  # if true: only post the comment if coverage changes
  require_base: false        # [true :: must have a base report to post]
  require_head: true       # [true :: must have a head report to post]

❗️

Setting the top-level comment key to true is not a valid configuration, as it will overwrite the default configuration with a boolean value and preclude the sending of any comment.

Layout

Customize your comment layout by choosing the order and types of components to include. Below is an example of a layout for diff, flags, files.

  • Diff is the Coverage Diff of the pull request.
  • Flags are a list of user defined Flags, and the impact on their coverage
    • Learn more about setting up Flags.
  • Files are a list of files that are impacted by the pull request (coverage changes, file is new or removed).

Behavior

Choose the way Codecov submits comments in your pull requests.

  • default: update, if exists. Otherwise post new.
  • once: update, if exists. Otherwise post new. Skip if deleted.
  • new: delete old and post new.

📘

Behavior: default

When updating, the creation date of the comment will stay the same. There will be an edited link with a drop-down where you can check the times updated.

Emails will be submitted to all subscribers of the pull request only when posting a new comment. There is no way to disable email notifications. This is a limitation of the Supported CI Providers.

Requiring Changes

You may desire to change when the comment is posted, if any changes are discovered in coverage.

comment:
  require_changes: true

Comments will now only post when coverage changes. Furthermore, if a comment already exists, and a newer commit results in no coverage change for the entire pull, the comment will be deleted.

Requiring the Base and/or Head Commit

You can force comments to post on pull requests even if Codecov doesn't have coverage reports for either the base or head commit. This generally isn't recommended since, without base and head coverage report information, the resulting comment is not very helpful.

However, setting both require_base and require_head to false can allow you to test the ability of Codecov to post a comment to your pull requests without needing to upload coverage for both the base and head commit.

comment:
  require_head: false     # default true
  require_base: false     # default true

after_n_builds

By default Codecov will post and/or update the pull request comment after it processes each report uploaded for a particular pull request commit. If your CI process uploads many reports to codecov, this can be confusing for team members viewing the pull request as reports are processing.

To remedy this, you can delay the posting of a pull request comment until a certain number of reports are received and processed by Codecov, using the after_n_builds setting.

Generally, you should set after_n_builds equal to the number of reports you upload per commit. However, this is not required. If after_n_builds is greater than the number of reports you upload for a commit, no comment will post. If it is less, the comment will post when after_n_builds is reached and (by default) continue to update on each additional report upload.

after_n_builds for flags

After_n_builds for flags allows you to specify how many uploads are in each Flag and only receive notifications for that flag after Codecov receives the n uploads for that Flag. Longer form blog on this functionality.

When using flag_management configuration will look like this:

flag_management:
  individual_flags:
    - name: projectA
      paths:
        - projectA/
      after_n_builds: 3
    - name: projectB
      paths:
        - projectB/
      after_n_builds: 2

When using flags to specify your flags setup, configuration will look like so:

flags:
  projectA:
    paths:
      - projectA/
    after_n_builds: 3
  projectB:
    paths:
      - projectB/
    after_n_builds: 2

show_carryforward_flags

For those using the Carryforward Flags feature, Carryforward Flags do not show in the pull request comment by default.

You can configure presence of Carryforward Flags in the flags table via advanced usage of Carryforward Flags.

Disable comment

To disable the comment, simply set the top-level comment key to false in your codecov.yml, as shown below.

comment: false

You can do this in your Team Yaml, to take effect on all your repositories.

For more troubleshooting options, be sure to read about the Team Bot


What’s Next

It is important to learn about the Codecov Delta syntax to fully understand pull request comments.