Rest API to get code quality on fly

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    I am using SonarQube version 8.1 and Scanner 4.4
  • what are you trying to achieve
    I am looking to get the code quality, error, smell, bug, etc report by calling an API from my PHP application. In my application, the code will be sent through the API for each user and using the JSON data we will create the report.
  • what have you tried so far to achieve this
    I have created a project in my local machine’s SonarQube server, the API called to check that the javascript file is providing the correct report now as per my requirement, but now I want to get the same on the fly by sending the codes to the API.

Hi,

Welcome to the community!

It’s not clear what you’re asking.

 
Ann

Thanks for the reply.

We are building an online based assessment application where the candidates will write codes of different languages based on the questions. Now we need to get all the reports, bugs, quality, complexity etc by calling an API from our application. What’s the best and shortest procedure to get that?

As per my research i have found all the APIs used to get the code report, now the issue is for each new code of the candidates i have to update the file from where the SonarQube is executing to find the errors. Do i have to create file for each different language with its respective file extension? For every new code i have to run the SonarScanner command? Is there any single API to get all types of report? Please Help!

Hi,

If you want not just issues but also metrics, then yes you’ll need to set file extensions and run analysis each time. If you’re just interested in issues, then you might look at SonarLint.

 
HTH,
Ann

Hi,

Thanks a lot for your valuable reply. We will work on that and it’s clear that how we need to proceed.

TVM,
Rohit

Hi Ann,

One more thing i would like to ask, Is there any API by which i can run the sonnarscanner command ( sonar-scanner -Dsonar.projectKey=####### -Dsonar.sources=. -Dsonar.host.url=https://192.###.##.##:#### -Dsonar.login=8f65###################49c0) to sync the new code with the SonarQube server added in the respective file? Similar to “api/system/restart” (which restarts the server).

Anyone please help me on this.

Can I run the sonar-scanner command from remote server using PHP? How to achieve this, so that the code gets updated in the SonarQube?

Is there anyone who can help me on this? I just want to run the sonar-scanner from remote server using PHP.

Hi,

Have you considered that you’re not getting an answer because this isn’t supported?

 
Ann

Hi,
Are you asking or saying? If not, then is it because i am using community edition or it is not possible to run sonar scanner remotely?

Rohit

Hi Rohit,

The scanners are not ‘always on’ applications that are actively listening for commands. They spin up when you invoke them, do their job, and spin down. It’s possible to invoke the command remotely in the same way it’s possible to invoke any other command (E.G. cd, mkdir, rm -R) on a remote machine - by establishing a remote session. If I were you, I would proceed carefully.

 
Ann

Hi ANN,

I know how to invoke a command from remote server but wondering if there is any other API or a different way to achieve the same. Anyways thanks for your valuable reply.

Thanks a lot
Rohit

Hi Rohit,

Did you find any solution or workaround on this problem ?

Thanks
-Dhanasekaran.