Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GitProject.get_commits() #857

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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` | ✔ | ✔ | ✘ |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something that works on Pagure? (not even push counts, cause even that can yield 500…)

| `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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling that the list was a not the best decision waaaay back in the old days.

]

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
Loading