Skip to content

Commit

Permalink
Implement GitProject.get_commits()
Browse files Browse the repository at this point in the history
Signed-off-by: Nikola Forró <nforro@redhat.com>
  • Loading branch information
nforro committed Sep 6, 2024
1 parent 7daaa24 commit 97310e6
Show file tree
Hide file tree
Showing 8 changed files with 150,876 additions and 0 deletions.
1 change: 1 addition & 0 deletions COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ In case you find any error, please [create a new issue](https://github.com/packi
| ----------------------------- | :----: | :----: | :---------------------: |
| `change_token` ||||
| `get_release` ||||
| `get_commits` ||||
| `get_latest_release` ||||
| `is_private` ||| ✘ (may not be accurate) |
| `remove_user` ||||
Expand Down
12 changes: 12 additions & 0 deletions ogr/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,18 @@ def default_branch(self) -> str:
"""Default branch (usually `main`, `master` or `trunk`)."""
raise NotImplementedError()

def get_commits(self, ref: Optional[str] = None) -> list[str]:
"""
Get list of commits for the project.
Args:
ref: Ref to start listing commits from, defaults to the default project branch.
Returns:
List of commit SHAs for the project.
"""
raise NotImplementedError()

def get_description(self) -> str:
"""
Returns:
Expand Down
4 changes: 4 additions & 0 deletions ogr/services/github/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ def default_branch(self):
def get_branches(self) -> list[str]:
return [branch.name for branch in self.github_repo.get_branches()]

def get_commits(self, ref: Optional[str] = None) -> list[str]:
ref = ref or self.github_repo.default_branch
return [commit.sha for commit in self.github_repo.get_commits(sha=ref)]

def get_description(self) -> str:
return self.github_repo.description

Expand Down
7 changes: 7 additions & 0 deletions ogr/services/gitlab/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ def change_token(self, new_token: str):
def get_branches(self) -> list[str]:
return [branch.name for branch in self.gitlab_repo.branches.list(all=True)]

def get_commits(self, ref: Optional[str] = None) -> list[str]:
ref = ref or self.default_branch
return [
commit.id
for commit in self.gitlab_repo.commits.list(ref_name=ref, all=True)
]

def get_file_content(self, path, ref=None) -> str:
ref = ref or self.default_branch
# GitLab cannot resolve './'
Expand Down

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions tests/integration/github/test_generic_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_branches(self):
assert branches
assert {"master"}.issubset(set(branches))

def test_commits(self):
commits = self.ogr_project.get_commits()
assert commits
assert commits[-1] == "7d4b107e0aa5a3fa55886ceb8acfb0b718919b37"

def test_git_urls(self):
urls = self.ogr_project.get_git_urls()
assert urls
Expand Down
Loading

0 comments on commit 97310e6

Please sign in to comment.