From 96ce15b4d9e47b14b0050893fdec69e65cd71e5e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 2 Apr 2019 10:31:50 -0700 Subject: [PATCH] modules/webhook: Improve pull request formatting. --- modules/webhook.cc | 195 +++++++++++++++++++++++++++++++-------------- 1 file changed, 133 insertions(+), 62 deletions(-) diff --git a/modules/webhook.cc b/modules/webhook.cc index b19a4afd8..a60ebbc97 100644 --- a/modules/webhook.cc +++ b/modules/webhook.cc @@ -259,7 +259,7 @@ github_heading(std::ostream &out, if(commit_hash && type == "push") out << " "; else if(commit_hash && type == "pull_request") - out << " "; + out << " "; else if(commit_hash) out << " "; @@ -388,13 +388,50 @@ github_handle__pull_request(std::ostream &out, << "" ; + if(pr["title"]) + out << " " + << "" + << unquote(pr["title"]) + << "" + ; + + const json::object head + { + pr["head"] + }; + + const json::object base + { + pr["base"] + }; + + for(const json::object &label : json::array(pr["labels"])) + { + out << " "; + out << ""; + + out << ""; + out << " "; + out << unquote(label["name"]); + out << " "; + out << ""; + + out << ""; + } + if(pr["merged"] == "true") out << ' ' + << "" - << "" << "merged" - << "" << "" + << "" ; if(pr.has("merged_by") && pr["merged_by"] != "null") @@ -410,39 +447,57 @@ github_handle__pull_request(std::ostream &out, ; } - if(pr["merged"] == "false") switch(hash(pr["mergeable"])) + const json::string &body { - default: - case hash("null"): - out << " / " - << "" - << "" - << "CHECKING MERGE" - << "" - << "" - ; - break; + pr["body"] + }; - case hash("true"): - out << " / " - << "" - << "" - << "MERGEABLE" - << "" - << "" - ; - break; + if(!empty(body)) + out << " " + << "
"
+		    << body
+		    << "
" + ; - case hash("false"): - out << " / " - << "" - << "" - << "MERGE CONFLICT" - << "" - << "" - ; - break; - } + if(pr.has("commits")) + out << " " + << "" + << pr["commits"] + << ' ' + << "" + << "commits" + << "" + << "" + ; + + if(pr.has("comments")) + out << " / " + << "" + << pr["comments"] + << ' ' + << "" + << "comments" + << "" + << "" + ; + + if(pr.has("changed_files")) + out << " / " + << "" + << pr["changed_files"] + << ' ' + << "" + << "files" + << "" + << "" + ; if(pr.has("additions")) out << " / " @@ -464,37 +519,48 @@ github_handle__pull_request(std::ostream &out, << "
" ; - if(pr.has("changed_files")) - out << " / " - << "" - << pr["changed_files"] - << ' ' - << "" - << "files" - << "" - << "" - ; - - const json::object head + if(pr["merged"] == "false") switch(hash(pr["mergeable"])) { - pr["head"] - }; + default: + case hash("null"): + out << " / " + << "" + << "" + << " " + << "CHECKING" + << " " + << "" + << "" + ; + break; - out << " " - << "
"
-	    << ""
-	    << ""
-	    << unquote(head["sha"]).substr(0, 8)
-	    << ""
-	    << ""
-	    << " "
-	    << ""
-	    << unquote(pr["title"])
-	    << ""
-	    << "
" - ; + case hash("true"): + out << " / " + << "" + << "" + << " " + << "NO CONFLICTS" + << " " + << "" + << "" + ; + break; + + case hash("false"): + out << " / " + << "" + << "" + << " " + << "MERGE CONFLICT" + << " " + << "" + << "" + ; + break; + } return out; } @@ -945,6 +1011,11 @@ github_find_commit_hash(const json::object &content) if(content["commit"]) return unquote(content["commit"]); + const json::object pr{content["pull_request"]}; + const json::object prhead{pr["head"]}; + if(prhead["sha"]) + return unquote(prhead["sha"]); + return {}; }