"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.goDependency = void 0;
const tslib_1 = require("tslib");
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const regex_1 = require("../../../../util/regex");
const go_1 = require("../../../datasource/go");
function goDependency({ rule: depType, name: depName, tag: currentValue, commit: currentDigest, importpath: packageName, remote, }) {
    let dep = null;
    if (depType === 'go_repository' &&
        is_1.default.string(depName) &&
        (is_1.default.string(currentValue) || is_1.default.string(currentDigest)) &&
        is_1.default.string(packageName)) {
        dep = {
            datasource: go_1.GoDatasource.id,
            depType,
            depName,
            packageName,
        };
        if (is_1.default.string(currentValue)) {
            dep.currentValue = currentValue;
        }
        if (is_1.default.string(currentDigest)) {
            dep.currentValue = 'v0.0.0';
            dep.currentDigest = currentDigest;
            dep.currentDigestShort = currentDigest.substring(0, 7);
            dep.digestOneAndOnly = true;
        }
        if (is_1.default.string(remote)) {
            const remoteMatch = (0, regex_1.regEx)(/https:\/\/github\.com(?:.*\/)(([a-zA-Z]+)([-])?([a-zA-Z]+))/).exec(remote);
            if (remoteMatch && remoteMatch[0].length === remote.length) {
                dep.packageName = remote.replace('https://', '');
            }
            else {
                dep.skipReason = 'unsupported-remote';
            }
        }
    }
    return dep;
}
exports.goDependency = goDependency;
//# sourceMappingURL=go.js.map