ronantakizawa/codereview-bench huggingface dataset:
Repository: louislam/uptime-kuma
File: src/components/notifications/CallMeBot.vue (Vue)

Code before:
<template>
    <div class="mb-3">
        <label for="callmebot-endpoint" class="form-label">{{ $t("Endpoint") }}</label>
        <div class="input-group mb-3">
            <input id="callmebot-endpoint" v-model="$parent.notification.callMeBotEndpoint" type="text" class="form-control" required>
            <button v-if="$parent.notification.callMeBotEndpoint" class="btn btn-outline-secondary" type="button" @click="cleanupEndpoint">
                {{ $t("Cleanup") }}
            </button>
        </div>
        <i18n-t tag="div" keypath="callMeBotGet" class="form-text">
            <a href="https://www.callmebot.com/blog/free-api-facebook-messenger/" target="_blank">Facebook Messenger</a>
        </i18n-t>
        <i18n-t tag="div" keypath="callMeBotGet" class="form-text">
            <a href="https://www.callmebot.com/blog/test-whatsapp-api/" target="_blank">WhatsApp</a>
        </i18n-t>
        <i18n-t tag="div" keypath="callMeBotGet" class="form-text">
            <a href="https://www.callmebot.com/blog/telegram-phone-call-using-your-browser/" target="_blank">Telegram Call</a>
        </i18n-t>
        <i18n-t tag="div" keypath="callMeBotInfo" class="form-text" />
    </div>
</template>

<script>

export default {
    methods: {
        /**
         * Remove the &text= param to be able to append one later
         * @returns {Promise<void>}
         * @throws The provided URL is invalid
         */

        cleanupEndpoint() {
            try {
                const url = new URL(this.$parent.notification.callMeBotEndpoint);
                url.searchParams.delete("text");
                this.$parent.notification.callMeBotEndpoint = url;
                this.$root.toastSuccess("URL was cleaned successfully");
            } catch (e) {
                this.$root.toastError("Invalid URL");
            }
        },
    }
};

Review comment (refactor):
This helptext is quite weird.
Think about a user coming across this: would they be able to figure out what to do in this case?

Please:
- refactor this into a single helptext which does not contain the same text 3x
- consider linking to the ratelimits instead of telling people what one of them has currently (this may change)

Code after:
<template>
    <div class="mb-3">
        <label for="callmebot-endpoint" class="form-label">{{ $t("Endpoint") }}</label>
        <input id="callmebot-endpoint" v-model="$parent.notification.callMeBotEndpoint" type="text" class="form-control" required>
        <i18n-t tag="div" keypath="callMeBotGet" class="form-text">
            <a href="https://www.callmebot.com/blog/free-api-facebook-messenger/" target="_blank">Facebook Messenger</a>
            <a href="https://www.callmebot.com/blog/test-whatsapp-api/" target="_blank">WhatsApp</a>
            <a href="https://www.callmebot.com/blog/telegram-phone-call-using-your-browser/" target="_blank">Telegram Call</a>
            1 message / 10 sec; 1 call / 65 sec
            <!--There is no public documentation available. This data is based on testing!-->
        </i18n-t>
    </div>
</template>
Repository: louislam/uptime-kuma
File: server/notification-providers/call-me-bot.js (JavaScript)

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

class CallMeBot extends NotificationProvider {
    name = "CallMeBot";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";
        try {
            const url = new URL(notification.callMeBotEndpoint);
            url.searchParams.delete("text");
            await axios.get(`${url}&text=${encodeURIComponent(msg)}`);
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = CallMeBot;


Review comment (suggestion):
You could simply do the folllowing which does not have implicite assumptions about the url-parameters (f.ex. containing a `?` previously)

I have not tested if `toString` is actually nessesary.

```suggestion
            url.searchParams.set("text", msg);
            await axios.get(url.toString());
```

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

class CallMeBot extends NotificationProvider {
    name = "CallMeBot";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";
        try {
            const url = new URL(notification.callMeBotEndpoint);
            url.searchParams.set("text", msg);
            await axios.get(url.toString());
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

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

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

class Cellsynt extends NotificationProvider {
    name = "Cellsynt";

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

        let data = {
            /**
             * You can find more information about the API here: https://www.cellsynt.com/en/sms/api-integration
             */
            params: {
                "username": notification.cellsyntLogin,
                "password": notification.cellsyntPassword,
                "destination": notification.cellsyntDestination,
                "text": msg.replace(/[^\x00-\x7F]/g, ""),
                "originatortype": notification.cellsyntOriginatortype,
                "originator": notification.cellsyntOriginator,
                "allowconcat": notification.cellsyntAllowLongSMS ? 6 : 1
            }
        };
        try {
            const resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
            if (resp.data == null || resp.data.includes("Error")) {
                throw new Error(resp.data);
            } else {
                return okMsg;
            }
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = Cellsynt;


Review comment (suggestion):
```suggestion
            // docs at https://www.cellsynt.com/en/sms/api-integration
```

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

class Cellsynt extends NotificationProvider {
    name = "Cellsynt";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";
        const data = {
            // docs at https://www.cellsynt.com/en/sms/api-integration
            params: {
                "username": notification.cellsyntLogin,
                "password": notification.cellsyntPassword,
                "destination": notification.cellsyntDestination,
                "text": msg.replace(/[^\x00-\x7F]/g, ""),
                "originatortype": notification.cellsyntOriginatortype,
                "originator": notification.cellsyntOriginator,
                "allowconcat": notification.cellsyntAllowLongSMS ? 6 : 1
            }
        };
        try {
            const resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
            if (resp.data == null ) {
                throw new Error("Could not connect to Cellsynt, please try again.");
            } else if (resp.data.includes("Error:")) {
                resp.data = resp.data.replaceAll("Error:", "");
                throw new Error(resp.data);
            }
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

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

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

        let data = {
            /**
             * You can find more information about the API here: https://www.cellsynt.com/en/sms/api-integration
             */
            params: {
                "username": notification.cellsyntLogin,
                "password": notification.cellsyntPassword,
                "destination": notification.cellsyntDestination,
                "text": msg.replace(/[^\x00-\x7F]/g, ""),
                "originatortype": notification.cellsyntOriginatortype,
                "originator": notification.cellsyntOriginator,
                "allowconcat": notification.cellsyntAllowLongSMS ? 6 : 1
            }
        };
        try {
            const resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
            if (resp.data == null || resp.data.includes("Error")) {
                throw new Error(resp.data);
            } else {
                return okMsg;
            }
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = Cellsynt;


Review comment (suggestion):
nit(personal preference):

```suggestion
            }
            return okMsg;
```

Code after:
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";
        const data = {
            // docs at https://www.cellsynt.com/en/sms/api-integration
            params: {
                "username": notification.cellsyntLogin,
                "password": notification.cellsyntPassword,
                "destination": notification.cellsyntDestination,
                "text": msg.replace(/[^\x00-\x7F]/g, ""),
                "originatortype": notification.cellsyntOriginatortype,
                "originator": notification.cellsyntOriginator,
                "allowconcat": notification.cellsyntAllowLongSMS ? 6 : 1
            }
        };
        try {
            const resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
            if (resp.data == null ) {
                throw new Error("Could not connect to Cellsynt, please try again.");
            } else if (resp.data.includes("Error:")) {
                resp.data = resp.data.replaceAll("Error:", "");
                throw new Error(resp.data);
            }
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

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

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

class Cellsynt extends NotificationProvider {
    name = "Cellsynt";

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

        let data = {
            /**
             * You can find more information about the API here: https://www.cellsynt.com/en/sms/api-integration
             */
            params: {
                "username": notification.cellsyntLogin,
                "password": notification.cellsyntPassword,
                "destination": notification.cellsyntDestination,
                "text": msg.replace(/[^\x00-\x7F]/g, ""),
                "originatortype": notification.cellsyntOriginatortype,
                "originator": notification.cellsyntOriginator,
                "allowconcat": notification.cellsyntAllowLongSMS ? 6 : 1
            }
        };
        try {
            const resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
            if (resp.data == null || resp.data.includes("Error")) {
                throw new Error(resp.data);
            } else {
                return okMsg;
            }
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

Review comment (suggestion):
nit:

```suggestion
        const data = {
```

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

class Cellsynt extends NotificationProvider {
    name = "Cellsynt";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";
        const data = {
            // docs at https://www.cellsynt.com/en/sms/api-integration
            params: {
                "username": notification.cellsyntLogin,
                "password": notification.cellsyntPassword,
                "destination": notification.cellsyntDestination,
                "text": msg.replace(/[^\x00-\x7F]/g, ""),
                "originatortype": notification.cellsyntOriginatortype,
                "originator": notification.cellsyntOriginator,
                "allowconcat": notification.cellsyntAllowLongSMS ? 6 : 1
            }
        };
        try {
            const resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
            if (resp.data == null ) {
                throw new Error("Could not connect to Cellsynt, please try again.");
            } else if (resp.data.includes("Error:")) {
                resp.data = resp.data.replaceAll("Error:", "");
                throw new Error(resp.data);
            }
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}
Repository: louislam/uptime-kuma
File: src/components/notifications/index.js (JavaScript)

Code before:
    "promosms": PromoSMS,
    "pushbullet": Pushbullet,
    "PushByTechulus": TechulusPush,
    "PushDeer": PushDeer,
    "pushover": Pushover,
    "pushy": Pushy,
    "rocket.chat": RocketChat,
    "serwersms": SerwerSMS,
    "signal": Signal,
    "SMSManager": SMSManager,
    "slack": Slack,
    "squadcast": Squadcast,
    "SMSEagle": SMSEagle,
    "smtp": STMP,
    "stackfield": Stackfield,
    "teams": Teams,
    "telegram": Telegram,
    "twilio": Twilio,
    "Splunk": Splunk,
    "webhook": Webhook,
    "WeCom": WeCom,
    "GoAlert": GoAlert,
    "ServerChan": ServerChan,
    "ZohoCliq": ZohoCliq,
    "gtxmessaging": GtxMessaging,
    "Cellsynt": Cellsynt
};

export default NotificationFormList;


Review comment (suggestion):
nit:
https://github.com/louislam/uptime-kuma/pull/4558#discussion_r1538361274

```suggestion
    "Cellsynt": Cellsynt,
```

Code after:
    "promosms": PromoSMS,
    "pushbullet": Pushbullet,
    "PushByTechulus": TechulusPush,
    "PushDeer": PushDeer,
    "pushover": Pushover,
    "pushy": Pushy,
    "rocket.chat": RocketChat,
    "serwersms": SerwerSMS,
    "signal": Signal,
    "SMSManager": SMSManager,
    "slack": Slack,
    "squadcast": Squadcast,
    "SMSEagle": SMSEagle,
    "smtp": STMP,
    "stackfield": Stackfield,
    "teams": Teams,
    "telegram": Telegram,
    "twilio": Twilio,
    "Splunk": Splunk,
    "webhook": Webhook,
    "WeCom": WeCom,
    "GoAlert": GoAlert,
    "ServerChan": ServerChan,
    "ZohoCliq": ZohoCliq,
    "gtxmessaging": GtxMessaging,
    "Cellsynt": Cellsynt,
};

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

Code before:
    name = "Cellsynt";

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

        let data = {
            /**
             * You can find more information about the API here: https://www.cellsynt.com/en/sms/api-integration
             */
            params: {
                "username": notification.cellsyntLogin,
                "password": notification.cellsyntPassword,
                "destination": notification.cellsyntDestination,
                "text": msg.replace(/[^\x00-\x7F]/g, ""),
                "originatortype": notification.cellsyntOriginatortype,
                "originator": notification.cellsyntOriginator,
                "allowconcat": notification.cellsyntAllowLongSMS ? 6 : 1
            }
        };
        try {
            const resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
            if (resp.data == null || resp.data.includes("Error")) {
                throw new Error(resp.data);
            } else {
                return okMsg;
            }
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = Cellsynt;


Review comment (suggestion):
I think `Error: null` might not be the best error message => lets split these two cases

Code after:
    name = "Cellsynt";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";
        const data = {
            // docs at https://www.cellsynt.com/en/sms/api-integration
            params: {
                "username": notification.cellsyntLogin,
                "password": notification.cellsyntPassword,
                "destination": notification.cellsyntDestination,
                "text": msg.replace(/[^\x00-\x7F]/g, ""),
                "originatortype": notification.cellsyntOriginatortype,
                "originator": notification.cellsyntOriginator,
                "allowconcat": notification.cellsyntAllowLongSMS ? 6 : 1
            }
        };
        try {
            const resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
            if (resp.data == null ) {
                throw new Error("Could not connect to Cellsynt, please try again.");
            } else if (resp.data.includes("Error:")) {
                resp.data = resp.data.replaceAll("Error:", "");
                throw new Error(resp.data);
            }
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

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

Code before:
const axios = require("axios");

class Cellsynt extends NotificationProvider {
    name = "Cellsynt";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";
        const data = {
            // docs at https://www.cellsynt.com/en/sms/api-integration
            params: {
                "username": notification.cellsyntLogin,
                "password": notification.cellsyntPassword,
                "destination": notification.cellsyntDestination,
                "text": msg.replace(/[^\x00-\x7F]/g, ""),
                "originatortype": notification.cellsyntOriginatortype,
                "originator": notification.cellsyntOriginator,
                "allowconcat": notification.cellsyntAllowLongSMS ? 6 : 1
            }
        };
        try {
            const resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
            if (resp.data == null ) {
                throw new Error("Error: Could not connect to Cellsynt, please try again.");
            } else if (resp.data.includes("Error:")) {
                resp.data = resp.data.replaceAll("Error:", "");
                throw new Error(resp.data);
            }
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = Cellsynt;


Review comment (suggestion):
`Error:` is already appended via the outer try-catch

```suggestion
                throw new Error("Could not connect to Cellsynt, please try again.");
```

Code after:
const axios = require("axios");

class Cellsynt extends NotificationProvider {
    name = "Cellsynt";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";
        const data = {
            // docs at https://www.cellsynt.com/en/sms/api-integration
            params: {
                "username": notification.cellsyntLogin,
                "password": notification.cellsyntPassword,
                "destination": notification.cellsyntDestination,
                "text": msg.replace(/[^\x00-\x7F]/g, ""),
                "originatortype": notification.cellsyntOriginatortype,
                "originator": notification.cellsyntOriginator,
                "allowconcat": notification.cellsyntAllowLongSMS ? 6 : 1
            }
        };
        try {
            const resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
            if (resp.data == null ) {
                throw new Error("Could not connect to Cellsynt, please try again.");
            } else if (resp.data.includes("Error:")) {
                resp.data = resp.data.replaceAll("Error:", "");
                throw new Error(resp.data);
            }
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = Cellsynt;
Repository: louislam/uptime-kuma
File: src/i18n.js (JavaScript)

Code before:
    "ge": "ქართული"
};

let messages = {
    en,
};

for (let lang in languageList) {
    messages[lang] = {
        languageName: languageList[lang]
    };
}

const rtlLangs = [ "fa", "ar-SY", "ur" ];

/**
 * Find the best matching locale to display
 * If no locale can be matched, the default is "en"
 * @returns {string} the locale that should be displayed
 */
export function currentLocale() {
    const potentialLocales = [ localStorage.locale, navigator.language, ...navigator.languages ];
    const availableLocales = potentialLocales
        .filter(l => !!l)
        .map(l => l.split("-")[0] in messages ? l.split("-")[0] : l)
        .filter(l => l in messages);
    return availableLocales[0] || "en";
}

export const localeDirection = () => {
    return rtlLangs.includes(currentLocale()) ? "rtl" : "ltr";
};

export const i18n = createI18n({
    locale: currentLocale(),
    fallbackLocale: "en",
    silentFallbackWarn: true,
    silentTranslationWarn: true,
    messages: messages,
});


Review comment (bug):
Since it is getting more conditions now, is it able to break them down into more traditional programming `for-loop` and `if-else`? Because I am a bit struggling to understand why those bugs is happening.

Also it didn't utilize the array `languageList` anymore here, make me wondering if it is really ok.

Code after:
    "ge": "ქართული"
};

let messages = {
    en,
};

for (let lang in languageList) {
    messages[lang] = {
        languageName: languageList[lang]
    };
}

const rtlLangs = [ "fa", "ar-SY", "ur" ];

/**
 * Find the best matching locale to display
 * If no locale can be matched, the default is "en"
 * @returns {string} the locale that should be displayed
 */
export function currentLocale() {
    for (const locale of [ localStorage.locale, navigator.language, ...navigator.languages ]) {
        // localstorage might not have a value or there might not be a language in `navigator.language`
        if (!locale) {
            continue;
        }
        if (locale in messages) {
            return locale;
        }
        // some locales are further specified such as "en-US".
        // If we only have a generic locale for this, we can use it too
        const genericLocale = locale.split("-")[0];
        if (genericLocale in messages) {
            return genericLocale;
        }
    }
    return "en";
}

export const localeDirection = () => {
    return rtlLangs.includes(currentLocale()) ? "rtl" : "ltr";
};

export const i18n = createI18n({
    locale: currentLocale(),
    fallbackLocale: "en",
    silentFallbackWarn: true,
    silentTranslationWarn: true,
    messages: messages,
});