mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 08:42:34 +01:00
modules/webhook: Add github status handler; add appveyor stub; fix merge font tag.
This commit is contained in:
parent
8f3d3fa200
commit
d4a17120fe
1 changed files with 77 additions and 1 deletions
|
@ -65,6 +65,10 @@ static void
|
|||
github_handle(client &,
|
||||
const resource::request &);
|
||||
|
||||
static void
|
||||
appveyor_handle(client &,
|
||||
const resource::request &);
|
||||
|
||||
resource::response
|
||||
post__webhook(client &client,
|
||||
const resource::request &request)
|
||||
|
@ -72,6 +76,9 @@ post__webhook(client &client,
|
|||
if(has(http::headers(request.head.headers), "X-GitHub-Event"_sv))
|
||||
github_handle(client, request);
|
||||
|
||||
else if(has(http::headers(request.head.headers), "X-Appveyor-Secret"_sv))
|
||||
appveyor_handle(client, request);
|
||||
|
||||
return resource::response
|
||||
{
|
||||
client, http::OK
|
||||
|
@ -123,6 +130,10 @@ static std::ostream &
|
|||
github_handle__organization(std::ostream &,
|
||||
const json::object &content);
|
||||
|
||||
static std::ostream &
|
||||
github_handle__status(std::ostream &,
|
||||
const json::object &content);
|
||||
|
||||
static std::ostream &
|
||||
github_handle__ping(std::ostream &,
|
||||
const json::object &content);
|
||||
|
@ -162,6 +173,10 @@ github_handle(client &client,
|
|||
headers.at("X-GitHub-Delivery")
|
||||
};
|
||||
|
||||
if(type == "status")
|
||||
if(unquote(request["state"]) == "pending")
|
||||
return;
|
||||
|
||||
const unique_buffer<mutable_buffer> buf
|
||||
{
|
||||
48_KiB
|
||||
|
@ -188,6 +203,8 @@ github_handle(client &client,
|
|||
github_handle__label(out, request.content);
|
||||
else if(type == "organization")
|
||||
github_handle__organization(out, request.content);
|
||||
else if(type == "status")
|
||||
github_handle__status(out, request.content);
|
||||
|
||||
if(!string_view(webhook_room))
|
||||
return;
|
||||
|
@ -427,7 +444,7 @@ github_handle__pull_request(std::ostream &out,
|
|||
if(pr["merged"] == "true")
|
||||
out << ' '
|
||||
<< "<font color=\"#FFFFFF\""
|
||||
<< "data-mx-bg-color=\"#6f42c1\""
|
||||
<< "data-mx-bg-color=\"#6f42c1\">"
|
||||
<< "<b>"
|
||||
<< "merged"
|
||||
<< "</b>"
|
||||
|
@ -909,6 +926,55 @@ github_handle__organization(std::ostream &out,
|
|||
return out;
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
github_handle__status(std::ostream &out,
|
||||
const json::object &content)
|
||||
{
|
||||
const json::string &state
|
||||
{
|
||||
content["state"]
|
||||
};
|
||||
|
||||
const json::string &description
|
||||
{
|
||||
content["description"]
|
||||
};
|
||||
|
||||
const string_view &url
|
||||
{
|
||||
content["target_url"]
|
||||
};
|
||||
|
||||
|
||||
if(state == "success")
|
||||
out << " "
|
||||
<< "<font data-mx-bg-color=\"#03B381\">"
|
||||
;
|
||||
|
||||
else if(state == "failure")
|
||||
out << " "
|
||||
<< "<font data-mx-bg-color=\"#CC0000\">"
|
||||
;
|
||||
|
||||
out << " "
|
||||
<< "<a href="
|
||||
<< url
|
||||
<< ">";
|
||||
|
||||
out << ""
|
||||
<< "<font color=\"#FFFFFF\">"
|
||||
<< "<b>"
|
||||
<< description
|
||||
<< "</b>"
|
||||
<< "</font>"
|
||||
<< "</a>"
|
||||
<< " "
|
||||
<< "</font>"
|
||||
;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
github_handle__watch(std::ostream &out,
|
||||
const json::object &content)
|
||||
|
@ -1072,3 +1138,13 @@ catch(const crh::error &e)
|
|||
http::NOT_IMPLEMENTED, "The signature algorithm is not supported.",
|
||||
};
|
||||
}
|
||||
|
||||
void
|
||||
appveyor_handle(client &client,
|
||||
const resource::request &request)
|
||||
{
|
||||
const http::headers &headers
|
||||
{
|
||||
request.head.headers
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue