"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findSourceUrl = findSourceUrl;
const common_1 = require("../../../util/common");
const url_1 = require("../../../util/git/url");
const regex_1 = require("../../../util/regex");
const chartRepo = (0, regex_1.regEx)(/charts?|helm|helm-charts/i);
const githubRelease = (0, regex_1.regEx)(/^(https:\/\/github\.com\/[^/]+\/[^/]+)\/releases\//);
function isPossibleChartRepo(url) {
    if ((0, common_1.detectPlatform)(url) === null) {
        return false;
    }
    const parsed = (0, url_1.parseGitUrl)(url);
    return chartRepo.test(parsed.name);
}
function findSourceUrl(release) {
    // it's a github release :)
    const releaseMatch = githubRelease.exec(release.urls[0]);
    if (releaseMatch) {
        return releaseMatch[1];
    }
    if (release.home && isPossibleChartRepo(release.home)) {
        return release.home;
    }
    if (!release.sources?.length) {
        return null;
    }
    for (const url of release.sources) {
        if (isPossibleChartRepo(url)) {
            return url;
        }
    }
    // fallback
    return release.sources[0];
}
//# sourceMappingURL=common.js.map