enable deletion of repos as well
This commit is contained in:
parent
3b0618d639
commit
3e31ccce5c
@ -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():
|
||||
|
@ -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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user