Skip to content

gitlab.v4.objects.repositories.RepositoryMixin.repository_merge_base should only return dict[str, Any] #3390

@stdedos

Description

@stdedos

Description of the problem, including code/CLI snippet

Based on the "average" repository_merge_base call

@cli.register_custom_action(cls_names="Project", required=("refs",))
@exc.on_http_error(exc.GitlabGetError)
def repository_merge_base(
self, refs: list[str], **kwargs: Any
) -> dict[str, Any] | requests.Response:
"""Return a diff between two branches/commits.
Args:
refs: The refs to find the common ancestor of. Multiple refs can be passed.
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the server failed to perform the request
Returns:
The common ancestor commit (*not* a RESTObject)
"""
path = f"/projects/{self.encoded_id}/repository/merge_base"
query_data, _ = utils._transform_types(
data={"refs": refs},
custom_types={"refs": types.ArrayAttribute},
transform_data=True,
)
return self.manager.gitlab.http_get(path, query_data=query_data, **kwargs)

And the definition of http_get

def http_get(
self,
path: str,
query_data: dict[str, Any] | None = None,
streamed: bool = False,
raw: bool = False,
**kwargs: Any,
) -> dict[str, Any] | requests.Response:
"""Make a GET request to the Gitlab server.
Args:
path: Path or full URL to query ('/projects' or
'http://whatever/v4/api/projecs')
query_data: Data to send as query parameters
streamed: Whether the data should be streamed
raw: If True do not try to parse the output as json
**kwargs: Extra options to send to the server (e.g. sudo)
Returns:
A requests result object is streamed is True or the content type is
not json.
The parsed json data otherwise.
Raises:
GitlabHttpError: When the return code is not 2xx
GitlabParsingError: If the json data could not be parsed
"""
query_data = query_data or {}
result = self.http_request(
"get", path, query_data=query_data, streamed=streamed, **kwargs
)
content_type = utils.get_content_type(result.headers.get("Content-Type"))
if content_type == "application/json" and not streamed and not raw:
try:
json_result = result.json()
if TYPE_CHECKING:
assert isinstance(json_result, dict)
return json_result
except Exception as e:
raise gitlab.exceptions.GitlabParsingError(
error_message="Failed to parse the server message"
) from e
else:
return result

I would say that 99.9% (or even 100% of the time) the result is JSON aka dict[str, Any]

Expected Behavior

Actual Behavior

Specifications

  • python-gitlab version:
  • Gitlab server version (or gitlab.com):

https://github.com/python-gitlab/python-gitlab/issues?q=sort%3Aupdated-desc%20is%3Aissue%20repository_merge_base

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions