"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.gitDependency = void 0;
const tslib_1 = require("tslib");
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const github_url_from_git_1 = tslib_1.__importDefault(require("github-url-from-git"));
const github_releases_1 = require("../../../datasource/github-releases");
function gitDependency({ rule: depType, name: depName, tag: currentValue, commit: currentDigest, remote, }) {
    let dep = null;
    if (depType === 'git_repository' &&
        is_1.default.string(depName) &&
        (is_1.default.string(currentValue) || is_1.default.string(currentDigest)) &&
        is_1.default.string(remote)) {
        dep = {
            datasource: github_releases_1.GithubReleasesDatasource.id,
            depType,
            depName,
        };
        if (is_1.default.string(currentValue)) {
            dep.currentValue = currentValue;
        }
        if (is_1.default.string(currentDigest)) {
            dep.currentDigest = currentDigest;
        }
        // TODO: Check if we really need to use parse here or if it should always be a plain https url (#9605)
        const packageName = (0, github_url_from_git_1.default)(remote)?.substring('https://github.com/'.length);
        // istanbul ignore else
        if (packageName) {
            dep.packageName = packageName;
        }
        else {
            dep.skipReason = 'unsupported-remote';
        }
    }
    return dep;
}
exports.gitDependency = gitDependency;
//# sourceMappingURL=git.js.map