0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-28 00:14:07 +01:00

modules/webhook: Improve find_party; use url of found party.

This commit is contained in:
Jason Volk 2019-01-20 13:57:15 -08:00
parent 20eceba930
commit be65ec7417

View file

@ -89,7 +89,7 @@ github_find_commit_hash(const json::object &content);
static string_view static string_view
github_find_issue_number(const json::object &content); github_find_issue_number(const json::object &content);
static string_view static std::pair<string_view, string_view>
github_find_party(const json::object &content); github_find_party(const json::object &content);
static std::ostream & static std::ostream &
@ -192,7 +192,7 @@ github_heading(std::ostream &out,
}; };
out << "<a href=\\\"" << unquote(repository["html_url"]) << "\\\">" out << "<a href=\\\"" << unquote(repository["html_url"]) << "\\\">"
<< "<b>" << unquote(repository["full_name"]) << "</b>" << unquote(repository["full_name"])
<< "</a>"; << "</a>";
const string_view commit_hash const string_view commit_hash
@ -203,7 +203,7 @@ github_heading(std::ostream &out,
if(commit_hash && type == "push") if(commit_hash && type == "push")
out << " <b><font color=\\\"#FF5733\\\">"; out << " <b><font color=\\\"#FF5733\\\">";
else if(commit_hash && type == "pull_request") else if(commit_hash && type == "pull_request")
out << " <b><font color=\\\"fuschia\\\">"; out << " <b><font color=\\\"#CC00CC\\\">";
else if(commit_hash) else if(commit_hash)
out << " <b>"; out << " <b>";
@ -221,13 +221,17 @@ github_heading(std::ostream &out,
else else
out << " " << type; out << " " << type;
const string_view party const auto party
{ {
github_find_party(content) github_find_party(content)
}; };
if(party) out << " by "
out << " by " << party; << "<a href=\\\""
<< party.second
<< "\\\">"
<< party.first
<< "</a>";
return out; return out;
} }
@ -249,7 +253,6 @@ github_handle__push(std::ostream &out,
if(!count) if(!count)
{ {
out << " <font color=\\\"#FF0000\\\">"; out << " <font color=\\\"#FF0000\\\">";
if(content["ref"]) if(content["ref"])
out << " " << unquote(content["ref"]); out << " " << unquote(content["ref"]);
@ -258,7 +261,12 @@ github_handle__push(std::ostream &out,
} }
if(content["ref"]) if(content["ref"])
out << " " << unquote(content["ref"]); {
const auto ref(unquote(content["ref"]));
out << " "
<< " "
<< token_last(ref, '/');
}
out << " <a href=\\\"" << unquote(content["compare"]) << "\\\">" out << " <a href=\\\"" << unquote(content["compare"]) << "\\\">"
<< "<b>" << count << " commits</b>" << "<b>" << count << " commits</b>"
@ -282,9 +290,14 @@ github_handle__push(std::ostream &out,
const json::object committer(commit["committer"]); const json::object committer(commit["committer"]);
if(committer["email"] != author["email"]) if(committer["email"] != author["email"])
out << " via " << committer["name"]; out << " via " << unquote(committer["name"]);
const auto message(unquote(commit["message"]));
const auto summary
{
split(message, "\\n").first
};
const auto summary(token(unquote(commit["message"]), '\n', 0));
out << " <u>" out << " <u>"
<< summary << summary
<< "</u>"; << "</u>";
@ -308,18 +321,36 @@ github_handle__ping(std::ostream &out,
} }
/// Researched from yestifico bot /// Researched from yestifico bot
static string_view static std::pair<string_view, string_view>
github_find_party(const json::object &content) github_find_party(const json::object &content)
{ {
const json::object pusher(content["pusher"]); const json::object pull_request
if(!empty(pusher)) {
return unquote(pusher["name"]); content["pull_request"]
};
const json::object sender(content["sender"]); const json::object user
if(!empty(sender)) {
return unquote(sender["login"]); pull_request["user"]
};
return {}; if(!empty(user))
return
{
unquote(user["login"]),
unquote(user["html_url"])
};
const json::object sender
{
content["sender"]
};
return
{
unquote(sender["login"]),
unquote(sender["html_url"])
};
} }
/// Researched from yestifico bot /// Researched from yestifico bot