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

modules/webhook: Add github issues handler.

This commit is contained in:
Jason Volk 2019-01-22 15:30:49 -08:00
parent 79dc0955b4
commit e491cf5694

View file

@ -100,6 +100,10 @@ static std::ostream &
github_handle__pull_request(std::ostream &,
const json::object &content);
static std::ostream &
github_handle__issues(std::ostream &,
const json::object &content);
static std::ostream &
github_handle__ping(std::ostream &,
const json::object &content);
@ -155,6 +159,8 @@ github_handle(client &client,
github_handle__push(out, request.content);
else if(type == "pull_request")
github_handle__pull_request(out, request.content);
else if(type == "issues")
github_handle__issues(out, request.content);
if(!string_view(webhook_room))
return;
@ -442,6 +448,81 @@ github_handle__pull_request(std::ostream &out,
return out;
}
static std::ostream &
github_handle__issues(std::ostream &out,
const json::object &content)
{
out << " "
<< "<b>"
<< unquote(content["action"])
<< "</b>"
;
const json::object issue
{
content["issue"]
};
switch(hash(unquote(content["action"])))
{
case "assigned"_:
case "unassigned"_:
{
const json::object assignee
{
content["assignee"]
};
out << " "
<< "<a href=\""
<< unquote(assignee["html_url"])
<< "\">"
<< unquote(assignee["login"])
<< "</a>"
;
break;
}
}
out << " "
<< "<a href=\""
<< unquote(issue["html_url"])
<< "\">"
<< "<b><u>"
<< unquote(issue["title"])
<< "</u></b>"
<< "</a>"
;
if(unquote(content["action"]) == "opened")
{
out << " "
<< "<blockquote>"
<< "<pre>"
;
static const auto delim("\\r\\n");
const auto body(unquote(issue["body"]));
auto lines(split(body, delim)); do
{
out << lines.first
<< "<br />"
;
lines = split(lines.second, delim);
}
while(!empty(lines.second));
out << ""
<< "</pre>"
<< "</blockquote>"
;
}
return out;
}
static std::ostream &
github_handle__ping(std::ostream &out,
const json::object &content)