SonarQube 8.9.1 (build 44547) - Developer Edition
Fetching the source via url “…/api/sources/key=PROJ:src/test_file&branch=b1” results in fetching from the default branch instead (usually master), which results in an error if the file does not exist on that branch.
Note that the URL “…/api/issues” works correctly with the branch parameter.
Looks similar to these issues on previous versions:
Can you clarify which API you’re using?
api/source/key=PROJ:src/test_file&branch=b1 does not exist. There must be a typo somewhere…
api/sources/raw can return the source code of a file on a branch BUT this is an internal API not formally supported publicly by SonarSource
Yes you are correct, typo in copying partial URLs. Sorry about that.
It should be the SCM endpoint i.e.
Yes, you’re correct. You cannot select branch from this API. Actually this API is not actively evolved since it is no longer used by SonarQube and there are alternatives API that do the job fine:
- If you only want the raw source file you should use
- If you want the SCM data you should use the
api/sources/lines. This API is internal though.
Both the above API support the
Now I am not quite sure why you want to fetch source code from SonarQube. This is 2nd hand information. You should get it from the SCM itself.
It is the SCM data I needed for a report which I generate using the Python sonarqube library.
Originally the report was generated on another server without access to the GIT repository (post build/scan). That is no longer the case so I can fetch directly as you mention.
Thanks for the help.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.