Branch name that contains a / needs to be changed to % for api call to work

SonarQube 6.7.2 LTS

I have seen weird behavior with the following api call and need to rename the branch to change the / to % to get the correct results.

Branch name - feature/MADLC-7668-test-execution-remove-description_AR
Returns a null, but when you change to feature%MADLC-7668-test-execution-remove-description_AR it returns expected results.

$ curl -s GET “http://sonarqube.xxx.com/api/measures/component?componentKey=il-workflow&metricKeys=files&branch=feature/MADLC-7668-test-execution-remove-description_AR” | jq -cr .component.measures | jq -cr .[0].value
null

$ curl -s GET “http://sonarqube.xxx.com/api/measures/component?componentKey=il-workflow&metricKeys=files&branch=feature%MADLC-7668-test-execution-remove-description_AR” | jq -cr .component.measures | jq -cr .[0].value
34

Branch name - bugfix/XXX-12345-SonarQube-0-files
Returns expected results, even if your rename to bugfix%XXX-12345-SonarQube-0-files

$ curl -s GET “http://sonarqube.xxx.com/api/measures/component?componentKey=maven-test&metricKeys=files&branch=bugfix/XXX-12345-SonarQube-0-files” | jq -cr .component.measures | jq -cr .[0].value
230

$ curl -s GET “http://sonarqube.xxx.com/api/measures/component?componentKey=maven-test&metricKeys=files&branch=bugfix%XXX-12345-SonarQube-0-files” | jq -cr .component.measures | jq -cr .[0].value
230

Hi,

The first thought that comes to mind is that the URL encoded character for a ‘/’ is ‘%2F’ so it’s hard for me to see how ‘%’ could make any difference. It’s also hard to double-check that against your data since you kept the trailing formatting (jq -cr .[0].value).

The other thought that comes to mind is that you seem to be querying measures on feature branches. If you (as one would expect) track those feature branches as short-lived branches in SonarQube, then don’t expect to get measures for them: for short-lived branches only issues are computed.

All in all I would suggest you focus on the raw WebAPI call for now (can even do that from the browser), and its raw output (also comparing to what you get in the UI). It should help clarify current behaviour. (and until then I would definitely not trust the results you seem to be getting with that % in the URL)

%MA is an invalid url encoding sequence. Query parameters that contain an invalid sequence get dropped, so the result you get is the same result as if there was no branch= parameter present at all.

The results you are getting when using the correct branch value should be correct as is. I suggest to drop the filters and inspect the content. If it’s not what you would expect, then please share with us what you expected, and we should be able to find the explanation.

1 Like