Merge pull request #2382 from bluewave-labs/feat/format-check

Feat/format check
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-06-01 11:57:08 -07:00
commit 41e3e262fb
8 files changed
+244 -176

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
name: Format Check (Client & Server)
on:
pull_request:
workflow_dispatch:
jobs:
format-client:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install client dependencies
working-directory: client
run: npm ci
- name: Check client formatting
working-directory: client
run: npm run format-check
format-server:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install server dependencies
working-directory: server
run: npm ci
- name: Check server formatting
working-directory: server
run: npm run format-check
close-pr-if-needed:
if: always()
runs-on: ubuntu-latest
needs: [format-client, format-server]
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Get PR number
id: pr
run: echo "PR_NUMBER=$(jq -r .pull_request.number "$GITHUB_EVENT_PATH")" >> $GITHUB_ENV
- name: Close PR using GitHub CLI
if: |
needs.format-client.result == 'failure' ||
needs.format-server.result == 'failure'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr close "$PR_NUMBER" --delete-branch --comment "❌ Formatting check failed — PR auto-closed.
Please run \`npm run format\` and push again."
@@ -161,7 +161,8 @@ Select.propTypes = {
label: PropTypes.string, label: PropTypes.string,
placeholder: PropTypes.string, placeholder: PropTypes.string,
isHidden: PropTypes.bool, isHidden: PropTypes.bool,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]).isRequired, value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool])
.isRequired,
items: PropTypes.arrayOf( items: PropTypes.arrayOf(
PropTypes.shape({ PropTypes.shape({
_id: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]) _id: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool])
+2
View File
@@ -14,10 +14,12 @@ Fixes #123
- [ ] (Do not skip this or your PR will be closed) I have performed a self-review and testing of my code. - [ ] (Do not skip this or your PR will be closed) I have performed a self-review and testing of my code.
- [ ] I have included the issue # in the PR. - [ ] I have included the issue # in the PR.
- [ ] I have added i18n support to visible strings (instead of `<div>Add</div>`, use): - [ ] I have added i18n support to visible strings (instead of `<div>Add</div>`, use):
```Javascript ```Javascript
const { t } = useTranslation(); const { t } = useTranslation();
<div>{t('add')}</div> <div>{t('add')}</div>
``` ```
- [ ] The issue I am working on is assigned to me. - [ ] The issue I am working on is assigned to me.
- [ ] I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application). - [ ] I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
- [ ] My PR is granular and targeted to one specific feature. - [ ] My PR is granular and targeted to one specific feature.
+139 -139
View File
@@ -4,171 +4,171 @@ import { handleError, handleValidationError } from "./controllerUtils.js";
const SERVICE_NAME = "NotificationController"; const SERVICE_NAME = "NotificationController";
const NOTIFICATION_TYPES = { const NOTIFICATION_TYPES = {
WEBHOOK: 'webhook', WEBHOOK: "webhook",
TELEGRAM: 'telegram' TELEGRAM: "telegram",
}; };
const PLATFORMS = { const PLATFORMS = {
SLACK: 'slack', SLACK: "slack",
DISCORD: 'discord', DISCORD: "discord",
TELEGRAM: 'telegram' TELEGRAM: "telegram",
}; };
class NotificationController { class NotificationController {
constructor(notificationService, stringService, statusService) { constructor(notificationService, stringService, statusService) {
this.notificationService = notificationService; this.notificationService = notificationService;
this.stringService = stringService; this.stringService = stringService;
this.statusService = statusService; this.statusService = statusService;
this.triggerNotification = this.triggerNotification.bind(this); this.triggerNotification = this.triggerNotification.bind(this);
this.testWebhook = this.testWebhook.bind(this); this.testWebhook = this.testWebhook.bind(this);
} }
async triggerNotification(req, res, next) { async triggerNotification(req, res, next) {
try { try {
await triggerNotificationBodyValidation.validateAsync(req.body, { await triggerNotificationBodyValidation.validateAsync(req.body, {
abortEarly: false, abortEarly: false,
stripUnknown: true, stripUnknown: true,
}); });
} catch (error) { } catch (error) {
next(handleValidationError(error, SERVICE_NAME)); next(handleValidationError(error, SERVICE_NAME));
return; return;
} }
try { try {
const { monitorId, type, platform, config, status = false } = req.body; const { monitorId, type, platform, config, status = false } = req.body;
// Create a simplified networkResponse similar to what would come from monitoring // Create a simplified networkResponse similar to what would come from monitoring
const networkResponse = { const networkResponse = {
monitorId, monitorId,
status status,
}; };
// Use the statusService to get monitor details and handle status change logic // Use the statusService to get monitor details and handle status change logic
// This returns { monitor, statusChanged, prevStatus } exactly like your job queue uses // This returns { monitor, statusChanged, prevStatus } exactly like your job queue uses
const statusResult = await this.statusService.updateStatus(networkResponse); const statusResult = await this.statusService.updateStatus(networkResponse);
if (type === NOTIFICATION_TYPES.WEBHOOK) { if (type === NOTIFICATION_TYPES.WEBHOOK) {
const notification = { const notification = {
type, type,
platform, platform,
config, config,
}; };
await this.notificationService.sendWebhookNotification( await this.notificationService.sendWebhookNotification(
statusResult, // Contains monitor, statusChanged, and prevStatus statusResult, // Contains monitor, statusChanged, and prevStatus
notification notification
); );
} }
return res.success({ return res.success({
msg: this.stringService.webhookSendSuccess, msg: this.stringService.webhookSendSuccess,
}); });
} catch (error) { } catch (error) {
next(handleError(error, SERVICE_NAME, "triggerNotification")); next(handleError(error, SERVICE_NAME, "triggerNotification"));
} }
} }
createTestNetworkResponse() { createTestNetworkResponse() {
return { return {
monitor: { monitor: {
_id: "test-monitor-id", _id: "test-monitor-id",
name: "Test Monitor", name: "Test Monitor",
url: "https://example.com" url: "https://example.com",
}, },
status: true, status: true,
statusChanged: true, statusChanged: true,
prevStatus: false, prevStatus: false,
}; };
} }
handleTelegramTest(botToken, chatId) { handleTelegramTest(botToken, chatId) {
if (!botToken || !chatId) { if (!botToken || !chatId) {
return { return {
isValid: false, isValid: false,
error: { error: {
msg: this.stringService.telegramRequiresBotTokenAndChatId, msg: this.stringService.telegramRequiresBotTokenAndChatId,
status: 400 status: 400,
} },
}; };
} }
return { return {
isValid: true, isValid: true,
notification: { notification: {
type: NOTIFICATION_TYPES.WEBHOOK, type: NOTIFICATION_TYPES.WEBHOOK,
platform: PLATFORMS.TELEGRAM, platform: PLATFORMS.TELEGRAM,
config: { botToken, chatId } config: { botToken, chatId },
} },
}; };
} }
handleWebhookTest(webhookUrl, platform) { handleWebhookTest(webhookUrl, platform) {
if (webhookUrl === null) { if (webhookUrl === null) {
return { return {
isValid: false, isValid: false,
error: { error: {
msg: this.stringService.webhookUrlRequired, msg: this.stringService.webhookUrlRequired,
status: 400 status: 400,
} },
}; };
} }
return { return {
isValid: true, isValid: true,
notification: { notification: {
type: NOTIFICATION_TYPES.WEBHOOK, type: NOTIFICATION_TYPES.WEBHOOK,
platform: platform, platform: platform,
config: { webhookUrl } config: { webhookUrl },
} },
}; };
} }
async testWebhook(req, res, next) { async testWebhook(req, res, next) {
try { try {
const { webhookUrl, platform, botToken, chatId } = req.body; const { webhookUrl, platform, botToken, chatId } = req.body;
if (platform === null) { if (platform === null) {
return res.error({ return res.error({
msg: this.stringService.platformRequired, msg: this.stringService.platformRequired,
status: 400 status: 400,
}); });
} }
// Platform-specific handling // Platform-specific handling
const platformHandlers = { const platformHandlers = {
[PLATFORMS.TELEGRAM]: () => this.handleTelegramTest(botToken, chatId), [PLATFORMS.TELEGRAM]: () => this.handleTelegramTest(botToken, chatId),
// Default handler for webhook-based platforms (Slack, Discord, etc.) // Default handler for webhook-based platforms (Slack, Discord, etc.)
default: () => this.handleWebhookTest(webhookUrl, platform) default: () => this.handleWebhookTest(webhookUrl, platform),
}; };
const handler = platformHandlers[platform] || platformHandlers.default; const handler = platformHandlers[platform] || platformHandlers.default;
const handlerResult = handler(); const handlerResult = handler();
if (!handlerResult.isValid) { if (!handlerResult.isValid) {
return res.error(handlerResult.error); return res.error(handlerResult.error);
} }
const networkResponse = this.createTestNetworkResponse(); const networkResponse = this.createTestNetworkResponse();
const result = await this.notificationService.sendWebhookNotification( const result = await this.notificationService.sendWebhookNotification(
networkResponse, networkResponse,
handlerResult.notification handlerResult.notification
); );
if (result && result !== false) { if (result && result !== false) {
return res.success({ return res.success({
msg: this.stringService.webhookSendSuccess, msg: this.stringService.webhookSendSuccess,
}); });
} else { } else {
return res.error({ return res.error({
msg: this.stringService.testNotificationFailed, msg: this.stringService.testNotificationFailed,
status: 400 status: 400,
}); });
} }
} catch (error) { } catch (error) {
next(handleError(error, SERVICE_NAME, "testWebhook")); next(handleError(error, SERVICE_NAME, "testWebhook"));
} }
} }
} }
export default NotificationController; export default NotificationController;
+1 -1
View File
@@ -22,7 +22,7 @@ const NotificationSchema = mongoose.Schema(
}, },
platform: { platform: {
type: String, type: String,
}, },
config: { config: {
type: configSchema, type: configSchema,
default: () => ({}), default: () => ({}),
+1 -1
View File
@@ -38,7 +38,7 @@ const updateStatusPage = async (statusPageData, image) => {
data: image.buffer, data: image.buffer,
contentType: image.mimetype, contentType: image.mimetype,
}; };
}else{ } else {
statusPageData.logo = null; statusPageData.logo = null;
} }
+13 -19
View File
@@ -2,29 +2,23 @@ import { Router } from "express";
import { verifyJWT } from "../middleware/verifyJWT.js"; import { verifyJWT } from "../middleware/verifyJWT.js";
class NotificationRoutes { class NotificationRoutes {
constructor(notificationController) { constructor(notificationController) {
this.router = Router(); this.router = Router();
this.notificationController = notificationController; this.notificationController = notificationController;
this.initializeRoutes(); this.initializeRoutes();
} }
initializeRoutes() { initializeRoutes() {
this.router.use(verifyJWT); this.router.use(verifyJWT);
this.router.post( this.router.post("/trigger", this.notificationController.triggerNotification);
"/trigger",
this.notificationController.triggerNotification
);
this.router.post( this.router.post("/test-webhook", this.notificationController.testWebhook);
"/test-webhook", }
this.notificationController.testWebhook
);
}
getRouter() { getRouter() {
return this.router; return this.router;
} }
} }
export default NotificationRoutes; export default NotificationRoutes;
+24 -15
View File
@@ -1,17 +1,26 @@
<mjml> <mjml>
<mj-body> <mj-body>
<mj-section> <mj-section>
<mj-column> <mj-column>
<mj-text font-size="20px" font-family="Helvetica Neue"> <mj-text
Hello! font-size="20px"
</mj-text> font-family="Helvetica Neue"
<mj-text font-size="16px" font-family="Helvetica Neue"> >
This is a test email from the Monitoring System. Hello!
</mj-text> </mj-text>
<mj-text font-size="14px" font-family="Helvetica Neue"> <mj-text
If you're receiving this, your email configuration is working correctly. font-size="16px"
</mj-text> font-family="Helvetica Neue"
</mj-column> >
</mj-section> This is a test email from the Monitoring System.
</mj-body> </mj-text>
<mj-text
font-size="14px"
font-family="Helvetica Neue"
>
If you're receiving this, your email configuration is working correctly.
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml> </mjml>