webhooks/git: use markdown for tracker comments

The raw body of comments is included in email notifications. HTML makes
ugly plain text messages.

Use markdown for generated tracker comments which can be used in plain
text emails as-is.

Fixes: https://todo.sr.ht/~sircmpwn/hub.sr.ht/77
Fixes: be5d50d8d8 ("webhooks: update todo tickets with git commits")
Signed-off-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Robin Jarry 2021-11-29 14:55:54 +01:00 committed by Drew DeVault
parent be5d50d8d8
commit b5ebc44032
1 changed files with 6 additions and 4 deletions

View File

@ -143,16 +143,18 @@ def _handle_commit_trailer(trailer, value, pusher, repo, commit):
commit_author = html.escape(commit["author"]["name"].strip())
commit_sha = commit["id"][:7]
commit_url = repo.url() + f"/commit/{commit_sha}"
comment = (
f"<i>{commit_author} referenced this ticket in commit " +
f"<a href='{commit_url}' title='{commit_message}'>{commit_sha}</a>.</i>")
comment = f"""\
*{commit_author} referenced this ticket in commit [{commit_sha}].*
[{commit_sha}]: {commit_url} "{commit_message}"\
"""
try:
todo.update_ticket(
user=pusher,
owner=match["owner"],
tracker=match["tracker"],
ticket=int(match["ticket"]),
comment=" ".join(comment.split()).strip(),
comment=comment,
resolution=resolution,
)
except Exception: