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?
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
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.
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?
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.