From 7904fa0563fb708ca39fd14079d8cb8cef6a3db6 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 10 Apr 2023 01:05:27 -0700 Subject: [PATCH] modules/webhook: Render markdown to html for dependabot alerts. --- modules/web_hook.cc | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/modules/web_hook.cc b/modules/web_hook.cc index 78b3c2b82..c2a66eb13 100644 --- a/modules/web_hook.cc +++ b/modules/web_hook.cc @@ -452,6 +452,10 @@ github_heading(std::ostream &out, return out; } +static string_view +github_markdown(unique_const_buffer &buf, + const string_view &text); + bool github_handle__dependabot_alert(std::ostream &out, const json::object &content) @@ -495,19 +499,17 @@ github_handle__dependabot_alert(std::ostream &out, << " 🚨
" ; - out - << "
" - ; - - static const auto delim("\\n"); - ircd::tokens(desc, delim, [&out] - (const string_view &line) + unique_const_buffer buf; + const string_view markup { - out << line << "
"; - }); + github_markdown(buf, desc) + }; out - << "
" + //<< "
" + << markup + //<< "
" + << "
" ; if(path) @@ -828,6 +830,24 @@ github_request(unique_const_buffer &out, return github_request(content, out, method, repo, fmt, std::forward(a)...); } +static string_view +github_markdown(unique_const_buffer &buf, + const string_view &text) +{ + const json::strung content + { + json::members + { + { "text", text } + } + }; + + return _github_request + ( + buf, "POST", "https://api.github.com/markdown", content + ); +} + static bool github_run_for_each_jobs(const string_view &repo, const string_view &run_id,