Possibility to work with git commit history in a custom plugin?

Hi all!
I am new to plugin development and in my custom plugin I want to display a new graph in the sonarqube instance. My plugin idea would be to display the relation between cyclometic complexity of a file and number of commits for a file. As far as i know sonarqube has an embedded git-plugin.
Therefore is it possible to get the commit history (similar to git-log command) of each file through sonarqube?

Thank you in advance!

Hi,

The embedded git-plugin runs on the scanner, and it’s not part of the plugin API, so your plugin won’t have access to it.
In theory it may be possible to implement, but it will be hard.
I think it’d have to:

  • Embed your own git client in your plugin (like JGit)
  • Make sure your plugin gets called in the scanner through one of the extension points. Perhaps as a sensor (even though it wouldn’t analyze files), or as a PostJob.
  • Collect information in the scanner, and submit data through a webservice that your plugin would have to implement on the server side
  • Store the data somewhere in the FS

But without looking into it in more detail, I can’t guarantee that it will work.

Thank you for your answer.
Maybe I am thinking too easy but isnt it possible to get the complexity score of each file after the scanner?
Because if, then I would just call the git api (git client) to get the commits for each file and then I have all the information i need right?
The last question would be how the frontend can access the information from the git client so I can create a graph.
Am I missing something?

Yes, you can easily get the cyclomatic complexity as a measure in the server. As I said the server doesn’t have access to git though.

Okay thank you!
So theoretically
I should use a PostJob to get the complexity value of each file and then call a gitclient for the commit information per file. Then I just need to make the information about the nr of commits per file accessible for the frontend so I can make a graph with both informations on the frontend?

Is that realistic?

Yes, just keep in mind you’ll have to transfer that information from the scanner to the server before making it available to the frontend.
Have a look at Sonar Plugin API and the docs here.

Thank you for the tipp!
Just for clarification.

What server are you talking about? Do I have to run a server on my own ? Can I not do everything in the plugin itself?
You are probably talking about this part right?

Does that mean that my plugin would need an endpoint exposed for getting the information from the gitclient? Cant the plugin itself use the gitclient? Or is the endpoint needed so the frontend can get the new data?
(Sorry for so many quesitons haha)