From d4a17120fea84602743af3125b93f375b8472411 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 4 Apr 2019 00:47:02 -0700 Subject: [PATCH] modules/webhook: Add github status handler; add appveyor stub; fix merge font tag. --- modules/webhook.cc | 78 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/modules/webhook.cc b/modules/webhook.cc index a60ebbc97..d84c991e7 100644 --- a/modules/webhook.cc +++ b/modules/webhook.cc @@ -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 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 << ' ' << "" << "" << "merged" << "" @@ -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 << " " + << "" + ; + + else if(state == "failure") + out << " " + << "" + ; + + out << " " + << ""; + + out << "" + << "" + << "" + << description + << "" + << "" + << "" + << " " + << "" + ; + + 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 + }; +}