Skip to content

Commit ef4b3ec

Browse files
committed
Quality pass
1 parent 350f594 commit ef4b3ec

File tree

9 files changed

+24
-16
lines changed

9 files changed

+24
-16
lines changed

sonar/branches.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ def delete(self) -> bool:
176176
log.warning(e.message)
177177
return False
178178

179-
def get(self, api: str, params: types.ApiParams = None, data: str = None, mute: tuple[HTTPStatus] = (), **kwargs) -> requests.Response:
179+
def get(self, api: str, params: types.ApiParams = None, data: Optional[str] = None, mute: tuple[HTTPStatus] = (), **kwargs: str) -> requests.Response:
180+
"""Performs an HTTP GET request for the object"""
180181
try:
181182
return super().get(api=api, params=params, data=data, mute=mute, **kwargs)
182183
except exceptions.ObjectNotFound as e:
@@ -185,7 +186,8 @@ def get(self, api: str, params: types.ApiParams = None, data: str = None, mute:
185186
projects.Project.CACHE.clear()
186187
raise
187188

188-
def post(self, api: str, params: types.ApiParams = None, mute: tuple[HTTPStatus] = (), **kwargs) -> requests.Response:
189+
def post(self, api: str, params: types.ApiParams = None, mute: tuple[HTTPStatus] = (), **kwargs: str) -> requests.Response:
190+
"""Performs an HTTP POST request for the object"""
189191
try:
190192
return super().post(api=api, params=params, mute=mute, **kwargs)
191193
except exceptions.ObjectNotFound as e:

sonar/hotspots.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ def __mark_as(self, resolution: Optional[str], comment: Optional[str] = None, st
160160
params = util.remove_nones({"hotspot": self.key, "status": status, "resolution": resolution, "commemt": comment})
161161
ok = self.post("hotspots/change_status", params=params).ok
162162
self.refresh()
163-
return ok
164163
except exceptions.SonarException:
165164
return False
165+
else:
166+
return ok
166167

167168
def mark_as_safe(self) -> bool:
168169
"""Marks a hotspot as safe
@@ -231,9 +232,10 @@ def assign(self, assignee: Optional[str], comment: Optional[str] = None) -> bool
231232
ok = self.post("hotspots/assign", util.remove_nones({"hotspot": self.key, "assignee": assignee, "comment": comment})).ok
232233
if ok:
233234
self.assignee = assignee
234-
return ok
235235
except exceptions.SonarException:
236236
return False
237+
else:
238+
return ok
237239

238240
def unassign(self, comment: Optional[str] = None) -> bool:
239241
"""Unassigns a hotspot (and optionally comment)

sonar/issues.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,10 @@ def assign(self, assignee: Optional[str] = None) -> bool:
343343
log.debug("Assigning %s to '%s'", str(self), str(assignee))
344344
if ok := self.post("issues/assign", params).ok:
345345
self.assignee = assignee
346-
return ok
347346
except exceptions.SonarException:
348347
return False
348+
else:
349+
return ok
349350

350351
def get_tags(self, **kwargs) -> list[str]:
351352
"""Returns issues tags"""
@@ -393,9 +394,10 @@ def set_type(self, new_type: str) -> bool:
393394
try:
394395
if ok := self.post("issues/set_type", {"issue": self.key, "type": new_type}).ok:
395396
self.type = new_type
396-
return ok
397397
except exceptions.SonarException:
398398
return False
399+
else:
400+
return ok
399401

400402
def is_wont_fix(self) -> bool:
401403
"""

sonar/permissions/permission_templates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def set_as_default(self, what_list: list[str]) -> bool:
148148
return self.post("permissions/set_default_template", params={"templateId": self.key, "qualifier": qual}).ok
149149
except exceptions.SonarException:
150150
return False
151+
return False
151152

152153
def set_pattern(self, pattern: str) -> PermissionTemplate:
153154
"""Sets a permission template pattern"""

sonar/projects.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,7 @@ def reload(self, data: types.ApiPayload) -> Project:
251251
:rtype: Project
252252
"""
253253
"""Loads a project object with contents of an api/projects/search call"""
254-
if self.sq_json is None:
255-
self.sq_json = data
256-
else:
257-
self.sq_json.update(data)
254+
self.sq_json = (self.sq_json or {}) | data
258255
self.name = data["name"]
259256
self._visibility = data["visibility"]
260257
if "lastAnalysisDate" in data:

sonar/qualitygates.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,10 @@ def set_as_default(self) -> bool:
300300
# Turn off default for all other quality gates except the current one
301301
for qg in get_list(self.endpoint).values():
302302
qg.is_default = qg.name == self.name
303-
return ok
304303
except exceptions.SonarException:
305304
return False
305+
else:
306+
return ok
306307

307308
def update(self, **data) -> bool:
308309
"""Updates a quality gate

sonar/settings.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,21 @@ def set(self, value: any) -> bool:
261261
try:
262262
if ok := self.post(Setting.API[c.CREATE], params=params).ok:
263263
self.value = value
264-
return ok
265264
except exceptions.SonarException:
266265
return False
266+
else:
267+
return ok
267268

268269
def reset(self) -> bool:
269270
log.info("Resetting %s", str(self))
270271
params = {"keys": self.key} | {} if not self.component else {"component": self.component.key}
271272
try:
272273
ok = self.post("settings/reset", params=params).ok
273274
self.refresh()
274-
return ok
275275
except exceptions.SonarException:
276276
return False
277+
else:
278+
return ok
277279

278280
def to_json(self, list_as_csv: bool = True) -> types.ObjectJsonRepr:
279281
val = self.value
@@ -508,10 +510,11 @@ def set_setting(endpoint: pf.Platform, key: str, value: any, component: object =
508510
log.warning("Setting '%s' does not exist on target platform, it cannot be set", key)
509511
return False
510512
s.set(value)
511-
return True
512513
except exceptions.SonarException as e:
513514
log.error("Setting '%s' cannot be set: %s", key, e.message)
514515
return False
516+
else:
517+
return True
515518

516519

517520
def decode(setting_key: str, setting_value: any) -> any:

sonar/sqobject.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,12 @@ def set_tags(self, tags: list[str]) -> bool:
186186
try:
187187
if ok := self.post(self.__class__.API[c.SET_TAGS], params={**self.api_params(c.SET_TAGS), "tags": utilities.list_to_csv(tags)}).ok:
188188
self._tags = sorted(tags)
189-
return ok
190189
except exceptions.SonarException:
191190
return False
192191
except (AttributeError, KeyError):
193192
raise exceptions.UnsupportedOperation(f"Can't set tags on {self.__class__.__name__.lower()}s")
193+
else:
194+
return ok
194195

195196
def get_tags(self, **kwargs) -> list[str]:
196197
"""Returns object tags"""

sonar/users.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import datetime as dt
2828
import json
2929

30-
from http import HTTPStatus
3130
from requests import RequestException
3231

3332
import sonar.logging as log

0 commit comments

Comments
 (0)