From 3e31ccce5ce6e23c8d9fc2e27b572d08a7ea132a Mon Sep 17 00:00:00 2001 From: stupidcomputer Date: Wed, 9 Oct 2024 06:44:24 -0500 Subject: [PATCH] enable deletion of repos as well --- bridge/__init__.py | 67 +++++++++++++++++++++++----------------------- bridge/webgit.py | 8 ++++++ 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/bridge/__init__.py b/bridge/__init__.py index e6a272d..23c7ce1 100644 --- a/bridge/__init__.py +++ b/bridge/__init__.py @@ -48,41 +48,42 @@ def gitea_handle_repo_action(): except KeyError: abort(400) # the data isn't formatted correctly - if not repo_action == "created": + if repo_action == "created": + new_repo = github.create_repo( + repo_name, repo_description + ) + new_repo_url = new_repo.json()["html_url"] + + gitea.add_push_target( + repo_owner, repo_name, new_repo_url, repo_owner, + app.config["GITHUB_ACCESS_TOKEN"] + ) + gitea.force_push_target( + repo_owner, + repo_name + ) + + github.create_webhook( + repo_owner, + repo_name, + "https://{}/bridge/endpoints/github/issue".format( + app.config["GITEA_INSTANCE_DOMAIN"] + ), + ["issues", "issue_comment"] + ) + gitea.create_webhook( + repo_owner, + repo_name, + "https://{}/bridge/endpoints/gitea/issue".format( + app.config["GITEA_INSTANCE_DOMAIN"] + ), + ["issues", "issue_comment"] + ) + return '' + elif repo_action == "deleted": + github.delete_repo(repo_owner, repo_name) - new_repo = github.create_repo( - repo_name, repo_description - ) - new_repo_url = new_repo.json()["html_url"] - - gitea.add_push_target( - repo_owner, repo_name, new_repo_url, repo_owner, - app.config["GITHUB_ACCESS_TOKEN"] - ) - gitea.force_push_target( - repo_owner, - repo_name - ) - - github.create_webhook( - repo_owner, - repo_name, - "https://{}/bridge/endpoints/github/issue".format( - app.config["GITEA_INSTANCE_DOMAIN"] - ), - ["issues", "issue_comment"] - ) - gitea.create_webhook( - repo_owner, - repo_name, - "https://{}/bridge/endpoints/gitea/issue".format( - app.config["GITEA_INSTANCE_DOMAIN"] - ), - ["issues", "issue_comment"] - ) - - return '' @app.route("/bridge/endpoints/gitea/issue", methods=["POST"]) def gitea_handle_issue_action(): diff --git a/bridge/webgit.py b/bridge/webgit.py index 2d273ad..749396d 100644 --- a/bridge/webgit.py +++ b/bridge/webgit.py @@ -43,6 +43,9 @@ class WebgitClient: def patch(self, *args, **kwargs): return self._request_wrapper("PATCH", *args, **kwargs) + def delete(self, *args, **kwargs): + return self._request_wrapper("DELETE", *args, **kwargs) + def create_repo(self, name, description): return self.post( self.api_prefix + "/user/repos", @@ -104,6 +107,11 @@ class WebgitClient: }, ) + def delete_repo(self, owner, repo_name): + return self.delete( + self.api_prefix + "/repos/{}/{}".format(owner, repo_name) + ) + @dataclass class Github(WebgitClient): """