Skip to content

Commit e353045

Browse files
committed
Implement GithubCommit.get_prs
Signed-off-by: Cristian Le <[email protected]>
1 parent 7f798eb commit e353045

File tree

3 files changed

+999
-0
lines changed

3 files changed

+999
-0
lines changed

ogr/services/github/commit.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Copyright Contributors to the Packit project.
22
# SPDX-License-Identifier: MIT
3+
from typing import Optional
4+
35
import github
46
from github.Commit import Commit as _GitCommit
57

8+
from ogr.abstract import PullRequest
69
from ogr.exceptions import GithubAPIException
710
from ogr.services import github as ogr_github
811
from ogr.services.base import BaseGitCommit
912
from ogr.services.github.changes import GithubCommitChanges
13+
from ogr.services.github.pull_request import GithubPullRequest
1014

1115

1216
class GithubCommit(BaseGitCommit):
@@ -23,6 +27,12 @@ def changes(self) -> GithubCommitChanges:
2327
self._changes = GithubCommitChanges(self)
2428
return self._changes
2529

30+
def get_prs(self) -> Optional[list[PullRequest]]:
31+
raw_prs = list(self._raw_commit.get_pulls())
32+
if not raw_prs:
33+
return None
34+
return [GithubPullRequest(pr, self.project) for pr in raw_prs]
35+
2636
@staticmethod
2737
def get(project: "ogr_github.GithubProject", sha: str) -> "GithubCommit":
2838
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 = 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)