enable deletion of repos as well

This commit is contained in:
stupidcomputer 2024-10-09 06:44:24 -05:00
parent 67314c71cf
commit 82ce1c7f6d
2 changed files with 42 additions and 33 deletions

View File

@ -47,41 +47,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():

View File

@ -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):
"""