Skip to content

Commit 0bd2975

Browse files
committed
Implement GithubCommit.get_prs
Signed-off-by: Cristian Le <[email protected]>
1 parent 56c957d commit 0bd2975

File tree

3 files changed

+1004
-0
lines changed

3 files changed

+1004
-0
lines changed

ogr/services/github/commit.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ogr.exceptions import GithubAPIException, OgrNetworkError
1111
from ogr.services import github as ogr_github
1212
from ogr.services.base import BaseGitCommit
13+
from ogr.services.github.pull_request import GithubPullRequest
1314

1415

1516
class GithubCommit(BaseGitCommit):
@@ -26,6 +27,10 @@ def changes(self) -> "GithubCommitChanges":
2627
self._changes = GithubCommitChanges(self)
2728
return self._changes
2829

30+
def get_prs(self) -> Iterable[GithubPullRequest]:
31+
for pr in self._raw_commit.get_pulls():
32+
yield GithubPullRequest(pr, self.project)
33+
2934
@staticmethod
3035
def get(project: "ogr_github.GithubProject", sha: str) -> "GithubCommit":
3136
try:

tests/integration/github/test_commit.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,16 @@ def test_changes(self):
2222
commit = self.hello_world_project.get_commit("f06fed9")
2323
changes = commit.changes
2424
assert list(changes.files) == ["LICENSE", "README.md"]
25+
26+
def test_get_prs(self):
27+
# Commit with PR associated
28+
commit_with_one_pr = self.hello_world_project.get_commit("0840e2d")
29+
prs = list(commit_with_one_pr.get_prs())
30+
assert prs
31+
assert len(prs) == 1
32+
assert prs[0].id == 556
33+
# Commit with no PR
34+
commit_without_pr = self.hello_world_project.get_commit("f2c98da")
35+
prs = commit_without_pr.get_prs()
36+
assert not prs
37+
# No test data for commit with multiple PRs

0 commit comments

Comments
 (0)