"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.detectPlatform = void 0;
const tslib_1 = require("tslib");
const constants_1 = require("../constants");
const hostRules = tslib_1.__importStar(require("./host-rules"));
const url_1 = require("./url");
/**
 * Tries to detect the `platform` from a url.
 *
 * @param url the url to detect `platform` from
 * @returns matched `platform` if found, otherwise `null`
 */
function detectPlatform(url) {
    const { hostname } = (0, url_1.parseUrl)(url) ?? {};
    if (hostname === 'dev.azure.com' || hostname?.endsWith('.visualstudio.com')) {
        return 'azure';
    }
    if (hostname === 'bitbucket.org' || hostname?.includes('bitbucket')) {
        return 'bitbucket';
    }
    if (hostname &&
        (['gitea.com', 'codeberg.org'].includes(hostname) ||
            hostname.includes('gitea') ||
            hostname.includes('forgejo'))) {
        return 'gitea';
    }
    if (hostname === 'github.com' || hostname?.includes('github')) {
        return 'github';
    }
    if (hostname === 'gitlab.com' || hostname?.includes('gitlab')) {
        return 'gitlab';
    }
    const hostType = hostRules.hostType({ url });
    if (!hostType) {
        return null;
    }
    if (constants_1.BITBUCKET_API_USING_HOST_TYPES.includes(hostType)) {
        return 'bitbucket';
    }
    if (constants_1.GITEA_API_USING_HOST_TYPES.includes(hostType)) {
        return 'gitea';
    }
    if (constants_1.GITHUB_API_USING_HOST_TYPES.includes(hostType)) {
        return 'github';
    }
    if (constants_1.GITLAB_API_USING_HOST_TYPES.includes(hostType)) {
        return 'gitlab';
    }
    return null;
}
exports.detectPlatform = detectPlatform;
//# sourceMappingURL=common.js.map