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

Code before:
                case "steam":
                    address = monitorJSON["hostname"];
                    if (monitorJSON["port"]) {
                        address += ":" + monitorJSON["port"];
                    }
                    break;
                default:
                    address = monitorJSON["url"];
                    break;
            }

            // If heartbeatJSON is not null, we go into the normal alerting loop.
            if (heartbeatJSON["status"] === DOWN) {
                data.text = `Your service ${monitorJSON["name"]} (${address}) went down at ${heartbeatJSON["localDateTime"]} ` +
                    `(${heartbeatJSON["timezone"]}). Error: ${heartbeatJSON["msg"]}`;

                await axios.post("sms", data);
                return okMsg;

            } else if (heartbeatJSON["status"] === UP) {
                data.text = `Your service ${monitorJSON["name"]} (${address}) went back up at ${heartbeatJSON["localDateTime"]} ` +
                    `(${heartbeatJSON["timezone"]}).`;

                await axios.post("sms", data);
                return okMsg;
            }
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }

}

module.exports = SevenIO;


Review comment (suggestion):
this can be simplified minorly

```suggestion
            } else if (heartbeatJSON["status"] === UP) {
                data.text = `Your service ${monitorJSON["name"]} (${address}) went back up at ${heartbeatJSON["localDateTime"]} ` +
                    `(${heartbeatJSON["timezone"]}).`;
            }
            await axios.post("sms", data);
            return okMsg;
```

Code after:
                    address = monitorJSON["hostname"];
                    if (monitorJSON["port"]) {
                        address += ":" + monitorJSON["port"];
                    }
                    break;
                default:
                    if (![ "https://", "http://", "" ].includes(monitorJSON["url"])) {
                        address = monitorJSON["url"];
                    }
                    break;
            }

            if (address !== "") {
                address = `(${address}) `;
            }

            // If heartbeatJSON is not null, we go into the normal alerting loop.
            if (heartbeatJSON["status"] === DOWN) {
                data.text = `Your service ${monitorJSON["name"]} ${address}went down at ${heartbeatJSON["localDateTime"]} ` +
                    `(${heartbeatJSON["timezone"]}). Error: ${heartbeatJSON["msg"]}`;
            } else if (heartbeatJSON["status"] === UP) {
                data.text = `Your service ${monitorJSON["name"]} ${address}went back up at ${heartbeatJSON["localDateTime"]} ` +
                    `(${heartbeatJSON["timezone"]}).`;
            }
            await axios.post("sms", data, config);
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }

}

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

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

class SevenIO extends NotificationProvider {

    name = "SevenIO";

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

        const data = {
            to: notification.sevenioTo,
            from: notification.sevenioSender || "Uptime Kuma",
            text: msg,
        };

        const axios = Axios.create({
            baseURL: "https://gateway.seven.io/api/",
            headers: {
                "Content-Type": "application/json",
                "X-API-Key": notification.sevenioApiKey,
            },
        });

Review comment (suggestion):
let^'s not be special here ^^

```suggestion
const axios = require("axios");
```

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

class SevenIO extends NotificationProvider {
    name = "SevenIO";

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

        const data = {
            to: notification.sevenioTo,
            from: notification.sevenioSender || "Uptime Kuma",
            text: msg,
        };

        const config = {
            baseURL: "https://gateway.seven.io/api/",
            headers: {
                "Content-Type": "application/json",
                "X-API-Key": notification.sevenioApiKey,
            },
        };
Repository: louislam/uptime-kuma
File: server/notification-providers/sevenio.js (JavaScript)

Code before:
                case "steam":
                    address = monitorJSON["hostname"];
                    if (monitorJSON["port"]) {
                        address += ":" + monitorJSON["port"];
                    }
                    break;
                default:
                    if (![ "https://", "http://", "" ].includes(monitorJSON["url"])) {
                        address = monitorJSON["url"];
                    }
                    break;
            }

            if (address !== "") {
                address = `(${address}) `;
            }

            // If heartbeatJSON is not null, we go into the normal alerting loop.
            if (heartbeatJSON["status"] === DOWN) {
                data.text = `Your service ${monitorJSON["name"]} ${address}went down at ${heartbeatJSON["localDateTime"]} ` +
                    `(${heartbeatJSON["timezone"]}). Error: ${heartbeatJSON["msg"]}`;
            } else if (heartbeatJSON["status"] === UP) {
                data.text = `Your service ${monitorJSON["name"]} ${address}went back up at ${heartbeatJSON["localDateTime"]} ` +
                    `(${heartbeatJSON["timezone"]}).`;
            }
            await axios.post("sms", data);
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }

}

module.exports = SevenIO;


Review comment (suggestion):
```suggestion
            await axios.post("sms", data, config);
```

Code after:
                    address = monitorJSON["hostname"];
                    if (monitorJSON["port"]) {
                        address += ":" + monitorJSON["port"];
                    }
                    break;
                default:
                    if (![ "https://", "http://", "" ].includes(monitorJSON["url"])) {
                        address = monitorJSON["url"];
                    }
                    break;
            }

            if (address !== "") {
                address = `(${address}) `;
            }

            // If heartbeatJSON is not null, we go into the normal alerting loop.
            if (heartbeatJSON["status"] === DOWN) {
                data.text = `Your service ${monitorJSON["name"]} ${address}went down at ${heartbeatJSON["localDateTime"]} ` +
                    `(${heartbeatJSON["timezone"]}). Error: ${heartbeatJSON["msg"]}`;
            } else if (heartbeatJSON["status"] === UP) {
                data.text = `Your service ${monitorJSON["name"]} ${address}went back up at ${heartbeatJSON["localDateTime"]} ` +
                    `(${heartbeatJSON["timezone"]}).`;
            }
            await axios.post("sms", data, config);
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }

}

module.exports = SevenIO;
Repository: louislam/uptime-kuma
File: test/cypress/unit/i18n.spec.js (JavaScript)

Code before:
import { currentLocale } from "../../../src/i18n";

