8000 feat(api): add support for commit sequence · python-gitlab/python-gitlab@1f97be2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f97be2

Browse files
jyggennejch
authored andcommitted
feat(api): add support for commit sequence
1 parent cf87226 commit 1f97be2

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

gitlab/v4/objects/commits.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,24 @@ def revert(
127127
post_data = {"branch": branch}
128128
return self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
129129

130+
@cli.register_custom_action(cls_names="ProjectCommit")
131+
@exc.on_http_error(exc.GitlabGetError)
132+
def sequence(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
133+
"""Get the sequence number of the commit.
134+
135+
Args:
136+
**kwargs: Extra options to send to the server (e.g. sudo)
137+
138+
Raises:
139+
GitlabAuthenticationError: If authentication is not correct
140+
GitlabGetError: If the sequence number could not be retrieved
141+
142+
Returns:
143+
The commit's sequence number
144+
"""
145+
path = f"{self.manager.path}/{self.encoded_id}/sequence"
146+
return self.manager.gitlab.http_get(path, **kwargs)
147+
130148
@cli.register_custom_action(cls_names="ProjectCommit")
131149
@exc.on_http_error(exc.GitlabGetError)
132150
def signature(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:

tests/unit/objects/test_commits.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ def resp_get_commit_gpg_signature():
7878
yield rsps
7979

8080

81+
@pytest.fixture
82+
def resp_get_commit_sequence():
83+
content = {
84+
"count": 1,
85+
}
86+
87+
with responses.RequestsMock() as rsps:
88+
rsps.add(
89+
method=responses.GET,
90+
url="http://localhost/api/v4/projects/1/repository/commits/6b2257ea/sequence",
91+
json=content,
92+
content_type="application/json",
93+
status=200,
94+
)
95+
yield rsps
96+
97+
8198
def test_get_commit(project, resp_commit):
8299
commit = project.commits.get("6b2257ea")
83100
assert commit.short_id == "6b2257ea"
@@ -113,3 +130,9 @@ def test_get_commit_gpg_signature(project, resp_get_commit_gpg_signature):
113130
signature = commit.signature()
114131
assert signature["gpg_key_primary_keyid"] == "8254AAB3FBD54AC9"
115132
assert signature["verification_status"] == "verified"
133+
134+
135+
def test_get_commit_sequence(project, resp_get_commit_sequence):
136+
commit = project.commits.get("6b2257ea", lazy=True)
137+
sequence = commit.sequence()
138+
assert sequence["count"] == 1

0 commit comments

Comments
 (0)
0