Skip to content

Commit 97310e6

Browse files
committed
Implement GitProject.get_commits()
Signed-off-by: Nikola Forró <[email protected]>
1 parent 7daaa24 commit 97310e6

File tree

8 files changed

+150876
-0
lines changed

8 files changed

+150876
-0
lines changed

COMPATIBILITY.md

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ In case you find any error, please [create a new issue](https://github.com/packi
5454
| ----------------------------- | :----: | :----: | :---------------------: |
5555
| `change_token` ||||
5656
| `get_release` ||||
57+
| `get_commits` ||||
5758
| `get_latest_release` ||||
5859
| `is_private` ||| ✘ (may not be accurate) |
5960
| `remove_user` ||||

ogr/abstract.py

+12
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,18 @@ def default_branch(self) -> str:
14761476
"""Default branch (usually `main`, `master` or `trunk`)."""
14771477
raise NotImplementedError()
14781478

1479+
def get_commits(self, ref: Optional[str] = None) -> list[str]:
1480+
"""
1481+
Get list of commits for the project.
1482+
1483+
Args:
1484+
ref: Ref to start listing commits from, defaults to the default project branch.
1485+
1486+
Returns:
1487+
List of commit SHAs for the project.
1488+
"""
1489+
raise NotImplementedError()
1490+
14791491
def get_description(self) -> str:
14801492
"""
14811493
Returns:

ogr/services/github/project.py

+4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ def default_branch(self):
163163
def get_branches(self) -> list[str]:
164164
return [branch.name for branch in self.github_repo.get_branches()]
165165

166+
def get_commits(self, ref: Optional[str] = None) -> list[str]:
167+
ref = ref or self.github_repo.default_branch
168+
return [commit.sha for commit in self.github_repo.get_commits(sha=ref)]
169+
166170
def get_description(self) -> str:
167171
return self.github_repo.description
168172

ogr/services/gitlab/project.py

+7
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ def change_token(self, new_token: str):
360360
def get_branches(self) -> list[str]:
361361
return [branch.name for branch in self.gitlab_repo.branches.list(all=True)]
362362

363+
def get_commits(self, ref: Optional[str] = None) -> list[str]:
364+
ref = ref or self.default_branch
365+
return [
366+
commit.id
367+
for commit in self.gitlab_repo.commits.list(ref_name=ref, all=True)
368+
]
369+
363370
def get_file_content(self, path, ref=None) -> str:
364371
ref = ref or self.default_branch
365372
# GitLab cannot resolve './'

tests/integration/github/test_data/test_generic_commands/GenericCommands.test_commits.yaml

+150,167
Large diffs are not rendered by default.

tests/integration/github/test_generic_commands.py

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ def test_branches(self):
5050
assert branches
5151
assert {"master"}.issubset(set(branches))
5252

53+
def test_commits(self):
54+
commits = self.ogr_project.get_commits()
55+
assert commits
56+
assert commits[-1] == "7d4b107e0aa5a3fa55886ceb8acfb0b718919b37"
57+
5358
def test_git_urls(self):
5459
urls = self.ogr_project.get_git_urls()
5560
assert urls

0 commit comments

Comments
 (0)