describe("Test i18n.js", () => {

    it("currentLocale()", () => {
        const setLanguage = (language) => {
            Object.defineProperty(window.navigator, 'language', {
                value: language,
                writable: true
            });
            Object.defineProperty(window.navigator, 'languages', {
                value: [language],
                writable: true
            });
        }

        setLanguage('en-EN');
        expect(currentLocale()).equal("en");

        setLanguage('zh-HK');
        expect(currentLocale()).equal("zh-HK");

        // Note that in Safari on iOS prior to 10.2, the country code returned is lowercase: "en-us", "fr-fr" etc.
        // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language
        setLanguage('zh-hk');
        expect(currentLocale()).equal("en");

        setLanguage('en-US');
        expect(currentLocale()).equal("en");

        setLanguage('ja-ZZ');
        expect(currentLocale()).equal("ja");

        setLanguage('zz-ZZ');
        expect(currentLocale()).equal("en");

        setLanguage('zz-ZZ');
        expect(currentLocale()).equal("en");

        setLanguage('en');
        localStorage.locale = "en";
        expect(currentLocale()).equal("en");

Review comment (suggestion):
```suggestion
        setLanguage('en-EN');

```

Code after:
import { currentLocale } from "../../../src/i18n";

describe("Test i18n.js", () => {

    it("currentLocale()", () => {
        const setLanguage = (language) => {
            Object.defineProperty(window.navigator, 'language', {
                value: language,
                writable: true
            });
            Object.defineProperty(window.navigator, 'languages', {
                value: [language],
                writable: true
            });
        }
        setLanguage('en-EN');

        expect(currentLocale()).equal("en");

        setLanguage('zh-HK');
        expect(currentLocale()).equal("zh-HK");

        // Note that in Safari on iOS prior to 10.2, the country code returned is lowercase: "en-us", "fr-fr" etc.
        // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language
        setLanguage('zh-hk');
        expect(currentLocale()).equal("en");

        setLanguage('en-US');
        expect(currentLocale()).equal("en");

        setLanguage('ja-ZZ');
        expect(currentLocale()).equal("ja");

        setLanguage('zz-ZZ');
        expect(currentLocale()).equal("en");

        setLanguage('zz-ZZ');
        expect(currentLocale()).equal("en");

        setLanguage('en');
        localStorage.locale = "en";
        expect(currentLocale()).equal("en");
Repository: louislam/uptime-kuma
File: src/i18n.js (JavaScript)

Code before:
    "yue": "繁體中文 (廣東話 / 粵語)",
    "ro": "Limba română",
    "ur": "Urdu",
    "ge": "ქართული"
};

let messages = {
    en,
};

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

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

export const currentLocale = () => localStorage.locale
    || languageList[navigator.language] && navigator.language
    || languageList[navigator.language.substring(0, 2)] && navigator.language.substring(0, 2)
    || "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 (suggestion):
This will always skip English because `en` (or its variants like `en-US`) is not present in `languageList`. Users with browser configured to send multiple supported locales will always have interface rendered in first non-English language.

Code after:
    "yue": "繁體中文 (廣東話 / 粵語)",
    "ro": "Limba română",
    "ur": "Urdu",
    "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.language.substring(0, 2), ...navigator.languages ];
    const availableLocales = potentialLocales.filter(l => languageList[l]);
    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,
});
Repository: louislam/uptime-kuma
File: server/notification-providers/whapi.js (JavaScript)

Code before:
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {

        let okMsg = "Sent Successfully.";

        let apiUrl = notification.whapiApiUrl;
        let apiToken = notification.whapiAuthToken;
        let toNumber = notification.whapiToNumber;

        try {

            let config = {
                headers: {
                    "Accept": "application/json",
                    "Content-Type": "application/json",
                    "Authorization": "Bearer " + apiToken,
                }
            };

            let data = {
                "to": toNumber + "@s.whatsapp.net",
                "body": msg,
            };

            let url = apiUrl + "/messages/text";

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

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

}

module.exports = Whapi;


Review comment (security):
nit:
- I would prefer to not having the variables extracted as I don't see a good reason for his behaviour
- and using `const` instead of `let`

```suggestion
        try {
            const config = {
                headers: {
                    "Accept": "application/json",
                    "Content-Type": "application/json",
                    "Authorization": "Bearer " + notification.whapiAuthToken,
                }
            };

            const data = {
                "to": notification.whapiToNumber + "@s.whatsapp.net",
                "body": msg,
            };

            const url = notification.whapiApiUrl + "/messages/text";

            await axios.post(url, data, config);
```

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

        try {
            const config = {
                headers: {
                    "Accept": "application/json",
                    "Content-Type": "application/json",
                    "Authorization": "Bearer " + notification.whapiAuthToken,
                }
            };

            let data = {
                "to": notification.whapiRecipient,
                "body": msg,
            };

            let url = (notification.whapiApiUrl || "https://gate.whapi.cloud/").replace(/\/+$/, "") + "/messages/text";

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

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

}

module.exports = Whapi;
Repository: louislam/uptime-kuma
File: src/components/notifications/Whapi.vue (Vue)

Code before:
<template>
    <div class="mb-3">
        <label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label>
        <input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" type="text" class="form-control" required>
    </div>

    <div class="mb-3">
        <label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
        <input id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" type="text" class="form-control" required>
    </div>

    <div class="mb-3">
        <label for="whapi-to-number" class="form-label">{{ $t("Phone number") }}</label>
        <input id="whapi-to-number" v-model="$parent.notification.whapiToNumber" type="text" pattern="^[\d-]{10,31}$" class="form-control" required>
        <i18n-t tag="div" keypath="wayToWriteWhapiPhoneNumber" class="form-text"></i18n-t>
    </div>

    <div class="mb-3">
        <i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
            <a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
        </i18n-t>
    </div>
</template>


Review comment (suggestion):
Please add a placeholder how the url should look and/or add a helptext how it can be obtained.

Currently, you are appending `/messages/text` to this url might not be transparent to users.

Code after:
<template>
    <div class="mb-3">
        <label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label>
        <input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" placeholder="https://gate.whapi.cloud/" type="text" class="form-control">
    </div>

    <div class="mb-3">
        <label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
        <HiddenInput id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" :required="true" autocomplete="new-password"></HiddenInput>
        <i18n-t tag="div" keypath="wayToGetWhapiUrlAndToken" class="form-text">
            <a href="https://panel.whapi.cloud/dashboard" target="_blank">https://panel.whapi.cloud/dashboard</a>
        </i18n-t>
    </div>

    <div class="mb-3">
        <label for="whapi-recipient" class="form-label">{{ $t("whapiRecipient") }}</label>
        <input id="whapi-recipient" v-model="$parent.notification.whapiRecipient" type="text" pattern="^[\d-]{10,31}(@[\w\.]{1,})?$" class="form-control" required>
        <div class="form-text">{{ $t("wayToWriteWhapiRecipient", ["00117612345678", "00117612345678@s.whatsapp.net", "123456789012345678@g.us"]) }}</div>
    </div>

    <i18n-t tag="div" keypath="More info on:" class="mb-3 form-text">
        <a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
    </i18n-t>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";

export default {
    components: {
Repository: louislam/uptime-kuma
File: src/components/notifications/Whapi.vue (Vue)

Code before:
<template>
    <div class="mb-3">
        <label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label>
        <input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" type="text" class="form-control" required>
    </div>

    <div class="mb-3">
        <label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
        <input id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" type="text" class="form-control" required>
    </div>

    <div class="mb-3">
        <label for="whapi-to-number" class="form-label">{{ $t("Phone number") }}</label>
        <input id="whapi-to-number" v-model="$parent.notification.whapiToNumber" type="text" pattern="^[\d-]{10,31}$" class="form-control" required>
        <i18n-t tag="div" keypath="wayToWriteWhapiPhoneNumber" class="form-text"></i18n-t>
    </div>

    <div class="mb-3">
        <i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
            <a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
        </i18n-t>
    </div>
</template>


Review comment (suggestion):
Please component translations only if you need to embed html in this translation.

```suggestion
        <div class="form-text">{{ t("wayToWriteWhapiPhoneNumber") }}</div>
```

Please also consider if adding an example phone number might make setting this up eazier like this and including it via `{0}` in the translation

```suggestion
        <div class="form-text">{{ t("wayToWriteWhapiPhoneNumber", ["00117612345678"]) }}</div>
```

Code after:
<template>
    <div class="mb-3">
        <label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label>
        <input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" placeholder="https://gate.whapi.cloud/" type="text" class="form-control">
    </div>

    <div class="mb-3">
        <label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
        <HiddenInput id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" :required="true" autocomplete="new-password"></HiddenInput>
        <i18n-t tag="div" keypath="wayToGetWhapiUrlAndToken" class="form-text">
            <a href="https://panel.whapi.cloud/dashboard" target="_blank">https://panel.whapi.cloud/dashboard</a>
        </i18n-t>
    </div>

    <div class="mb-3">
        <label for="whapi-recipient" class="form-label">{{ $t("whapiRecipient") }}</label>
        <input id="whapi-recipient" v-model="$parent.notification.whapiRecipient" type="text" pattern="^[\d-]{10,31}(@[\w\.]{1,})?$" class="form-control" required>
        <div class="form-text">{{ $t("wayToWriteWhapiRecipient", ["00117612345678", "00117612345678@s.whatsapp.net", "123456789012345678@g.us"]) }}</div>
    </div>

    <i18n-t tag="div" keypath="More info on:" class="mb-3 form-text">
        <a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
    </i18n-t>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";

export default {
    components: {
        HiddenInput,
    }
};
</script>
Repository: louislam/uptime-kuma
File: src/components/notifications/Whapi.vue (Vue)

Code before:
<template>
    <div class="mb-3">
        <label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label>
        <input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" type="text" class="form-control" required>
    </div>

    <div class="mb-3">
        <label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
        <input id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" type="text" class="form-control" required>
    </div>

    <div class="mb-3">
        <label for="whapi-to-number" class="form-label">{{ $t("Phone number") }}</label>
        <input id="whapi-to-number" v-model="$parent.notification.whapiToNumber" type="text" pattern="^[\d-]{10,31}$" class="form-control" required>
        <i18n-t tag="div" keypath="wayToWriteWhapiPhoneNumber" class="form-text"></i18n-t>
    </div>

    <div class="mb-3">
        <i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
            <a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
        </i18n-t>
    </div>
</template>


Review comment (suggestion):
Please add all translations to the `en.json`. If not done for every one, this string will not be able to be translated.

Code after:
<template>
    <div class="mb-3">
        <label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label>
        <input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" placeholder="https://gate.whapi.cloud/" type="text" class="form-control">
    </div>

    <div class="mb-3">
        <label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
        <HiddenInput id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" :required="true" autocomplete="new-password"></HiddenInput>
        <i18n-t tag="div" keypath="wayToGetWhapiUrlAndToken" class="form-text">
            <a href="https://panel.whapi.cloud/dashboard" target="_blank">https://panel.whapi.cloud/dashboard</a>
        </i18n-t>
    </div>

    <div class="mb-3">
        <label for="whapi-recipient" class="form-label">{{ $t("whapiRecipient") }}</label>
        <input id="whapi-recipient" v-model="$parent.notification.whapiRecipient" type="text" pattern="^[\d-]{10,31}(@[\w\.]{1,})?$" class="form-control" required>
        <div class="form-text">{{ $t("wayToWriteWhapiRecipient", ["00117612345678", "00117612345678@s.whatsapp.net", "123456789012345678@g.us"]) }}</div>
    </div>

    <i18n-t tag="div" keypath="More info on:" class="mb-3 form-text">
        <a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
    </i18n-t>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";

export default {
    components: {
        HiddenInput,
    }
};
</script>