From f9a4dd36e458fa79d615d467b075ced6eac969c0 Mon Sep 17 00:00:00 2001 From: Austin Su Date: Thu, 22 Jul 2021 14:55:42 +0800 Subject: [PATCH] Update gitea-rocketchat.hooks.js Support x-gitea-event== issue_comment && action == reviewed / --- gitea-rocketchat.hooks.js | 56 +++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/gitea-rocketchat.hooks.js b/gitea-rocketchat.hooks.js index 46e5d06..125a678 100644 --- a/gitea-rocketchat.hooks.js +++ b/gitea-rocketchat.hooks.js @@ -225,30 +225,34 @@ const giteaEvents = { }, /* Comment on existing issues or pull request*/ issue_comment(request) { - const user = request.content.comment.user; + const user = request.content.sender; const repo = request.content.repository; const action = request.content.action; - - if (action == "created") { - // Do nothing - } else if (action == "edited") { - // Do nothing - } else if (action == "deleted") { - // Do nothing - } else { - return { - error: { - success: false, - message: 'Unsupported issue_comment action' - } - }; - } - - if (request.content.comment.pull_request_url) { + + if (action == "created" || action == "edited" || action == "deleted") { + var body = request.content.comment.body; + var number = request.content.issue.number; + var title = request.content.issue.title; + var url = request.content.comment.html_url; + if (request.content.comment.pull_request_url) { + var type = "pull request"; + + } else if (request.content.comment.issue_url) { + var type = "issue"; + } else { + return { + error: { + success: false, + message: 'Unsupported issue_comment action' + } + }; + } + } else if (action == "reviewed") { + var body = request.content.review.content; + var number = request.content.pull_request.number; + var title = request.content.pull_request.title; + var url = request.content.pull_request.url; var type = "pull request"; - } else if (request.content.comment.issue_url) { - - var type = "issue"; } else { return { error: { @@ -258,11 +262,11 @@ const giteaEvents = { }; } + + const text = - action.capitalizeFirstLetter() + ' comment on **[' + type + ' ​#' + request.content.issue.number + - ' - ' + request.content.issue.title + '](' + - request.content.comment.html_url + ')**' + ' at [' + repo.full_name + '](' + repo.html_url + ')\n\n'; - + action.capitalizeFirstLetter() + ' comment on **[' + type + ' ​#' + number + + ' - ' + title + '](' + url + ')**' + ' at [' + repo.full_name + '](' + repo.html_url + ')\n\n'; return { content: { @@ -271,7 +275,7 @@ const giteaEvents = { text: text, attachments: [ { - text: request.content.comment.body + text: body } ] }