Bitbucket 6 does not call code insight code coverage provider callback

Hi,

I noticed that the Code Insights code coverage provider callback is not executed in Bitbucket versions >= 6.8 and <= 6.10.

In Bitbucket 7.x, this callback gets properly called:

public class MyCoverageProvider implements CodeCoverageProvider {

  public void streamCoverage(CodeCoverageRequest codeCoverageRequest,
                             CodeCoverageCallback codeCoverageCallback) {
 }
}

<code-coverage-provider name="My Bitbucket Code Coverage Provider" key="my-code-coverage-provider"  class="com.coverage.MyCoverageProvider">
  <description key="codecoverage.provider.description">Code Coverage Provider</description>
</code-coverage-provider>

The com.atlassian.bitbucket.codeinsights.coverage.CodeCoverageProvider interface exists since Bitbucket 6.8.

Is this a known problem, or is it just not meant to work before Bitbucket 7?

Or do I need to do someting differently in Bitbucket 6 to make this work?

Any help is much appreciated.

Thanks,
Michael

1 Like

Hi Michael,

If a pull request has multiple code insights reports that provide code coverage, only the first one will be called and all others will be ignored. Is it possible that in your testing with >7.0, you have multiple providers and multiple code insights reports?

Cheers,
Wolfgang

1 Like

Hi Wolfgang,

Thanks a lot for your feedback.

I’m not sure if I fully understand how this works.

So from my understanding, CodeCoerageProvider::streamCoverage is called for every file that is opened in a pull request diff on demand, and then the implementing callback can report coverage by using

codeCoverageCallback.onFileStart("myCoverageProviderKey", "myCoverageProviderUrl" , "filePath")
codeCoverageCallback.onRange(coverage)
codeCoverageCallback.onFileEnd()

This callback does not even get called in Bitbucket 6, so we cannot annotate files with coverage information.

I don’t see where the link between the code insight report and the code coverage is in this regard which could cause multiple reports.

Can you please clarify?

Thanks,
Michael

1 Like

Hi Michael,

No worries, I’ll try to clarify.

Each pull request can have multiple “Code Insights Reports”. Each report can have a “coverage provider key”, which corresponds to a module descriptor key that implements the CodeCoverageProvider interface.

If a pull request has multiple such insight reports that have a coverage provider key, only the first one it finds will get used. Which one comes first is undefined - it could be the one you want or it could be the wrong one.

Alternatively, if no insight report is found that has your expected coverage provider key, your coverage provider will not get called.

You can check out the source code of our unsupported labs plugin: InsightReportManager.java

Here it creates an insight report with its own coverage provider key. The provider is defined here: atlassian-plugin.xml

Let me know if those examples were helpful for you.

Cheers,
Wolfgang

1 Like

Hi Wolfgang,

Thanks, that clarifies a lot.

We only have one code insight report attached to a PR in our testing setup, and that references that one coverage provider:

new SetInsightReportRequest.Builder(repo, commitId, "my-report-key", "My App")
      .coverageProviderKey(PLUGIN_KEY + ":my-code-coverage-provider")

<code-coverage-provider name="My Bitbucket Code Coverage Provider" key="my-code-coverage-provider"  class="com.coverage.MyCoverageProvider">

If I understand it correctly, you are saying that Bitbucket will only consider one coverage report per code insight report key (“my-report-key” in the example above), so if multiple apps accidentally would use the same code insight report key, only of coverage report would be shown?

Does Bitbucket append the plugin key as a prefix to the code insight report key to make sure this is unique, or should the app use a fully qualified report key? So in the above example, should we rather use this?

new SetInsightReportRequest.Builder(repo, commitId, PLUGIN_KEY + ":my-report-key", "My App")

If I test our app standalone with no other apps in Bitbucket 7.0, I can see test coverage displayed correctly.
When I use Bitbucket 6.8, it does not appear. Is it possible that while the coverage provider API is available since Bitbucket 6.8, that Bitbucket only uses it since 7.0?

Thanks,
Michael

Not quite, it’ll look at all insight reports and pick the first one that provides coverage, and ignore the rest. That means if you had two reports that provide coverage, only one will get used. Coverage is never “merged”.

Ah yes you’re right, since 7.0 we are using a completely rewritten pull request experience and as part of that work, displaying code coverage was rewritten as well. Since Bitbucket <7.0 still uses the original pull request experience, which only had third party support for displaying code coverage, it won’t utilize the built in code coverage support. In the process of refactoring existing code for upcoming features, we sometimes add classes needed for that in the releases leading up to the release that contains the feature, but they are unused. That seems to be the case here too.

Cheers,
Wolfgang

2 Likes

Thanks again for the clarification, Wolfgang!