shijl0925 / python-sonarqube-api

Python Client library for interacting with Community, Developer, and Enterprise Editions SonarQube's REST APIs and SonarCloud's REST APIs.
https://python-sonarqube-pro-api.readthedocs.io/en/latest/
GNU Affero General Public License v3.0
133 stars 77 forks source link

get_rule() is broken for SonarCloud #36

Closed damiencarol closed 3 years ago

damiencarol commented 3 years ago

This snippet:

from sonarqube import SonarCloudClient

token = "..."
sonar = SonarCloudClient(sonarcloud_url="https://sonarcloud.io", token=token)
issues = sonar.issues.search_issues(componentKeys="...")
for issue in issues:
    print(f"key: {issue['key']}")
    print(f"rule: {sonar.rules.get_rule(issue['rule'])}")

Generate:

key: AXxbH--R-dDKUnsQv6k7
Traceback (most recent call last):
  File "/home/damien/python-sonarqube-api/test_cloud.py", line 8, in <module>
    print(f"rule: {sonar.rules.get_rule(issue['rule'])}")
  File "/home/damien/python-sonarqube-api/sonarqube/utils/common.py", line 132, in inner_func
    response = self._get(url_pattern, params=params)
  File "/home/damien/python-sonarqube-api/sonarqube/utils/rest_client.py", line 144, in _get
    return self.request("GET", path=path, params=params, data=data, headers=headers)
  File "/home/damien/python-sonarqube-api/sonarqube/utils/rest_client.py", line 82, in request
    raise ValidationError(msg)
sonarqube.utils.exceptions.ValidationError: Error in request. Possibly validation error [400]: The 'organization' parameter is missing
shijl0925 commented 3 years ago

from sonarqube import SonarCloudClient

token = "..." sonar = SonarCloudClient(sonarcloud_url="https://sonarcloud.io", token=token) issues = sonar.issues.search_issues(componentKeys="...") for issue in issues: print(f"key: {issue['key']}") print(f"rule: {sonar.rules.get_rule(issue['rule'], organization)}")


hi, you miss "organization" param in the function get_rule.

damiencarol commented 3 years ago

ok. thanks.