sonar-scanner-npm
sonar-scanner-npm copied to clipboard
Branch and PR analysis
I think it is not possible yet, so I post it here: It should be great to be able to run branch and PR analysis using this project instead of having to install sonar-scanner for it.
The required parameters to pass to sonar-scanner will be:
- sonar.branch.name
- sonar.pullrequest.branch
- sonar.pullrequest.key
- sonar.pullrequest.base
Seems to work if you pass them in the options. I Tried with AppVeyor and got something like:
const scanner = require('sonarqube-scanner');
var options = {
"sonar.sources": "./src",
//...
};
if(process.env.APPVEYOR_PULL_REQUEST_NUMBER){
var extraoptions = {
"sonar.pullrequest.key": process.env.APPVEYOR_PULL_REQUEST_NUMBER,
"sonar.pullrequest.branch": process.env.APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH,
"sonar.pullrequest.base": process.env.APPVEYOR_REPO_BRANCH
};
options = {...options, ...extraoptions};
};
console.log(options);
scanner(
{
serverUrl: process.env.SONAR_HOST,
token: process.env.SONAR_TOKEN,
options: options,
},
() => process.exit()
);
Most of the values are sent in from the CI env vars.
Hey guys, this is pretty cool. Maybe we can document it? Anyone motivated for a PR?
Note that the scanner itself can detected these settings already automatically for some CI server: https://docs.sonarqube.org/latest/analysis/pull-request/#header-4 https://docs.sonarqube.org/latest/branches/overview/#header-2
Thank you everyone for your contributions.
I added this topic to the list of potential improvements:
- #165
Feel free to reopen if you want to try a documentation PR or if anything new comes up.