Update gitea-rocketchat.hooks.js

Support x-gitea-event== issue_comment &&  action == reviewed /
This commit is contained in:
Austin Su 2021-07-22 14:55:42 +08:00 committed by GitHub
parent 5e750a6556
commit f9a4dd36e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -225,29 +225,19 @@ const giteaEvents = {
}, },
/* Comment on existing issues or pull request*/ /* Comment on existing issues or pull request*/
issue_comment(request) { issue_comment(request) {
const user = request.content.comment.user; const user = request.content.sender;
const repo = request.content.repository; const repo = request.content.repository;
const action = request.content.action; const action = request.content.action;
if (action == "created") { if (action == "created" || action == "edited" || action == "deleted") {
// Do nothing var body = request.content.comment.body;
} else if (action == "edited") { var number = request.content.issue.number;
// Do nothing var title = request.content.issue.title;
} else if (action == "deleted") { var url = request.content.comment.html_url;
// Do nothing
} else {
return {
error: {
success: false,
message: 'Unsupported issue_comment action'
}
};
}
if (request.content.comment.pull_request_url) { if (request.content.comment.pull_request_url) {
var type = "pull request"; var type = "pull request";
} else if (request.content.comment.issue_url) {
} else if (request.content.comment.issue_url) {
var type = "issue"; var type = "issue";
} else { } else {
return { return {
@ -257,12 +247,26 @@ const giteaEvents = {
} }
}; };
} }
} 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 {
return {
error: {
success: false,
message: 'Unsupported issue_comment action'
}
};
}
const text = const text =
action.capitalizeFirstLetter() + ' comment on **[' + type + ' #' + request.content.issue.number + action.capitalizeFirstLetter() + ' comment on **[' + type + ' #' + number +
' - ' + request.content.issue.title + '](' + ' - ' + title + '](' + url + ')**' + ' at [' + repo.full_name + '](' + repo.html_url + ')\n\n';
request.content.comment.html_url + ')**' + ' at [' + repo.full_name + '](' + repo.html_url + ')\n\n';
return { return {
content: { content: {
@ -271,7 +275,7 @@ const giteaEvents = {
text: text, text: text,
attachments: [ attachments: [
{ {
text: request.content.comment.body text: body
} }
] ]
} }