Compare commits
2 Commits
e9c532b218
...
5c56b2ca29
Author | SHA1 | Date |
---|---|---|
stupidcomputer | 5c56b2ca29 | |
stupidcomputer | 3e68945bfc |
|
@ -6,7 +6,7 @@ from flask import abort
|
|||
import requests
|
||||
|
||||
from .webgit import Gitea, Github
|
||||
from .utils import issue_sentinel, generate_sentinel
|
||||
from .utils import issue_sentinel, generate_sentinel, create_signature
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_envvar('GIT_BRIDGE_SETTINGS')
|
||||
|
@ -79,10 +79,11 @@ def gitea_handle_repo_action():
|
|||
["issues", "issue_comment"]
|
||||
)
|
||||
|
||||
return ''
|
||||
elif repo_action == "deleted":
|
||||
github.delete_repo(repo_owner, repo_name)
|
||||
|
||||
return ''
|
||||
|
||||
|
||||
@app.route("/bridge/endpoints/gitea/issue", methods=["POST"])
|
||||
def gitea_handle_issue_action():
|
||||
|
@ -142,22 +143,14 @@ def gitea_handle_issue_action():
|
|||
return ''
|
||||
|
||||
if event_type == "opened":
|
||||
issue_header = "*This issue has automatically been created by [`gitea-github-sync`](https://{}/bridge/about) on behalf of [{}]({}).*".format(
|
||||
app.config["GITEA_INSTANCE_DOMAIN"],
|
||||
issue_footer = create_signature(
|
||||
issue_user,
|
||||
issue_user_url,
|
||||
app.config["GITEA_INSTANCE_DOMAIN"],
|
||||
event_url,
|
||||
)
|
||||
|
||||
issue_footer = """
|
||||
<details>
|
||||
<summary>Internal issue metadata</summary>
|
||||
|
||||
{}
|
||||
</details>
|
||||
""".format(generate_sentinel(event_url))
|
||||
|
||||
issue_body = "\n\n".join([
|
||||
issue_header,
|
||||
event_body,
|
||||
issue_footer
|
||||
])
|
||||
|
@ -168,25 +161,20 @@ def gitea_handle_issue_action():
|
|||
event_title,
|
||||
issue_body,
|
||||
)
|
||||
|
||||
returned_data = new_issue.json()
|
||||
issue_comment_body = """
|
||||
*This issue is being mirrored on Github [here]({}).*
|
||||
|
||||
<details>
|
||||
<summary>Internal issue metadata</summary>
|
||||
|
||||
{}
|
||||
</details>
|
||||
""".format(
|
||||
issue_comment_body = create_signature(
|
||||
"mirrored",
|
||||
returned_data["html_url"],
|
||||
generate_sentinel(returned_data["url"])
|
||||
app.config["GITEA_INSTANCE_DOMAIN"],
|
||||
returned_data["url"],
|
||||
)
|
||||
|
||||
gitea.leave_comment_on_issue_by_number(
|
||||
repo_owner,
|
||||
repo_name,
|
||||
issue_number,
|
||||
body,
|
||||
issue_comment_body,
|
||||
)
|
||||
|
||||
elif event_type == "created":
|
||||
|
@ -195,22 +183,13 @@ def gitea_handle_issue_action():
|
|||
app.config["GITEA_INSTANCE_DOMAIN"],
|
||||
comment_user,
|
||||
)
|
||||
comment_header = "*This comment has automatically been created by [`gitea-github-sync`](https://{}/bridge/about) on behalf of [{}]({}).*".format(
|
||||
app.config["GITEA_INSTANCE_DOMAIN"],
|
||||
comment_footer = create_signature(
|
||||
comment_user,
|
||||
comment_user_url,
|
||||
app.config["GITEA_INSTANCE_DOMAIN"],
|
||||
event_url,
|
||||
)
|
||||
|
||||
comment_footer = """
|
||||
<details>
|
||||
<summary>Internal issue metadata</summary>
|
||||
|
||||
{}
|
||||
</details>
|
||||
""".format(generate_sentinel(event_url))
|
||||
|
||||
comment_body = "\n\n".join([
|
||||
comment_header,
|
||||
event_body,
|
||||
comment_footer,
|
||||
])
|
||||
|
@ -219,11 +198,11 @@ def gitea_handle_issue_action():
|
|||
repo_owner,
|
||||
repo_name,
|
||||
issue_number,
|
||||
body,
|
||||
comment_body,
|
||||
)
|
||||
|
||||
elif event_type == "closed":
|
||||
github_close_issue_result = github.close_issue_by_number(
|
||||
github.close_issue_by_number(
|
||||
repo_owner,
|
||||
repo_name,
|
||||
issue_number,
|
||||
|
@ -273,22 +252,13 @@ def github_handle_issue_action():
|
|||
return ''
|
||||
|
||||
if event_type == "opened":
|
||||
issue_header = "*This issue has automatically been created by [`gitea-github-sync`](https://{}/bridge/about) on behalf of [{}]({}).*".format(
|
||||
app.config["GITEA_INSTANCE_DOMAIN"],
|
||||
issue_footer = create_signature(
|
||||
issue_user,
|
||||
issue_user_url,
|
||||
app.config["GITEA_INSTANCE_DOMAIN"],
|
||||
event_url,
|
||||
)
|
||||
|
||||
issue_footer = """
|
||||
<details>
|
||||
<summary>Internal issue metadata</summary>
|
||||
|
||||
{}
|
||||
</details>
|
||||
""".format(generate_sentinel(event_url))
|
||||
|
||||
issue_body = "\n\n".join([
|
||||
issue_header,
|
||||
event_body,
|
||||
issue_footer
|
||||
])
|
||||
|
@ -305,27 +275,18 @@ def github_handle_issue_action():
|
|||
comment_user_url = "https://github.com/{}".format(
|
||||
comment_user,
|
||||
)
|
||||
comment_header = "*This comment has automatically been created by [`gitea-github-sync`](https://{}/bridge/about) on behalf of [{}]({}).*".format(
|
||||
app.config["GITEA_INSTANCE_DOMAIN"],
|
||||
comment_footer = create_signature(
|
||||
comment_user,
|
||||
comment_user_url,
|
||||
app.config["GITEA_INSTANCE_DOMAIN"],
|
||||
event_url,
|
||||
)
|
||||
|
||||
comment_footer = """
|
||||
<details>
|
||||
<summary>Internal issue metadata</summary>
|
||||
|
||||
{}
|
||||
</details>
|
||||
""".format(generate_sentinel(event_url))
|
||||
|
||||
comment_body = "\n\n".join([
|
||||
comment_header,
|
||||
event_body,
|
||||
comment_footer,
|
||||
])
|
||||
|
||||
|
||||
gitea.leave_comment_on_issue_by_number(
|
||||
repo_owner,
|
||||
repo_name,
|
||||
|
|
|
@ -14,3 +14,27 @@ issue_sentinel = "GITEA_GITHUB_ISSUE_SYNC_SENTINEL"
|
|||
|
||||
def generate_sentinel(url: str) -> str:
|
||||
return ' '.join([issue_sentinel, to_base64(url)])
|
||||
|
||||
def create_signature(
|
||||
username: str,
|
||||
username_url: str,
|
||||
domain_base: str,
|
||||
url_to_encode: str,
|
||||
):
|
||||
return """
|
||||
|
||||
---
|
||||
|
||||
[{}]({}) via [gitea-github-sync](https://{}/bridge/about)
|
||||
|
||||
<details>
|
||||
<summary>Internal information</summary>
|
||||
|
||||
{}
|
||||
</details>
|
||||
""".format(
|
||||
username,
|
||||
username_url,
|
||||
domain_base,
|
||||
generate_sentinel(url_to_encode),
|
||||
)
|
|
@ -183,11 +183,11 @@ class Gitea(WebgitClient):
|
|||
repo_name,
|
||||
),
|
||||
json={
|
||||
"active": True,
|
||||
"config": {
|
||||
"url": http_endpoint,
|
||||
"content_type": "json",
|
||||
},
|
||||
"active": True,
|
||||
"events": events,
|
||||
"type": "gitea",
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue