Sonarqube 8.2 automatic/programmatic Github Pull Request decoration?

Hi,

I have a similar question than Is there's any way to auto configure the sonarqube pull request decoration but for Github:

  • I just upgraded to Sonarqube 8.2
  • our sources (and our PRs) are on Github
  • we have > 400 projects scanned by SonarQube
  • before (i.e Sonarqube 7.9.x) we could have Pull Request decoration automatically, but after the migration it seems that it is no longer the case. Apparently if I want them back, I need to go over each project to manually add PullRequest decoration and select the GitHub repository

I have 2 questions:

  • can I automatically/programmatically set the PR decoration on all existing project (without going through > 400 UI pages)
  • can I programmatically set PR decoration when I add new project to scan

Regards

hey ,
you can use the sonarqube API for this,

curl -X “POST” “http://****/api/alm_settings/set_bitbucket_binding”
-H ‘Content-Type: application/x-www-form-urlencoded; charset=utf-8’
-u ‘***:***’
–data-urlencode “almSetting=***”
–data-urlencode “project=***”
–data-urlencode “repository=***”
–data-urlencode “slug=***”

Hi @Nicolas_Zin,

Welcome to our community forum and thanks @abhishektaneja for helping :slight_smile:

I’ll try to give additional information here :

Normally, it should be the case automatically for existing projects with PR decoration, after you perform a PR analysis after the migration, the properties should be set automatically

  • Could you please check and let us know, otherwise we will investigate what’s not working.
  • Are you using the Developer Edition? If you are using another Edition, it may also explain some errors.

It depends on how you create your new projects on SQ:

  • if you create them on the UI, you have to set up the properties manually on the project settings after the project creation. Note that we want to improve this part and set automatically the properties by selecting the repository at project creation.
  • if you create them via a script, you can use the API.

Also to help us in our improvements, I would be happy to know how you create your projects in SQ, and especially, do you create one project at a time, or several projects at a time?

Thanks

Thanks for the pointer @abhishektaneja.
I manage to have something working (for Jenkins):

           withCredentials([string(credentialsId: 'admin-sonar-token', variable: 'SONARQUBE_ADMIN_TOKEN')]) {
               sh """\
               curl
               --verbose
               --user ${env.SONARQUBE_ADMIN_TOKEN}:
               --data "almSetting=myalmsettingName"
               --data "project=${properties['sonar.projectKey']}"
               --data "repository=${gitRepo}"
               --request POST
               ${properties['sonar.host.url']}/api/alm_settings/set_github_binding
               """.stripIndent().readLines().join(' ')
           }
1 Like

Where can i find these almSetting,project parameters… ???