From 2f5ceb21d3c37917cd27408ef573905c6cb740df Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 3 May 2020 13:42:04 -0700 Subject: [PATCH] modules/web_hook: Support github gollum event. --- modules/web_hook.cc | 86 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/modules/web_hook.cc b/modules/web_hook.cc index 7f7f07898..1e06fb9d5 100644 --- a/modules/web_hook.cc +++ b/modules/web_hook.cc @@ -109,6 +109,10 @@ github_find_issue_number(const json::object &content); static std::pair github_find_party(const json::object &content); +static bool +github_handle__gollum(std::ostream &, + const json::object &content); + static bool github_handle__push(std::ostream &, const json::object &content); @@ -240,6 +244,8 @@ github_handle(client &client, github_handle__create(out, request.content): type == "delete"? github_handle__delete(out, request.content): + type == "gollum"? + github_handle__gollum(out, request.content): true // unhandled will just show heading }; @@ -349,6 +355,86 @@ github_heading(std::ostream &out, return out; } +bool +github_handle__gollum(std::ostream &out, + const json::object &content) +{ + const json::array pages + { + content["pages"] + }; + + const auto count + { + size(pages) + }; + + out + << " to " + << "" + << count + << "" + << " page" << (count != 1? "s" : "") + << ":" + ; + + for(const json::object &page : pages) + { + const json::string &action + { + page["action"] + }; + + const json::string sha + { + page["sha"] + }; + + out + << "
" + << "" + << sha.substr(0, 8) + << "" + << " " << action << " " + << "" + << "" + << json::string(page["title"]) + << "" + << "" + ; + + if(page["summary"] && page["summary"] != "null") + { + out + << " " + << "
" + << "
"
+			;
+
+			static const auto delim("\\r\\n");
+			const json::string body(page["summary"]);
+			auto lines(split(body, delim)); do
+			{
+				out
+				<< lines.first
+				<< "
" + ; + + lines = split(lines.second, delim); + } + while(!empty(lines.second)); + + out + << "" + << "
" + << "
" + ; + } + } + + return true; +} + bool github_handle__push(std::ostream &out, const json::object &content)