mirror of
https://github.com/plankanban/planka.git
synced 2025-07-21 06:09:43 +02:00
feat: Webhooks configuration, all events support, refactoring
This commit is contained in:
parent
3779bdb053
commit
c065566c15
96 changed files with 1280 additions and 509 deletions
|
@ -14,21 +14,21 @@ const valuesValidator = (value) => {
|
|||
return true;
|
||||
};
|
||||
|
||||
const buildAndSendSlackMessage = async (user, card, action) => {
|
||||
const buildAndSendSlackMessage = async (card, action, actorUser) => {
|
||||
const cardLink = `<${sails.config.custom.baseUrl}/cards/${card.id}|${card.name}>`;
|
||||
|
||||
let markdown;
|
||||
switch (action.type) {
|
||||
case Action.Types.CREATE_CARD:
|
||||
markdown = `${cardLink} was created by ${user.name} in *${action.data.list.name}*`;
|
||||
markdown = `${cardLink} was created by ${actorUser.name} in *${action.data.list.name}*`;
|
||||
|
||||
break;
|
||||
case Action.Types.MOVE_CARD:
|
||||
markdown = `${cardLink} was moved by ${user.name} to *${action.data.toList.name}*`;
|
||||
markdown = `${cardLink} was moved by ${actorUser.name} to *${action.data.toList.name}*`;
|
||||
|
||||
break;
|
||||
case Action.Types.COMMENT_CARD:
|
||||
markdown = `*${user.name}* commented on ${cardLink}:\n>${action.data.text}`;
|
||||
markdown = `*${actorUser.name}* commented on ${cardLink}:\n>${action.data.text}`;
|
||||
|
||||
break;
|
||||
default:
|
||||
|
@ -45,10 +45,18 @@ module.exports = {
|
|||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
|
@ -72,6 +80,24 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'actionCreate',
|
||||
data: {
|
||||
item: action,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [values.card],
|
||||
},
|
||||
},
|
||||
user: values.user,
|
||||
});
|
||||
|
||||
if (sails.config.custom.slackBotToken) {
|
||||
buildAndSendSlackMessage(values.card, action, values.user);
|
||||
}
|
||||
|
||||
const subscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
|
||||
action.cardId,
|
||||
action.userId,
|
||||
|
@ -84,26 +110,15 @@ module.exports = {
|
|||
userId,
|
||||
action,
|
||||
},
|
||||
user: values.user,
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
card: values.card,
|
||||
actorUser: values.user,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
if (sails.config.custom.slackBotToken) {
|
||||
buildAndSendSlackMessage(values.user, values.card, action);
|
||||
}
|
||||
|
||||
await sails.helpers.utils.sendWebhook.with({
|
||||
event: 'ACTION_CREATE',
|
||||
data: action,
|
||||
projectId: inputs.board.projectId,
|
||||
user: inputs.request.currentUser,
|
||||
card: values.card,
|
||||
board: inputs.board,
|
||||
});
|
||||
|
||||
return action;
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue