Skip to content

Commit 0a897cb

Browse files
committed
Add GitCommit and Commit changes abstracts
Signed-off-by: Cristian Le <git@lecris.dev>
1 parent 9c5d2d5 commit 0a897cb

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

ogr/abstract.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,11 @@ def labels(self) -> Union[list["PRLabel"], Iterable["PRLabel"]]:
648648
"""Labels of the pull request."""
649649
raise NotImplementedError()
650650

651+
@property
652+
def changes(self) -> "PullRequestChanges":
653+
"""Commit-like change information."""
654+
raise NotImplementedError()
655+
651656
@property
652657
def diff_url(self) -> str:
653658
"""Web URL to the diff of the pull request."""
@@ -1097,6 +1102,89 @@ def __str__(self) -> str:
10971102
)
10981103

10991104

1105+
class CommitLikeChanges(OgrAbstractClass):
1106+
"""
1107+
Class representing a commit-like changes.
1108+
1109+
Can be from a single commit or aggregated like from a PR.
1110+
"""
1111+
1112+
@property
1113+
def parent(self) -> Union["GitCommit", "PullRequest"]:
1114+
"""Parent object containing the changes."""
1115+
raise NotImplementedError
1116+
1117+
@property
1118+
def files(self) -> Union[list[str], Iterable[str]]:
1119+
"""Files changed by the current change."""
1120+
raise NotImplementedError
1121+
1122+
@property
1123+
def patch(self) -> bytes:
1124+
"""Patch of the changes."""
1125+
raise NotImplementedError
1126+
1127+
@property
1128+
def diff_url(self) -> str:
1129+
"""Web URL to the diff of the pull request."""
1130+
raise NotImplementedError()
1131+
1132+
1133+
class CommitChanges(CommitLikeChanges):
1134+
"""
1135+
Class representing a Commit's change
1136+
1137+
Attributes:
1138+
commit (GitCommit): Parent commit.
1139+
"""
1140+
1141+
def __init__(self, commit: "GitCommit") -> None:
1142+
self.commit = commit
1143+
1144+
@property
1145+
def parent(self) -> "GitCommit":
1146+
return self.commit
1147+
1148+
1149+
class PullRequestChanges(CommitLikeChanges):
1150+
"""
1151+
Class representing a PullRequest's changes
1152+
1153+
Attributes:
1154+
pull_request (PullRequest): Parent pull request.
1155+
"""
1156+
1157+
def __init__(self, pull_request: "PullRequest") -> None:
1158+
self.pull_request = pull_request
1159+
1160+
@property
1161+
def parent(self) -> "PullRequest":
1162+
return self.pull_request
1163+
1164+
1165+
class GitCommit(OgrAbstractClass):
1166+
"""
1167+
Class representing a git commit
1168+
1169+
Attributes:
1170+
project (GitProject): Git project where the commit belongs to.
1171+
"""
1172+
1173+
def __init__(self, raw_commit: Any, project: "GitProject") -> None:
1174+
self._raw_commit = raw_commit
1175+
self.project = project
1176+
1177+
@property
1178+
def sha(self) -> str:
1179+
"""Commit hash."""
1180+
raise NotImplementedError
1181+
1182+
@property
1183+
def changes(self) -> "CommitChanges":
1184+
"""Commit change information."""
1185+
raise NotImplementedError()
1186+
1187+
11001188
class GitTag(OgrAbstractClass):
11011189
"""
11021190
Class representing a git tag.
@@ -1514,6 +1602,16 @@ def default_branch(self) -> str:
15141602
"""Default branch (usually `main`, `master` or `trunk`)."""
15151603
raise NotImplementedError()
15161604

1605+
def get_commit(self, sha: str) -> "GitCommit":
1606+
"""
1607+
Get a specific commit information.
1608+
1609+
Args:
1610+
sha: Specific sha of the commit
1611+
1612+
"""
1613+
raise NotImplementedError()
1614+
15171615
def get_commits(self, ref: Optional[str] = None) -> Union[list[str], Iterable[str]]:
15181616
"""
15191617
Get list of commits for the project.

ogr/services/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from ogr.abstract import (
1010
CommitFlag,
1111
CommitStatus,
12+
GitCommit,
1213
GitProject,
1314
GitService,
1415
GitUser,
@@ -86,6 +87,10 @@ def get_statuses(self) -> Union[list[CommitFlag], Iterable[CommitFlag]]:
8687
return self.target_project.get_commit_statuses(commit)
8788

8889

90+
class BaseGitCommit(GitCommit):
91+
pass
92+
93+
8994
class BaseGitUser(GitUser):
9095
pass
9196

0 commit comments

Comments
 (0)