Skip to content

Commit 497e860

Browse files
fix: change to http_list for some ProjectCommit methods
Fix the type-hints and use `http_list()` for the ProjectCommits methods: - diff() - merge_requests() - refs() This will enable using the pagination support we have for lists. Closes: #1805 Closes: #1231
1 parent a349793 commit 497e860

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

gitlab/v4/objects/commits.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import Any, cast, Dict, Optional, TYPE_CHECKING, Union
1+
from typing import Any, cast, Dict, List, Optional, TYPE_CHECKING, Union
22

33
import requests
44

5+
import gitlab
56
from gitlab import cli
67
from gitlab import exceptions as exc
78
from gitlab.base import RequiredOptional, RESTManager, RESTObject
@@ -28,7 +29,7 @@ class ProjectCommit(RESTObject):
2829

2930
@cli.register_custom_action("ProjectCommit")
3031
@exc.on_http_error(exc.GitlabGetError)
31-
def diff(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
32+
def diff(self, **kwargs: Any) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]:
3233
"""Generate the commit diff.
3334
3435
Args:
@@ -42,7 +43,7 @@ def diff(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
4243
The changes done in this commit
4344
"""
4445
path = f"{self.manager.path}/{self.get_id()}/diff"
45-
return self.manager.gitlab.http_get(path, **kwargs)
46+
return self.manager.gitlab.http_list(path, **kwargs)
4647

4748
@cli.register_custom_action("ProjectCommit", ("branch",))
4849
@exc.on_http_error(exc.GitlabCherryPickError)
@@ -65,7 +66,7 @@ def cherry_pick(self, branch: str, **kwargs: Any) -> None:
6566
@exc.on_http_error(exc.GitlabGetError)
6667
def refs(
6768
self, type: str = "all", **kwargs: Any
68-
) -> Union[Dict[str, Any], requests.Response]:
69+
) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]:
6970
"""List the references the commit is pushed to.
7071
7172
Args:
@@ -80,12 +81,14 @@ def refs(
8081
The references the commit is pushed to.
8182
"""
8283
path = f"{self.manager.path}/{self.get_id()}/refs"
83-
data = {"type": type}
84-
return self.manager.gitlab.http_get(path, query_data=data, **kwargs)
84+
query_data = {"type": type}
85+
return self.manager.gitlab.http_list(path, query_data=query_data, **kwargs)
8586

8687
@cli.register_custom_action("ProjectCommit")
8788
@exc.on_http_error(exc.GitlabGetError)
88-
def merge_requests(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
89+
def merge_requests(
90+
self, **kwargs: Any
91+
) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]:
8992
"""List the merge requests related to the commit.
9093
9194
Args:
@@ -99,7 +102,7 @@ def merge_requests(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Respon
99102
The merge requests related to the commit.
100103
"""
101104
path = f"{self.manager.path}/{self.get_id()}/merge_requests"
102-
return self.manager.gitlab.http_get(path, **kwargs)
105+
return self.manager.gitlab.http_list(path, **kwargs)
103106

104107
@cli.register_custom_action("ProjectCommit", ("branch",))
105108
@exc.on_http_error(exc.GitlabRevertError)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy