ronantakizawa/codereview-bench huggingface dataset:
Repository: louislam/uptime-kuma
File: server/notification-providers/signl4.js (JavaScript)

Code before:
                headers: {
                    "Content-Type": "application/json"
                }
            };

            // Monitor URL and ID
            let monitorID = "";
            if (monitorJSON) {
                monitorID = monitorJSON.monitorID;
            }
            data.monitorUrl = this.extractAdress(monitorJSON);

            if (heartbeatJSON == null) {
                // Test alert
                data.title = "Uptime Kuma Alert";
                data.message = msg;
            } else if (heartbeatJSON.status === UP) {
                data.title = "Uptime Kuma Monitor ✅ Up";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorID;
                if (monitorID !== "") {
                    // Only close the alert if there is a valid ID
                    data["X-S4-Status"] = "resolved";
                }
            } else if (heartbeatJSON.status === DOWN) {
                data.title = "Uptime Kuma Monitor 🔴 Down";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorID;
                data["X-S4-Status"] = "new";
            }

            await axios.post(notification.webhookURL, data, config);
            return okMsg;

        } catch (error) {
            this.throwGeneralAxiosError(error);
        }

    }

}

module.exports = SIGNL4;


Review comment (suggestion):
```suggestion
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
                    data["X-S4-Status"] = "resolved";
            } else if (heartbeatJSON.status === DOWN) {
                data.title = "Uptime Kuma Monitor 🔴 Down";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
```

Code after:
                headers: {
                    "Content-Type": "application/json"
                }
            };

            if (heartbeatJSON == null) {
                // Test alert
                data.title = "Uptime Kuma Alert";
                data.message = msg;
            } else if (heartbeatJSON.status === UP) {
                data.title = "Uptime Kuma Monitor ✅ Up";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
                data["X-S4-Status"] = "resolved";
            } else if (heartbeatJSON.status === DOWN) {
                data.title = "Uptime Kuma Monitor 🔴 Down";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
                data["X-S4-Status"] = "new";
            }

            await axios.post(notification.webhookURL, data, config);
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = SIGNL4;
Repository: louislam/uptime-kuma
File: server/notification-providers/signl4.js (JavaScript)

Code before:
            if (heartbeatJSON == null) {
                // Test alert
                data.title = "Uptime Kuma Alert";
                data.message = msg;
            } else if (heartbeatJSON.status === UP) {
                data.title = "Uptime Kuma Monitor ✅ Up";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorID;
                if (monitorID !== "") {
                    // Only close the alert if there is a valid ID
                    data["X-S4-Status"] = "resolved";
                }
            } else if (heartbeatJSON.status === DOWN) {
                data.title = "Uptime Kuma Monitor 🔴 Down";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorID;
                data["X-S4-Status"] = "new";
            }

            await axios.post(notification.webhookURL, data, config);
            return okMsg;

        } catch (error) {
            this.throwGeneralAxiosError(error);
        }

    }

}

module.exports = SIGNL4;


Review comment (suggestion):
```suggestion
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
```

Code after:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { UP, DOWN } = require("../../src/util");

