(This question is unrelated to running the analysis, all of that works perfectly fine)
My problem is that I can’t figure out how to retrieve the badge or measures for any of the private projects in my org.
The weird thing is that retrieving a list of pull requests works like a charm, but when fetching a badge or measure it return status_code 200
and the SVG code for a “Project not found” image. Feel free to give it a try using the code below.
(ps: i’ve replaced the real project name with a dummy value in the code below)
import requests
from requests.exceptions import HTTPError
import os
API = "https://sonarcloud.io/api/";
HEADERS = { "Authorization": "Bearer " + os.environ["SONARCLOUD_TOKEN"] }
try:
response = requests.get(
# API + 'project_pull_requests/list',
API + 'project_badges/quality_gate',
params={'project' : 'orgname_projectname'},
headers=HEADERS
);
response.raise_for_status();
print(response.status_code)
print(response.text)
except HTTPError as http_error:
print(f"Something went wrong {http_error}")
200
<svg xmlns="http://www.w3.org/2000/svg" height="20" width="110">
<!-- ERROR -->
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<clipPath id="a">
<rect width="110" height="20" rx="3" fill="#fff"/>
</clipPath>
<g clip-path="url(#a)">
<rect fill="#e05d44" height="20" width="110"/>
<rect fill="url(#b)" height="20" width="110"/>
</g>
<g fill="#fff" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11" text-anchor="left">
<text x="4" y="15" fill="#010101" fill-opacity=".3">Project not found</text>
<text x="4" y="14">Project not found</text>
</g>
</svg>