-
Notifications
You must be signed in to change notification settings - Fork 59
Implement events support for Forgejo #2852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mynk8
wants to merge
7
commits into
packit:main
Choose a base branch
from
mynk8:rebase/forgejo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fb9033f
Implement Forgejo event handling in Packit Service
mynk8 c975387
test(data): add Forgejo webhooks for tests
mfocko 7182065
include unit tests for forgejo event; fixes
mynk8 22e5ab6
Merge branch 'main' into rebase/forgejo
mynk8 85cbebd
Merge branch 'main' into rebase/forgejo
mynk8 e2278a3
use fedora-messaging for forgejo events
mynk8 19bab6f
Merge branch 'main' into rebase/forgejo
mynk8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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__] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
😄