0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

modules/web_hook: Support github gollum event.

This commit is contained in:
Jason Volk 2020-05-03 13:42:04 -07:00
parent 77a8a3e3c9
commit 2f5ceb21d3

View file

@ -109,6 +109,10 @@ github_find_issue_number(const json::object &content);
static std::pair<json::string, json::string>
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 "
<< "<b>"
<< count
<< "</b>"
<< " page" << (count != 1? "s" : "")
<< ":"
;
for(const json::object &page : pages)
{
const json::string &action
{
page["action"]
};
const json::string sha
{
page["sha"]
};
out
<< "<br />"
<< "<b>"
<< sha.substr(0, 8)
<< "</b>"
<< " " << action << " "
<< "<a href=" << page["html_url"] << ">"
<< "<b>"
<< json::string(page["title"])
<< "</b>"
<< "</a>"
;
if(page["summary"] && page["summary"] != "null")
{
out
<< " "
<< "<blockquote>"
<< "<pre><code>"
;
static const auto delim("\\r\\n");
const json::string body(page["summary"]);
auto lines(split(body, delim)); do
{
out
<< lines.first
<< "<br />"
;
lines = split(lines.second, delim);
}
while(!empty(lines.second));
out
<< ""
<< "</code></pre>"
<< "</blockquote>"
;
}
}
return true;
}
bool
github_handle__push(std::ostream &out,
const json::object &content)