From 024452bbac36967e6e77c65cbe2e6c4b9ee18e2e Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 19 Nov 2019 12:22:46 +0000 Subject: [PATCH] expirental code to show comment content for github issue_comment webhooks --- modules/git_webhooks/github.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/git_webhooks/github.py b/modules/git_webhooks/github.py index cdf9016d..1a09f499 100644 --- a/modules/git_webhooks/github.py +++ b/modules/git_webhooks/github.py @@ -71,6 +71,7 @@ COMMENT_ACTIONS = { "edited": "edited a comment", "deleted": "deleted a comment" } +COMMENT_MAX = 100 CHECK_RUN_CONCLUSION = { "success": "passed", @@ -243,6 +244,16 @@ class GitHub(object): return outputs + def _comment(self, s): + s_line = utils.parse.line_normalise(s) + left, right = s_line[:COMMENT_MAX], s_line[COMMENT_MAX:] + if not right: + return left + else: + if " " in left: + left = left.rsplit(" ", 1)[0] + return "%s[...]" % left + def commit_comment(self, full_name, data): action = data["action"] commit = self._short_hash(data["comment"]["commit_id"]) @@ -370,9 +381,13 @@ class GitHub(object): type = "PR" if "pull_request" in data["issue"] else "issue" commenter = utils.irc.bold(data["sender"]["login"]) url = self._short_url(data["comment"]["html_url"]) - return ["[%s] %s %s on %s: %s - %s" % - (type, commenter, COMMENT_ACTIONS[action], number, issue_title, - url)] + + body = "" + if not action == "deleted": + body = ": %s" % self._comment(event["comment"]["body"]) + + return ["[%s] %s %s on %s%s - %s" % + (type, commenter, COMMENT_ACTIONS[action], number, body, url)] def create(self, full_name, data): ref = data["ref"]