carlspring
carlspring

Reputation: 32597

Is there a way to embed coverage from SonarQube into a Github project as an icon?

Is it possible to embed code coverage results (stored in SonarQube) into Github projects as one of those embeddable icon gadgets (not sure what their name is; it would be great if somebody to tell me that as well)...? I'm referring to the ones that show the build status, for example.

Upvotes: 12

Views: 7040

Answers (2)

Ahmad
Ahmad

Reputation: 5760

Using a plugin in no longer needed, as some new APIs are now added that will do what you want. You can use this snippet in your .md files:

[![SonarCloud Coverage](https://{domain}/api/project_badges/measure?project={projectName}&metric=coverage)](https://{domain}/component_measures/metric/coverage/list?id={projectName})

Note that you have to replace parameters inside {}s with your own values. If you are using on-premise version, the domain will be your own domain and if you are using cloud version, it will be sonarcloud.io.

Also note that this will work only for public projects. For private ones, I could not find any solution.

And finally as a side note, the metric parameter takes some values other than coverage and gives other fantastic badges that you may find helpful:

bugs, code_smells, coverage, duplicated_lines_density, ncloc, sqale_rating, alert_status, reliability_rating, security_rating, sqale_index, vulnerabilities

Upvotes: 3

G. Ann - SonarSource Team
G. Ann - SonarSource Team

Reputation: 22804

The only thing currently available is this under-development plugin, which was first discussed in this Google Group thread. Note that this project appears to be in its infancy.

EDIT

This plugin has since been released, and can be installed directly from the Update Center

EDIT 2

With SonarQube 7.1, badges become a native feature.

Upvotes: 13

Related Questions