"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkGithubToken = void 0;
const tslib_1 = require("tslib");
const global_1 = require("../config/global");
const logger_1 = require("../logger");
const github_releases_1 = require("../modules/datasource/github-releases");
const github_tags_1 = require("../modules/datasource/github-tags");
const memCache = tslib_1.__importStar(require("../util/cache/memory"));
const hostRules = tslib_1.__importStar(require("./host-rules"));
function checkGithubToken(packageFiles) {
    const { token } = hostRules.find({
        hostType: 'github',
        url: 'https://api.github.com',
    });
    if (token) {
        logger_1.logger.trace('GitHub token is found');
        return;
    }
    if (!global_1.GlobalConfig.get('githubTokenWarn')) {
        logger_1.logger.trace('GitHub token warning is disabled');
        return;
    }
    const githubDeps = [];
    for (const files of Object.values(packageFiles ?? {})) {
        for (const file of files ?? []) {
            for (const dep of file.deps ?? []) {
                if (!dep.skipReason &&
                    (dep.datasource === github_tags_1.GithubTagsDatasource.id ||
                        dep.datasource === github_releases_1.GithubReleasesDatasource.id)) {
                    dep.skipReason = 'github-token-required';
                    if (dep.depName) {
                        githubDeps.push(dep.depName);
                    }
                }
            }
        }
    }
    if (githubDeps.length > 0) {
        const warningLogged = memCache.get('github-token-required-warning-logged');
        if (!warningLogged) {
            logger_1.logger.warn({ githubDeps }, `GitHub token is required for some dependencies`);
            memCache.set('github-token-required-warning-logged', true);
        }
    }
}
exports.checkGithubToken = checkGithubToken;
//# sourceMappingURL=check-token.js.map