From 8d443ebeb57b4f137236b38e33a1c9f538cf1566 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 8 Aug 2021 06:58:25 -0700 Subject: [PATCH] modules/web_hook: Handle issue comment. --- modules/web_hook.cc | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/modules/web_hook.cc b/modules/web_hook.cc index af0c4a172..3cbb93020 100644 --- a/modules/web_hook.cc +++ b/modules/web_hook.cc @@ -129,6 +129,10 @@ static bool github_handle__issue_comment(std::ostream &, const json::object &content); +static bool +github_handle__commit_comment(std::ostream &, + const json::object &content); + static bool github_handle__issues(std::ostream &, const json::object &content); @@ -232,6 +236,8 @@ github_handle(client &client, github_handle__issues(out, request.content): type == "issue_comment"? github_handle__issue_comment(out, request.content): + type == "commit_comment"? + github_handle__commit_comment(out, request.content): type == "watch"? github_handle__watch(out, request.content): type == "star"? @@ -1101,6 +1107,87 @@ github_handle__issue_comment(std::ostream &out, return true; } +bool +github_handle__commit_comment(std::ostream &out, + const json::object &content) +{ + const json::object comment + { + content["comment"] + }; + + const json::string action + { + content["action"] + }; + + const json::string commit + { + comment["commit_id"] + }; + + const json::string assoc + { + comment["author_association"] + }; + + char assoc_buf[32]; + if(assoc && assoc != "NONE") + out + << " [" + << tolower(assoc_buf, assoc) + << "]" + ; + + out << " "; + switch(hash(action)) + { + case "created"_: + out << "commented on"; + break; + + default: + out << action; + break; + } + out << ""; + + out << " " + << "" + << "" + << trunc(commit, 8) + << "" + << "" + ; + + if(action == "created") + { + out << " " + << "
" + ; + + const json::string body + { + comment["body"] + }; + + static const auto delim("\\r\\n"); + ircd::tokens(body, delim, [&out] + (const string_view &line) + { + out << line << "
"; + }); + + out << "" + << "
" + ; + } + + return true; +} + bool github_handle__label(std::ostream &out, const json::object &content)