class SIGNL4 extends NotificationProvider {
    name = "SIGNL4";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        try {
            let data = {
                heartbeat: heartbeatJSON,
                monitor: monitorJSON,
                msg,
                // Source system
                "X-S4-SourceSystem": "UptimeKuma",
                monitorUrl: this.extractAdress(monitorJSON),
            };

            const config = {
                headers: {
                    "Content-Type": "application/json"
                }
            };

            if (heartbeatJSON == null) {
                // Test alert
                data.title = "Uptime Kuma Alert";
                data.message = msg;
            } else if (heartbeatJSON.status === UP) {
                data.title = "Uptime Kuma Monitor ✅ Up";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
                data["X-S4-Status"] = "resolved";
            } else if (heartbeatJSON.status === DOWN) {
                data.title = "Uptime Kuma Monitor 🔴 Down";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
                data["X-S4-Status"] = "new";
            }

            await axios.post(notification.webhookURL, data, config);
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = SIGNL4;
Repository: louislam/uptime-kuma
File: server/notification-providers/signl4.js (JavaScript)

Code before:
        const okMsg = "Sent Successfully.";

        try {
            let data = {
                heartbeat: heartbeatJSON,
                monitor: monitorJSON,
                msg,
                // Source system
                "X-S4-SourceSystem": "UptimeKuma",
                monitorUrl: this.extractAdress(monitorJSON),
            };

            const config = {
                headers: {
                    "Content-Type": "application/json"
                }
            };

            if (heartbeatJSON == null) {
                // Test alert
                data.title = "Uptime Kuma Alert";
                data.message = msg;
            } else if (heartbeatJSON.status === UP) {
                data.title = "Uptime Kuma Monitor ✅ Up";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
                    data["X-S4-Status"] = "resolved";
            } else if (heartbeatJSON.status === DOWN) {
                data.title = "Uptime Kuma Monitor 🔴 Down";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
                data["X-S4-Status"] = "new";
            }

            await axios.post(notification.webhookURL, data, config);
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = SIGNL4;


Review comment (suggestion):
another thing which I missed ^^

```suggestion
                data["X-S4-Status"] = "resolved";
```

Code after:
        const okMsg = "Sent Successfully.";

        try {
            let data = {
                heartbeat: heartbeatJSON,
                monitor: monitorJSON,
                msg,
                // Source system
                "X-S4-SourceSystem": "UptimeKuma",
                monitorUrl: this.extractAdress(monitorJSON),
            };

            const config = {
                headers: {
                    "Content-Type": "application/json"
                }
            };

            if (heartbeatJSON == null) {
                // Test alert
                data.title = "Uptime Kuma Alert";
                data.message = msg;
            } else if (heartbeatJSON.status === UP) {
                data.title = "Uptime Kuma Monitor ✅ Up";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
                data["X-S4-Status"] = "resolved";
            } else if (heartbeatJSON.status === DOWN) {
                data.title = "Uptime Kuma Monitor 🔴 Down";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
                data["X-S4-Status"] = "new";
            }

            await axios.post(notification.webhookURL, data, config);
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = SIGNL4;
Repository: louislam/uptime-kuma
File: test/e2e/specs/setup-process.once.js (JavaScript)

Code before:
import { test } from "@playwright/test";
import { getSqliteDatabaseExists, login, screenshot, takeSqliteSnapshot } from "../util-test";
import { step } from "../tools/step";

test.describe("Uptime Kuma Setup", () => {

    // Skip tests if the SQLite database already exists (only run once per session)
    test.skip(() => getSqliteDatabaseExists(), "Must only run once per session");

    /*
     * Hook to take a screenshot after each test
     */
    test.afterEach(async ({ page }, testInfo) => {
        await screenshot(testInfo, page);
    });

    /*
     * Setup
     */

    test("setup sqlite", async ({ page }, testInfo) => {
        step("Navigating to setup page");
        await page.goto("./");
        step("Clicking on SQLite option");
        await page.getByText("SQLite").click();
        step("Proceeding to next step");
        await page.getByRole("button", { name: "Next" }).click();
        await screenshot(testInfo, page);
        await page.waitForURL("/setup"); // ensures the server is ready to continue to the next test
    });

    test("setup admin", async ({ page }) => {
        step("Setting up admin credentials");
        await page.goto("./");
        await page.getByPlaceholder("Username").click();
        await page.getByPlaceholder("Username").fill("admin");
        await page.getByPlaceholder("Username").press("Tab");

Review comment (suggestion):
Think the code below is clear enough in this

```suggestion
```

Code after:
import { test } from "@playwright/test";
import { getSqliteDatabaseExists, login, screenshot, takeSqliteSnapshot } from "../util-test";

test.describe("Uptime Kuma Setup", () => {

    test.skip(() => getSqliteDatabaseExists(), "Must only run once per session");

    test.afterEach(async ({ page }, testInfo) => {
        await screenshot(testInfo, page);
    });

    /*
     * Setup
     */

    test("setup sqlite", async ({ page }, testInfo) => {
        await page.goto("./");
        await page.getByText("SQLite").click();
        await page.getByRole("button", { name: "Next" }).click();
        await screenshot(testInfo, page);
        await page.waitForURL("/setup"); // ensures the server is ready to continue to the next test
    });

    test("setup admin", async ({ page }) => {
        await page.goto("./");
        await page.getByPlaceholder("Username").click();
        await page.getByPlaceholder("Username").fill("admin");
        await page.getByPlaceholder("Username").press("Tab");
        await page.getByPlaceholder("Password", { exact: true }).fill("admin123");
        await page.getByPlaceholder("Password", { exact: true }).press("Tab");
        await page.getByPlaceholder("Repeat Password").fill("admin123");
        await page.getByRole("button", { name: "Create" }).click();
    });

    /*
     * All other tests should be run after setup
     */
Repository: louislam/uptime-kuma
File: server/notification-providers/techulus-push.js (JavaScript)

Code before:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class TechulusPush extends NotificationProvider {
    name = "PushByTechulus";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        let data = {
            "title": notification?.pushTitle?.length ? notification.pushTitle : "Uptime-Kuma",
            "body": msg,
            "timeSensitive": notification.pushTimeSensitive ?? false,
        };

        if (notification.pushChannel) {
            data.channel = notification.pushChannel;
        }

        if (notification.pushSound) {
            data.sound = notification.pushSound;
        }

        try {
            await axios.post(`https://push.techulus.com/api/v1/notify/${notification.pushAPIKey}`, data);
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = TechulusPush;


Review comment (security):
```suggestion
            "timeSensitive": notification.pushTimeSensitive ?? true,
```

Code after:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class TechulusPush extends NotificationProvider {
    name = "PushByTechulus";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        let data = {
            "title": notification?.pushTitle?.length ? notification.pushTitle : "Uptime-Kuma",
            "body": msg,
            "timeSensitive": notification.pushTimeSensitive ?? true,
        };

        if (notification.pushChannel) {
            data.channel = notification.pushChannel;
        }

        if (notification.pushSound) {
            data.sound = notification.pushSound;
        }

        try {
            await axios.post(`https://push.techulus.com/api/v1/notify/${notification.pushAPIKey}`, data);
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = TechulusPush;
Repository: louislam/uptime-kuma
File: server/notification-providers/46elks.js (JavaScript)

Code before:
    name = "Elks";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        try {

            // API credentials
            const username = notification.elksUsername;
            const password = notification.elksAuthToken;
            const authKey = Buffer.from(username + ":" + password).toString("base64");

            // Set the SMS endpoint
            const url = "https://api.46elks.com/a1/sms";

            // Request data object
            let data = {
                from: notification.elksFromNumber,
                to: notification.elksToNumber,
                message: msg
            };

            data = new URLSearchParams(data);
            data = data.toString();

            // Set the headers
            const config = {
                headers: {
                    "Authorization": "Basic " + authKey
                }
            };

            // Send request
            await axios.post(url, data, config);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }

    }

}

module.exports = Elks;


Review comment (suggestion):
Please use `UrlSearchParams` like the other notification providers

Example:

https://github.com/louislam/uptime-kuma/blob/bbc75b840bc0eefa1d7296a78487ad8ed4c8a97a/server/notification-providers/gtx-messaging.js#L17-L24

Code after:
    name = "Elks";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";
        const url = "https://api.46elks.com/a1/sms";

        try {
            let data = new URLSearchParams();
            data.append("from", notification.elksFromNumber);
            data.append("to", notification.elksToNumber );
            data.append("message", msg);

            const config = {
                headers: {
                    "Authorization": "Basic " + Buffer.from(`${notification.elksUsername}:${notification.elksAuthToken}`).toString("base64")
                }
            };

            await axios.post(url, data, config);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = Elks;
Repository: louislam/uptime-kuma
File: server/notification-providers/46elks.js (JavaScript)

Code before:
        const okMsg = "Sent Successfully.";

        try {

            const url = "https://api.46elks.com/a1/sms";

            let data = new URLSearchParams();
            data.append("from", notification.elksFromNumber);
            data.append("to", notification.elksToNumber );
            data.append("message", msg);

            const config = {
                headers: {
                    "Authorization": "Basic " + Buffer.from(`${notification.elksUsername}:${notification.elksAuthToken}`).toString("base64")
                }
            };

            await axios.post(url, data, config);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }

    }

}

module.exports = Elks;


Review comment (security):
nit: formatting

```suggestion
        const url = "https://api.46elks.com/a1/sms";

        try {
            let data = new URLSearchParams();
            data.append("from", notification.elksFromNumber);
            data.append("to", notification.elksToNumber );
            data.append("message", msg);

            const config = {
                headers: {
                    "Authorization": "Basic " + Buffer.from(`${notification.elksUsername}:${notification.elksAuthToken}`).toString("base64")
                }
            };

            await axios.post(url, data, config);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
```


Code after:
        const okMsg = "Sent Successfully.";
        const url = "https://api.46elks.com/a1/sms";

        try {
            let data = new URLSearchParams();
            data.append("from", notification.elksFromNumber);
            data.append("to", notification.elksToNumber );
            data.append("message", msg);

            const config = {
                headers: {
                    "Authorization": "Basic " + Buffer.from(`${notification.elksUsername}:${notification.elksAuthToken}`).toString("base64")
                }
            };

            await axios.post(url, data, config);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = Elks;
Repository: louislam/uptime-kuma
File: src/components/notifications/index.js (JavaScript)

Code before:
    "serwersms": SerwerSMS,
    "signal": Signal,
    "SIGNL4": SIGNL4,
    "SMSManager": SMSManager,
    "SMSPartner": SMSPartner,
    "slack": Slack,
    "squadcast": Squadcast,
    "SMSEagle": SMSEagle,
    "smtp": STMP,
    "stackfield": Stackfield,
    "teams": Teams,
    "telegram": Telegram,
    "threema": Threema,
    "twilio": Twilio,
    "Splunk": Splunk,
    "webhook": Webhook,
    "WeCom": WeCom,
    "GoAlert": GoAlert,
    "ServerChan": ServerChan,
    "ZohoCliq": ZohoCliq,
    "SevenIO": SevenIO,
    "whapi": Whapi,
    "gtxmessaging": GtxMessaging,
    "Cellsynt": Cellsynt,
    "WPush": WPush,
    "SendGrid": SendGrid
};

export default NotificationFormList;


Review comment (suggestion):
nit:

```suggestion
    "SendGrid": SendGrid,
```

Code after:
    "serwersms": SerwerSMS,
    "signal": Signal,
    "SIGNL4": SIGNL4,
    "SMSManager": SMSManager,
    "SMSPartner": SMSPartner,
    "slack": Slack,
    "squadcast": Squadcast,
    "SMSEagle": SMSEagle,
    "smtp": STMP,
    "stackfield": Stackfield,
    "teams": Teams,
    "telegram": Telegram,
    "threema": Threema,
    "twilio": Twilio,
    "Splunk": Splunk,
    "webhook": Webhook,
    "WeCom": WeCom,
    "GoAlert": GoAlert,
    "ServerChan": ServerChan,
    "ZohoCliq": ZohoCliq,
    "SevenIO": SevenIO,
    "whapi": Whapi,
    "gtxmessaging": GtxMessaging,
    "Cellsynt": Cellsynt,
    "WPush": WPush,
    "SendGrid": SendGrid,
};

export default NotificationFormList;
Repository: louislam/uptime-kuma
File: server/notification-providers/send-grid.js (JavaScript)

Code before:
          "Content-Type": "application/json",
          Authorization: `Bearer ${notification.sendgridApiKey}`,
        },
      };

      let personalizations = {
        to: [{ email: notification.sendgridToEmail }],
      };

      // Add CC recipients if provided
      if (notification.sendgridCcEmail) {
        personalizations.cc = notification.sendgridCcEmail
          .split(",")
          .map((email) => ({ email: email.trim() }));
      }

      // Add BCC recipients if provided
      if (notification.sendgridBccEmail) {
        personalizations.bcc = notification.sendgridBccEmail
          .split(",")
          .map((email) => ({ email: email.trim() }));
      }

      let data = {
        personalizations: [personalizations],
        from: { email: notification.sendgridFromEmail },
        subject:
          notification.sendgridSubject ||
          "Notification from Your Uptime Kuma",
        content: [
          {
            type: "text/plain",
            value: msg,
          },
        ],
      };

      await axios.post(
        "https://api.sendgrid.com/v3/mail/send",
        data,
        config
      );
      return okMsg;
    } catch (error) {
      this.throwGeneralAxiosError(error);
    }
  }
}

module.exports = SendGrid;


Review comment (suggestion):
lets trim this as well

```suggestion
        from: { email: notification.sendgridFromEmail.trim() },
```

Code after:
                    "Content-Type": "application/json",
                    Authorization: `Bearer ${notification.sendgridApiKey}`,
                },
            };

            let personalizations = {
                to: [{ email: notification.sendgridToEmail }],
            };

            // Add CC recipients if provided
            if (notification.sendgridCcEmail) {
                personalizations.cc = notification.sendgridCcEmail
                    .split(",")
                    .map((email) => ({ email: email.trim() }));
            }

            // Add BCC recipients if provided
            if (notification.sendgridBccEmail) {
                personalizations.bcc = notification.sendgridBccEmail
                    .split(",")
                    .map((email) => ({ email: email.trim() }));
            }

            let data = {
                personalizations: [ personalizations ],
                from: { email: notification.sendgridFromEmail.trim() },
                subject:
          notification.sendgridSubject ||
          "Notification from Your Uptime Kuma",
                content: [
                    {
                        type: "text/plain",
                        value: msg,
                    },
                ],
            };

            await axios.post(
                "https://api.sendgrid.com/v3/mail/send",
                data,
                config
            );
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = SendGrid;