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
9 files changed
+262 -194

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])
+6 -4
View File
@@ -1,23 +1,25 @@
**(Please remove this line only before submitting your PR. Ensure that all relevant items are checked before submission.)** **(Please remove this line only before submitting your PR. Ensure that all relevant items are checked before submission.)**
## Describe your changes ## Describe your changes
Briefly describe the changes you made and their purpose. Briefly describe the changes you made and their purpose.
## Write your issue number after "Fixes " ## Write your issue number after "Fixes "
Fixes #123 Fixes #123
## Please ensure all items are checked off before requesting a review. "Checked off" means you need to add an "x" character between brackets so they turn into checkmarks. ## Please ensure all items are checked off before requesting a review. "Checked off" means you need to add an "x" character between brackets so they turn into checkmarks.
- [ ] (Do not skip this or your PR will be closed) I deployed the application locally. - [ ] (Do not skip this or your PR will be closed) I deployed the application locally.
- [ ] (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.
+1 -1
View File
@@ -2,7 +2,7 @@
<p align="center"><strong>The backend service for Checkmate, an open source uptime and infrastructure monitoring application</strong></p> <p align="center"><strong>The backend service for Checkmate, an open source uptime and infrastructure monitoring application</strong></p>
This directory contains the **backend** of Checkmate, which handles data processing, storage, and API services for the Checkmate monitoring tool. The backend is responsible for managing uptime checks, handling real-time alerts, and storing historical monitoring data. This directory contains the **backend** of Checkmate, which handles data processing, storage, and API services for the Checkmate monitoring tool. The backend is responsible for managing uptime checks, handling real-time alerts, and storing historical monitoring data.
Checkmate's backend is designed to be lightweight and scalable, ensuring reliable performance even with a high number of active monitors. Checkmate's backend is designed to be lightweight and scalable, ensuring reliable performance even with a high number of active monitors.
+148 -148
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
// This returns { monitor, statusChanged, prevStatus } exactly like your job queue uses
const statusResult = await this.statusService.updateStatus(networkResponse);
if (type === NOTIFICATION_TYPES.WEBHOOK) {
const notification = {
type,
platform,
config,
};
await this.notificationService.sendWebhookNotification( // Use the statusService to get monitor details and handle status change logic
statusResult, // Contains monitor, statusChanged, and prevStatus // This returns { monitor, statusChanged, prevStatus } exactly like your job queue uses
notification const statusResult = await this.statusService.updateStatus(networkResponse);
);
}
return res.success({ if (type === NOTIFICATION_TYPES.WEBHOOK) {
msg: this.stringService.webhookSendSuccess, const notification = {
}); type,
} catch (error) { platform,
next(handleError(error, SERVICE_NAME, "triggerNotification")); config,
} };
}
createTestNetworkResponse() { await this.notificationService.sendWebhookNotification(
return { statusResult, // Contains monitor, statusChanged, and prevStatus
monitor: { notification
_id: "test-monitor-id", );
name: "Test Monitor", }
url: "https://example.com"
},
status: true,
statusChanged: true,
prevStatus: false,
};
}
handleTelegramTest(botToken, chatId) { return res.success({
if (!botToken || !chatId) { msg: this.stringService.webhookSendSuccess,
return { });
isValid: false, } catch (error) {
error: { next(handleError(error, SERVICE_NAME, "triggerNotification"));
msg: this.stringService.telegramRequiresBotTokenAndChatId, }
status: 400 }
}
};
}
return { createTestNetworkResponse() {
isValid: true, return {
notification: { monitor: {
type: NOTIFICATION_TYPES.WEBHOOK, _id: "test-monitor-id",
platform: PLATFORMS.TELEGRAM, name: "Test Monitor",
config: { botToken, chatId } url: "https://example.com",
} },
}; status: true,
} statusChanged: true,
prevStatus: false,
};
}
handleWebhookTest(webhookUrl, platform) { handleTelegramTest(botToken, chatId) {
if (webhookUrl === null) { if (!botToken || !chatId) {
return { return {
isValid: false, isValid: false,
error: { error: {
msg: this.stringService.webhookUrlRequired, 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: platform, platform: PLATFORMS.TELEGRAM,
config: { webhookUrl } config: { botToken, chatId },
} },
}; };
} }
async testWebhook(req, res, next) { handleWebhookTest(webhookUrl, platform) {
try { if (webhookUrl === null) {
const { webhookUrl, platform, botToken, chatId } = req.body; return {
isValid: false,
error: {
msg: this.stringService.webhookUrlRequired,
status: 400,
},
};
}
if (platform === null) { return {
return res.error({ isValid: true,
msg: this.stringService.platformRequired, notification: {
status: 400 type: NOTIFICATION_TYPES.WEBHOOK,
}); platform: platform,
} config: { webhookUrl },
},
// Platform-specific handling };
const platformHandlers = { }
[PLATFORMS.TELEGRAM]: () => this.handleTelegramTest(botToken, chatId),
// Default handler for webhook-based platforms (Slack, Discord, etc.) async testWebhook(req, res, next) {
default: () => this.handleWebhookTest(webhookUrl, platform) try {
}; const { webhookUrl, platform, botToken, chatId } = req.body;
const handler = platformHandlers[platform] || platformHandlers.default; if (platform === null) {
const handlerResult = handler(); return res.error({
msg: this.stringService.platformRequired,
if (!handlerResult.isValid) { status: 400,
return res.error(handlerResult.error); });
} }
const networkResponse = this.createTestNetworkResponse(); // Platform-specific handling
const platformHandlers = {
const result = await this.notificationService.sendWebhookNotification( [PLATFORMS.TELEGRAM]: () => this.handleTelegramTest(botToken, chatId),
networkResponse, // Default handler for webhook-based platforms (Slack, Discord, etc.)
handlerResult.notification default: () => this.handleWebhookTest(webhookUrl, platform),
); };
if (result && result !== false) { const handler = platformHandlers[platform] || platformHandlers.default;
return res.success({ const handlerResult = handler();
msg: this.stringService.webhookSendSuccess,
}); if (!handlerResult.isValid) {
} else { return res.error(handlerResult.error);
return res.error({ }
msg: this.stringService.testNotificationFailed,
status: 400 const networkResponse = this.createTestNetworkResponse();
});
} const result = await this.notificationService.sendWebhookNotification(
} catch (error) { networkResponse,
next(handleError(error, SERVICE_NAME, "testWebhook")); handlerResult.notification
} );
}
if (result && result !== false) {
return res.success({
msg: this.stringService.webhookSendSuccess,
});
} else {
return res.error({
msg: this.stringService.testNotificationFailed,
status: 400,
});
}
} catch (error) {
next(handleError(error, SERVICE_NAME, "testWebhook"));
}
}
} }
export default NotificationController; export default NotificationController;
+2 -2
View File
@@ -20,9 +20,9 @@ const NotificationSchema = mongoose.Schema(
type: String, type: String,
enum: ["email", "sms", "webhook"], enum: ["email", "sms", "webhook"],
}, },
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;
} }
+16 -22
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(
"/trigger",
this.notificationController.triggerNotification
);
this.router.post(
"/test-webhook",
this.notificationController.testWebhook
);
}
getRouter() { this.router.post("/trigger", this.notificationController.triggerNotification);
return this.router;
} this.router.post("/test-webhook", this.notificationController.testWebhook);
}
getRouter() {
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>