"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractPackageFile = extractPackageFile;
const tslib_1 = require("tslib");
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const logger_1 = require("../../../logger");
const yaml_1 = require("../../../util/yaml");
const extract_1 = require("../dockerfile/extract");
function extractPackageFile(content, packageFile) {
    const deps = [];
    try {
        // TODO: fix types
        const doc = (0, yaml_1.parseSingleYaml)(content);
        if (doc?.steps && is_1.default.array(doc.steps)) {
            for (const step of doc.steps) {
                if (step.name) {
                    const dep = (0, extract_1.getDep)(step.name);
                    logger_1.logger.trace({
                        depName: dep.depName,
                        currentValue: dep.currentValue,
                        currentDigest: dep.currentDigest,
                    }, 'Cloud Build docker image');
                    deps.push(dep);
                }
            }
        }
    }
    catch (err) /* istanbul ignore next */ {
        if (err.stack?.startsWith('YAMLException:')) {
            logger_1.logger.debug({ err, packageFile }, 'YAML exception extracting Docker images from a Cloud Build configuration file.');
        }
        else {
            logger_1.logger.debug({ err, packageFile }, 'Error extracting Docker images from a Cloud Build configuration file.');
        }
    }
    if (!deps.length) {
        return null;
    }
    return { deps };
}
//# sourceMappingURL=extract.js.map