"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractPackageFile = void 0;
const tslib_1 = require("tslib");
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const js_yaml_1 = require("js-yaml");
const logger_1 = require("../../../logger");
const extract_1 = require("../dockerfile/extract");
function extractPackageFile(content, fileName, extractConfig) {
    logger_1.logger.debug('woodpecker.extractPackageFile()');
    let config;
    try {
        // TODO: fix me (#9610)
        config = (0, js_yaml_1.load)(content, { json: true });
        if (!config) {
            logger_1.logger.debug({ fileName }, 'Null config when parsing Woodpecker Configuration content');
            return null;
        }
        if (typeof config !== 'object') {
            logger_1.logger.debug({ fileName, type: typeof config }, 'Unexpected type for Woodpecker Configuration content');
            return null;
        }
    }
    catch (err) {
        logger_1.logger.debug({ fileName, err }, 'Error parsing Woodpecker Configuration config YAML');
        return null;
    }
    // Image name/tags for services are only eligible for update if they don't
    // use variables and if the image is not built locally
    const deps = Object.values(config.pipeline ?? {})
        .filter((step) => is_1.default.string(step?.image))
        .map((step) => (0, extract_1.getDep)(step.image, true, extractConfig.registryAliases));
    logger_1.logger.trace({ deps }, 'Woodpecker Configuration image');
    return deps.length ? { deps } : null;
}
exports.extractPackageFile = extractPackageFile;
//# sourceMappingURL=extract.js.map