mirror of
https://github.com/matrix-construct/construct
synced 2024-10-05 07:08:53 +02: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 &,
|
github_handle(client &,
|
||||||
const resource::request &);
|
const resource::request &);
|
||||||
|
|
||||||
|
static void
|
||||||
|
appveyor_handle(client &,
|
||||||
|
const resource::request &);
|
||||||
|
|
||||||
resource::response
|
resource::response
|
||||||
post__webhook(client &client,
|
post__webhook(client &client,
|
||||||
const resource::request &request)
|
const resource::request &request)
|
||||||
|
@ -72,6 +76,9 @@ post__webhook(client &client,
|
||||||
if(has(http::headers(request.head.headers), "X-GitHub-Event"_sv))
|
if(has(http::headers(request.head.headers), "X-GitHub-Event"_sv))
|
||||||
github_handle(client, request);
|
github_handle(client, request);
|
||||||
|
|
||||||
|
else if(has(http::headers(request.head.headers), "X-Appveyor-Secret"_sv))
|
||||||
|
appveyor_handle(client, request);
|
||||||
|
|
||||||
return resource::response
|
return resource::response
|
||||||
{
|
{
|
||||||
client, http::OK
|
client, http::OK
|
||||||
|
@ -123,6 +130,10 @@ static std::ostream &
|
||||||
github_handle__organization(std::ostream &,
|
github_handle__organization(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
|
||||||
|
static std::ostream &
|
||||||
|
github_handle__status(std::ostream &,
|
||||||
|
const json::object &content);
|
||||||
|
|
||||||
static std::ostream &
|
static std::ostream &
|
||||||
github_handle__ping(std::ostream &,
|
github_handle__ping(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
@ -162,6 +173,10 @@ github_handle(client &client,
|
||||||
headers.at("X-GitHub-Delivery")
|
headers.at("X-GitHub-Delivery")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(type == "status")
|
||||||
|
if(unquote(request["state"]) == "pending")
|
||||||
|
return;
|
||||||
|
|
||||||
const unique_buffer<mutable_buffer> buf
|
const unique_buffer<mutable_buffer> buf
|
||||||
{
|
{
|
||||||
48_KiB
|
48_KiB
|
||||||
|
@ -188,6 +203,8 @@ github_handle(client &client,
|
||||||
github_handle__label(out, request.content);
|
github_handle__label(out, request.content);
|
||||||
else if(type == "organization")
|
else if(type == "organization")
|
||||||
github_handle__organization(out, request.content);
|
github_handle__organization(out, request.content);
|
||||||
|
else if(type == "status")
|
||||||
|
github_handle__status(out, request.content);
|
||||||
|
|
||||||
if(!string_view(webhook_room))
|
if(!string_view(webhook_room))
|
||||||
return;
|
return;
|
||||||
|
@ -427,7 +444,7 @@ github_handle__pull_request(std::ostream &out,
|
||||||
if(pr["merged"] == "true")
|
if(pr["merged"] == "true")
|
||||||
out << ' '
|
out << ' '
|
||||||
<< "<font color=\"#FFFFFF\""
|
<< "<font color=\"#FFFFFF\""
|
||||||
<< "data-mx-bg-color=\"#6f42c1\""
|
<< "data-mx-bg-color=\"#6f42c1\">"
|
||||||
<< "<b>"
|
<< "<b>"
|
||||||
<< "merged"
|
<< "merged"
|
||||||
<< "</b>"
|
<< "</b>"
|
||||||
|
@ -909,6 +926,55 @@ github_handle__organization(std::ostream &out,
|
||||||
return 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 &
|
std::ostream &
|
||||||
github_handle__watch(std::ostream &out,
|
github_handle__watch(std::ostream &out,
|
||||||
const json::object &content)
|
const json::object &content)
|
||||||
|
@ -1072,3 +1138,13 @@ catch(const crh::error &e)
|
||||||
http::NOT_IMPLEMENTED, "The signature algorithm is not supported.",
|
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