Skip to content
Open
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
3 changes: 3 additions & 0 deletions packit_service/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
copr,
enums,
event,
forgejo,
github,
gitlab,
koji,
Expand All @@ -20,8 +21,10 @@
__all__ = [
abstract.__name__,
anitya.__name__,
forgejo.__name__,
github.__name__,
gitlab.__name__,
forgejo.__name__,
koji.__name__,
openscanhub.__name__,
pagure.__name__,
Expand Down
3 changes: 2 additions & 1 deletion packit_service/events/abstract/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def __init__(
tag_name: str = "",
comment_object: Optional[Comment] = None,
dist_git_project_url=None,
commit_sha: Optional[str] = None,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How come this got in:

include unit tests for forgejo event; fixes

😄

) -> None:
super().__init__(
project_url=project_url,
Expand All @@ -168,7 +169,7 @@ def __init__(

# Lazy properties
self._tag_name = tag_name
self._commit_sha: Optional[str] = None
self._commit_sha: Optional[str] = commit_sha
self._comment_object = comment_object
self._issue_object: Optional[OgrIssue] = None

Expand Down
6 changes: 6 additions & 0 deletions packit_service/events/forgejo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

from . import abstract, issue, pr, push

__all__ = [abstract.__name__, issue.__name__, pr.__name__, push.__name__]
17 changes: 17 additions & 0 deletions packit_service/events/forgejo/abstract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

from typing import Optional

from ..abstract.base import ForgeIndependent


class ForgejoEvent(ForgeIndependent):
def __init__(self, project_url: str, pr_id: Optional[int] = None, **kwargs):
super().__init__(pr_id=pr_id)
self.project_url: str = project_url
# git ref that can be 'git checkout'-ed
self.git_ref: Optional[str] = None
self.identifier: Optional[str] = (
None # will be shown to users -- e.g. in logs or in the copr-project name
)
54 changes: 54 additions & 0 deletions packit_service/events/forgejo/issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

from typing import Optional

from ogr.abstract import Comment as OgrComment

from ..abstract.comment import Issue as AbstractIssueCommentEvent
from ..enums import IssueCommentAction
from .abstract import ForgejoEvent


class Comment(AbstractIssueCommentEvent, ForgejoEvent):
def __init__(
self,
action: IssueCommentAction,
issue_id: int,
repo_namespace: str,
repo_name: str,
target_repo: str,
project_url: str,
actor: str,
comment: str,
comment_id: int,
tag_name: str = "",
base_ref: Optional[str] = "main",
comment_object: Optional[OgrComment] = None,
dist_git_project_url=None,
) -> None:
super().__init__(
issue_id=issue_id,
repo_namespace=repo_namespace,
repo_name=repo_name,
project_url=project_url,
comment=comment,
comment_id=comment_id,
tag_name=tag_name,
comment_object=comment_object,
dist_git_project_url=dist_git_project_url,
)
self.action = action
self.actor = actor
self.base_ref = base_ref
self.target_repo = target_repo
self.identifier = str(issue_id)

@classmethod
def event_type(cls) -> str:
return "forgejo.issue.Comment"

def get_dict(self, default_dict: Optional[dict] = None) -> dict:
result = super().get_dict()
result["action"] = self.action.value
return result
118 changes: 118 additions & 0 deletions packit_service/events/forgejo/pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

from typing import Optional

from ogr.abstract import Comment as OgrComment
from ogr.abstract import GitProject

from packit_service.service.db_project_events import AddPullRequestEventToDb

from ..abstract.comment import PullRequest as AbstractPRCommentEvent
from ..enums import PullRequestAction, PullRequestCommentAction
from .abstract import ForgejoEvent


class Action(AddPullRequestEventToDb, ForgejoEvent):
def __init__(
self,
action: PullRequestAction,
pr_id: int,
base_repo_namespace: str,
base_repo_name: str,
base_ref: str,
target_repo_namespace: str,
target_repo_name: str,
project_url: str,
commit_sha: str,
commit_sha_before: str,
actor: str,
body: str,
):
super().__init__(project_url=project_url, pr_id=pr_id)
self.action = action
self.base_repo_namespace = base_repo_namespace
self.base_repo_name = base_repo_name
self.base_ref = base_ref
self.target_repo_namespace = target_repo_namespace
self.target_repo_name = target_repo_name
self.actor = actor
self.identifier = str(pr_id)
self.commit_sha = commit_sha
self.commit_sha_before = commit_sha_before
self.body = body

def get_dict(self, default_dict: Optional[dict] = None) -> dict:
result = super().get_dict()
result["action"] = result["action"].value
return result

@classmethod
def event_type(cls) -> str:
return "forgejo.pr.Action"

def get_base_project(self) -> GitProject:
return self.project.service.get_project(
namespace=self.base_repo_namespace,
repo=self.base_repo_name,
)


class Comment(AbstractPRCommentEvent, ForgejoEvent):
def __init__(
self,
action: PullRequestCommentAction,
pr_id: int,
base_repo_namespace: str,
base_repo_name: Optional[str],
base_ref: Optional[str],
target_repo_namespace: str,
target_repo_name: str,
project_url: str,
actor: str,
comment: str,
comment_id: int,
commit_sha: Optional[str] = None,
comment_object: Optional[OgrComment] = None,
) -> None:
super().__init__(
pr_id=pr_id,
project_url=project_url,
comment=comment,
comment_id=comment_id,
commit_sha=commit_sha,
comment_object=comment_object,
)
self.action = action
self.base_repo_namespace = base_repo_namespace
self.base_repo_name = base_repo_name
self.base_ref = base_ref
self.target_repo_namespace = target_repo_namespace
self.target_repo_name = target_repo_name
self.actor = actor
self.identifier = str(pr_id)
self.git_ref = None

@classmethod
def event_type(cls) -> str:
return "forgejo.pr.Comment"

def get_dict(self, default_dict: Optional[dict] = None) -> dict:
"""
Override get_dict to avoid accessing properties that make API calls.
Use private attributes directly, similar to forgejo/issue.py.
"""
from ..abstract.comment import CommentEvent

result = CommentEvent.get_dict(self, default_dict=default_dict)
result.pop("_comment_object")
result["action"] = self.action.value
result["pr_id"] = self.pr_id
result["commit_sha"] = self._commit_sha
return result

def get_base_project(self) -> GitProject:
return self.project.service.get_project(
namespace=self.base_repo_namespace,
repo=self.base_repo_name,
)
29 changes: 29 additions & 0 deletions packit_service/events/forgejo/push.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

from packit_service.service.db_project_events import AddBranchPushEventToDb

from .abstract import ForgejoEvent


class Commit(AddBranchPushEventToDb, ForgejoEvent):
def __init__(
self,
repo_namespace: str,
repo_name: str,
git_ref: str,
project_url: str,
commit_sha: str,
commit_sha_before: str,
):
super().__init__(project_url=project_url)
self.repo_namespace = repo_namespace
self.repo_name = repo_name
self.git_ref = git_ref
self.commit_sha = commit_sha
self.commit_sha_before = commit_sha_before
self.identifier = git_ref

@classmethod
def event_type(cls) -> str:
return "forgejo.push.Commit"
Loading
Loading