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.