Skip to content
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

feat: handle the uninstall action #572

Merged
merged 1 commit into from
Dec 6, 2024
Merged
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
11 changes: 10 additions & 1 deletion server/core/dao/repositoryConfigDAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,13 @@
return None
repo_configs = [RepositoryConfig(**repo) for repo in response.data]

return repo_configs
return repo_configs

Check warning on line 81 in server/core/dao/repositoryConfigDAO.py

View check run for this annotation

Codecov / codecov/patch

server/core/dao/repositoryConfigDAO.py#L81

Added line #L81 was not covered by tests

def delete_by_repo_ids(self, repo_ids: list):
response = (
self.client.table("github_repo_config")
.delete()
.in_("repo_id", repo_ids)
.execute()
)
return response
31 changes: 31 additions & 0 deletions server/event_handler/intsall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import Any
from github import Github, Auth
from github import GithubException
from core.dao.repositoryConfigDAO import RepositoryConfigDAO


class InstallEventHandler:
event: Any
auth: Auth.AppAuth
g: Github

def __init__(self, payload: Any, auth: Auth.AppAuth, installation_id: int) -> None:
self.event: Any = payload
self.auth: Auth.AppAuth = auth
self.g: Github = Github(auth=auth)

def delete_config(self):
repositories = self.event["repositories"]
repo_ids = [str(repo["id"]) for repo in repositories]
repository_config = RepositoryConfigDAO()
repository_config.delete_by_repo_ids(repo_ids)

async def execute(self):
try:
action = self.event["action"]
if action == "deleted":
self.delete_config()
return {"success": True}
except GithubException as e:
print(f"处理 GitHub 请求时出错:{e}")
xingwanying marked this conversation as resolved.
Show resolved Hide resolved
return {"success": False, "error": str(e)}
7 changes: 5 additions & 2 deletions server/github_app/handlers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union

from event_handler.intsall import InstallEventHandler
from petercat_utils import get_env_variable
from github import Auth

Expand All @@ -25,6 +26,7 @@
DiscussionEventHandler,
DiscussionCommentEventHandler,
PullRequestReviewCommentEventHandler,
InstallEventHandler,
None,
]:
handlers = {
Expand All @@ -33,8 +35,9 @@
"issue_comment": IssueCommentEventHandler,
"discussion": DiscussionEventHandler,
"discussion_comment": DiscussionCommentEventHandler,
"pull_request_review_comment":PullRequestReviewCommentEventHandler,
"pull_request_review":PullRequestReviewCommentEventHandler,
"pull_request_review_comment": PullRequestReviewCommentEventHandler,
"pull_request_review": PullRequestReviewCommentEventHandler,

Check warning on line 39 in server/github_app/handlers.py

View check run for this annotation

Codecov / codecov/patch

server/github_app/handlers.py#L39

Added line #L39 was not covered by tests
"installation": InstallEventHandler,
}
return (
handlers.get(event)(payload=payload, auth=auth, installation_id=installation_id)
Expand Down
Loading