mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
ref: Refactoring
This commit is contained in:
parent
cc95032e74
commit
38bc4cb0a0
7 changed files with 53 additions and 39 deletions
|
@ -68,11 +68,13 @@ services:
|
||||||
# - SLACK_BOT_TOKEN=
|
# - SLACK_BOT_TOKEN=
|
||||||
# - SLACK_CHANNEL_ID=
|
# - SLACK_CHANNEL_ID=
|
||||||
|
|
||||||
|
# - GOOGLE_CHAT_WEBHOOK_URL=
|
||||||
|
|
||||||
# - TELEGRAM_BOT_TOKEN=
|
# - TELEGRAM_BOT_TOKEN=
|
||||||
# - TELEGRAM_CHAT_ID=
|
# - TELEGRAM_CHAT_ID=
|
||||||
# - TELEGRAM_THREAD_ID=
|
# - TELEGRAM_THREAD_ID=
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
command: ['sh', '-c', 'npm run start']
|
command: ["sh", "-c", "npm run start"]
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
@ -105,7 +107,7 @@ services:
|
||||||
# - DEFAULT_ADMIN_NAME=Demo Demo
|
# - DEFAULT_ADMIN_NAME=Demo Demo
|
||||||
# - DEFAULT_ADMIN_USERNAME=demo
|
# - DEFAULT_ADMIN_USERNAME=demo
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
command: ['sh', '-c', 'npm run db:init']
|
command: ["sh", "-c", "npm run db:init"]
|
||||||
volumes:
|
volumes:
|
||||||
- ./server:/app
|
- ./server:/app
|
||||||
- /app/node_modules
|
- /app/node_modules
|
||||||
|
@ -122,10 +124,10 @@ services:
|
||||||
POSTGRES_USER: user
|
POSTGRES_USER: user
|
||||||
POSTGRES_PASSWORD: password
|
POSTGRES_PASSWORD: password
|
||||||
ports:
|
ports:
|
||||||
- '5432:5432'
|
- "5432:5432"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ['CMD-SHELL', 'pg_isready -U user -d planka_db']
|
test: ["CMD-SHELL", "pg_isready -U user -d planka_db"]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
@ -133,7 +135,7 @@ services:
|
||||||
proxy:
|
proxy:
|
||||||
image: nginx:alpine
|
image: nginx:alpine
|
||||||
ports:
|
ports:
|
||||||
- '3000:80'
|
- "3000:80"
|
||||||
volumes:
|
volumes:
|
||||||
- ./config/development/nginx.conf:/etc/nginx/nginx.conf
|
- ./config/development/nginx.conf:/etc/nginx/nginx.conf
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|
|
@ -74,6 +74,7 @@ services:
|
||||||
|
|
||||||
# - SLACK_BOT_TOKEN=
|
# - SLACK_BOT_TOKEN=
|
||||||
# - SLACK_CHANNEL_ID=
|
# - SLACK_CHANNEL_ID=
|
||||||
|
|
||||||
# - GOOGLE_CHAT_WEBHOOK_URL=
|
# - GOOGLE_CHAT_WEBHOOK_URL=
|
||||||
|
|
||||||
# - TELEGRAM_BOT_TOKEN=
|
# - TELEGRAM_BOT_TOKEN=
|
||||||
|
@ -92,7 +93,7 @@ services:
|
||||||
- POSTGRES_DB=planka
|
- POSTGRES_DB=planka
|
||||||
- POSTGRES_HOST_AUTH_METHOD=trust
|
- POSTGRES_HOST_AUTH_METHOD=trust
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ['CMD-SHELL', 'pg_isready -U postgres -d planka']
|
test: ["CMD-SHELL", "pg_isready -U postgres -d planka"]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|
|
@ -65,13 +65,13 @@ SECRET_KEY=notsecretkey
|
||||||
|
|
||||||
# SLACK_BOT_TOKEN=
|
# SLACK_BOT_TOKEN=
|
||||||
# SLACK_CHANNEL_ID=
|
# SLACK_CHANNEL_ID=
|
||||||
|
|
||||||
# GOOGLE_CHAT_WEBHOOK_URL=
|
# GOOGLE_CHAT_WEBHOOK_URL=
|
||||||
|
|
||||||
# TELEGRAM_BOT_TOKEN=
|
# TELEGRAM_BOT_TOKEN=
|
||||||
# TELEGRAM_CHAT_ID=
|
# TELEGRAM_CHAT_ID=
|
||||||
# TELEGRAM_THREAD_ID=
|
# TELEGRAM_THREAD_ID=
|
||||||
|
|
||||||
|
|
||||||
## Do not edit this
|
## Do not edit this
|
||||||
|
|
||||||
TZ=UTC
|
TZ=UTC
|
||||||
|
|
|
@ -14,7 +14,10 @@ const valuesValidator = (value) => {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildAndSendMessage = async (card, action, actorUser, send) => {
|
const truncateString = (string, maxLength = 30) =>
|
||||||
|
string.length > maxLength ? `${string.substring(0, 30)}...` : string;
|
||||||
|
|
||||||
|
const buildAndSendMarkdownMessage = async (card, action, actorUser, send) => {
|
||||||
const cardLink = `<${sails.config.custom.baseUrl}/cards/${card.id}|${card.name}>`;
|
const cardLink = `<${sails.config.custom.baseUrl}/cards/${card.id}|${card.name}>`;
|
||||||
|
|
||||||
let markdown;
|
let markdown;
|
||||||
|
@ -28,6 +31,7 @@ const buildAndSendMessage = async (card, action, actorUser, send) => {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Action.Types.COMMENT_CARD:
|
case Action.Types.COMMENT_CARD:
|
||||||
|
// TODO: truncate text?
|
||||||
markdown = `*${actorUser.name}* commented on ${cardLink}:\n>${action.data.text}`;
|
markdown = `*${actorUser.name}* commented on ${cardLink}:\n>${action.data.text}`;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -38,7 +42,7 @@ const buildAndSendMessage = async (card, action, actorUser, send) => {
|
||||||
await send(markdown);
|
await send(markdown);
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildAndSendMessageForTelegramBot = async (card, action, actorUser, send) => {
|
const buildAndSendHtmlMessage = async (card, action, actorUser, send) => {
|
||||||
const cardLink = `<a href="${sails.config.custom.baseUrl}/cards/${card.id}">${card.name}</a>`;
|
const cardLink = `<a href="${sails.config.custom.baseUrl}/cards/${card.id}">${card.name}</a>`;
|
||||||
|
|
||||||
let html;
|
let html;
|
||||||
|
@ -52,15 +56,14 @@ const buildAndSendMessageForTelegramBot = async (card, action, actorUser, send)
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Action.Types.COMMENT_CARD: {
|
case Action.Types.COMMENT_CARD: {
|
||||||
const commentedText =
|
html = `<b>${actorUser.name}</b> commented on ${cardLink}:\n<i>${truncateString(action.data.text)}</i>`;
|
||||||
action.data.text.length > 30 ? `${action.data.text.substring(0, 30)}...` : action.data.text;
|
|
||||||
html = `<b>${actorUser.name}</b> commented on ${cardLink}: <i>${commentedText}</i>`;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await send(html);
|
await send(html);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -142,11 +145,25 @@ module.exports = {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (sails.config.custom.slackBotToken) {
|
if (sails.config.custom.slackBotToken) {
|
||||||
buildAndSendMessage(values.card, action, values.user, sails.helpers.utils.sendSlackMessage);
|
buildAndSendMarkdownMessage(
|
||||||
|
values.card,
|
||||||
|
action,
|
||||||
|
values.user,
|
||||||
|
sails.helpers.utils.sendSlackMessage,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sails.config.custom.telegramChatId) {
|
if (sails.config.custom.googleChatWebhookUrl) {
|
||||||
buildAndSendMessageForTelegramBot(
|
buildAndSendMarkdownMessage(
|
||||||
|
values.card,
|
||||||
|
action,
|
||||||
|
values.user,
|
||||||
|
sails.helpers.utils.sendGoogleChatMessage,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sails.config.custom.telegramBotToken) {
|
||||||
|
buildAndSendHtmlMessage(
|
||||||
values.card,
|
values.card,
|
||||||
action,
|
action,
|
||||||
values.user,
|
values.user,
|
||||||
|
@ -154,14 +171,6 @@ module.exports = {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sails.config.custom.googleChatWebhookUrl) {
|
|
||||||
buildAndSendMessage(
|
|
||||||
values.card,
|
|
||||||
action,
|
|
||||||
values.user,
|
|
||||||
sails.helpers.utils.sendGoogleChatMessage,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return action;
|
return action;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
const buildAndSendMessage = async (card, actorUser, send) => {
|
const buildAndSendMarkdownMessage = async (card, actorUser, send) => {
|
||||||
await send(`*${card.name}* was deleted by ${actorUser.name}`);
|
await send(`*${card.name}* was deleted by ${actorUser.name}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildAndSendMessageForTelegramBot = async (card, actorUser, send) => {
|
const buildAndSendHtmlMessage = async (card, actorUser, send) => {
|
||||||
await send(`<b>${card.name}</b> was deleted by ${actorUser.name}`);
|
await send(`<b>${card.name}</b> was deleted by ${actorUser.name}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,19 +60,19 @@ module.exports = {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sails.config.custom.slackBotToken) {
|
if (sails.config.custom.slackBotToken) {
|
||||||
buildAndSendMessage(card, inputs.actorUser, sails.helpers.utils.sendSlackMessage);
|
buildAndSendMarkdownMessage(card, inputs.actorUser, sails.helpers.utils.sendSlackMessage);
|
||||||
}
|
|
||||||
|
|
||||||
if (sails.config.custom.telegramChatId) {
|
|
||||||
buildAndSendMessageForTelegramBot(
|
|
||||||
card,
|
|
||||||
inputs.actorUser,
|
|
||||||
sails.helpers.utils.sendTelegramMessage,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sails.config.custom.googleChatWebhookUrl) {
|
if (sails.config.custom.googleChatWebhookUrl) {
|
||||||
buildAndSendMessage(card, inputs.actorUser, sails.helpers.utils.sendGoogleChatMessage);
|
buildAndSendMarkdownMessage(
|
||||||
|
card,
|
||||||
|
inputs.actorUser,
|
||||||
|
sails.helpers.utils.sendGoogleChatMessage,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sails.config.custom.telegramBotToken) {
|
||||||
|
buildAndSendHtmlMessage(card, inputs.actorUser, sails.helpers.utils.sendTelegramMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const POST_MESSAGE_API_URL = (telegramBotToken) =>
|
const buildSendMessageApiUrl = (telegramBotToken) =>
|
||||||
`https://api.telegram.org/bot${telegramBotToken}/sendMessage`;
|
`https://api.telegram.org/bot${telegramBotToken}/sendMessage`;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -8,6 +8,7 @@ module.exports = {
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
async fn(inputs) {
|
async fn(inputs) {
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json; charset=utf-8',
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
|
@ -25,7 +26,7 @@ module.exports = {
|
||||||
|
|
||||||
let response;
|
let response;
|
||||||
try {
|
try {
|
||||||
response = await fetch(POST_MESSAGE_API_URL(sails.config.custom.telegramBotToken), {
|
response = await fetch(buildSendMessageApiUrl(sails.config.custom.telegramBotToken), {
|
||||||
headers,
|
headers,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
|
@ -36,8 +37,8 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const responseErrorJson = await response.json();
|
const responseJson = await response.json();
|
||||||
sails.log.error(`Error sending to Telegram: ${responseErrorJson.description}`);
|
sails.log.error(`Error sending to Telegram: ${responseJson.description}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -82,6 +82,7 @@ module.exports.custom = {
|
||||||
|
|
||||||
slackBotToken: process.env.SLACK_BOT_TOKEN,
|
slackBotToken: process.env.SLACK_BOT_TOKEN,
|
||||||
slackChannelId: process.env.SLACK_CHANNEL_ID,
|
slackChannelId: process.env.SLACK_CHANNEL_ID,
|
||||||
|
|
||||||
googleChatWebhookUrl: process.env.GOOGLE_CHAT_WEBHOOK_URL,
|
googleChatWebhookUrl: process.env.GOOGLE_CHAT_WEBHOOK_URL,
|
||||||
|
|
||||||
telegramBotToken: process.env.TELEGRAM_BOT_TOKEN,
|
telegramBotToken: process.env.TELEGRAM_BOT_TOKEN,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue