Skip to content

Commit e7f684e

Browse files
committed
implement support for Forgejo comments and reactions
2 parents c31b4cf + 02358ec commit e7f684e

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

ogr/abstract.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,34 @@ def __repr__(self) -> str:
157157

158158

159159
class Reaction(OgrAbstractClass):
160-
def __init__(self, raw_reaction: Any) -> None:
160+
def __init__(
161+
self,
162+
raw_reaction: Any,
163+
reaction_id: Optional[int] = None,
164+
parent: Optional[Any] = None,
165+
) -> None:
161166
self._raw_reaction = raw_reaction
167+
self._id = reaction_id
168+
self._parent = parent
162169

163170
def __str__(self):
164171
return f"Reaction(raw_reaction={self._raw_reaction})"
165172

166173
def delete(self) -> None:
167174
"""Delete a reaction."""
168-
raise NotImplementedError()
175+
if not self._id:
176+
raise ValueError("Cannot delete a reaction without an ID.")
177+
if not self._parent:
178+
raise ValueError("Cannot delete a reaction without a parent object.")
179+
if not self._raw_reaction or "content" not in self._raw_reaction:
180+
raise ValueError("Invalid raw reaction data.")
181+
182+
self._parent.client.issue.delete_comment_reaction(
183+
owner=self._parent.repo_namespace,
184+
repo=self._parent.repo_name,
185+
id=self._id,
186+
content=self._raw_reaction["content"],
187+
)
169188

170189

171190
class Comment(OgrAbstractClass):
@@ -204,7 +223,11 @@ def __str__(self) -> str:
204223

205224
def _from_raw_comment(self, raw_comment: Any) -> None:
206225
"""Constructs Comment object from raw_comment given from API."""
207-
raise NotImplementedError()
226+
self._id = raw_comment["id"]
227+
self._body = raw_comment["body"]
228+
self._author = raw_comment["user"]["login"]
229+
self._created = raw_comment["created_at"]
230+
self._edited = raw_comment.get("updated_at")
208231

209232
@property
210233
def body(self) -> str:
@@ -236,7 +259,15 @@ def edited(self) -> datetime.datetime:
236259

237260
def get_reactions(self) -> list[Reaction]:
238261
"""Returns list of reactions."""
239-
raise NotImplementedError()
262+
if not self._id or not self._parent:
263+
raise ValueError("Cannot fetch reactions without a comment ID and parent.")
264+
265+
reactions_data = self._parent.client.issue.get_comment_reactions(
266+
owner=self._parent.repo_namespace,
267+
repo=self._parent.repo_name,
268+
id=self._id,
269+
)
270+
return [Reaction(raw_reaction=react) for react in reactions_data]
240271

241272
def add_reaction(self, reaction: str) -> Reaction:
242273
"""
@@ -250,7 +281,16 @@ def add_reaction(self, reaction: str) -> Reaction:
250281
Returns:
251282
Object representing newly added reaction.
252283
"""
253-
raise NotImplementedError()
284+
if not self._id or not self._parent:
285+
raise ValueError("Cannot add reaction without a comment ID and parent.")
286+
287+
reaction_data = self._parent.client.issue.add_comment_reaction(
288+
owner=self._parent.repo_namespace,
289+
repo=self._parent.repo_name,
290+
id=self._id,
291+
content=reaction,
292+
)
293+
return Reaction(raw_reaction=reaction_data)
254294

255295

256296
class IssueComment(Comment):

recipe.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
name:
2828
- twine # we need newest twine, b/c of the check command
2929
- readme_renderer[md]
30-
- pytest-cov
31-
3230
state: latest
3331
become: true
3432
- name: Install requre

0 commit comments

Comments
 (0)