"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.needsChangelogs = exports.embedChangelogs = exports.embedChangelog = void 0;
const tslib_1 = require("tslib");
const p_map_1 = tslib_1.__importDefault(require("p-map"));
const template_1 = require("../../../util/template");
const changelog_1 = require("../update/pr/changelog");
async function embedChangelog(upgrade) {
    // getChangeLogJSON returns null on error, so don't try again
    if (upgrade.logJSON !== undefined) {
        return;
    }
    upgrade.logJSON = await (0, changelog_1.getChangeLogJSON)(upgrade);
}
exports.embedChangelog = embedChangelog;
async function embedChangelogs(branches) {
    await (0, p_map_1.default)(branches, embedChangelog, { concurrency: 10 });
}
exports.embedChangelogs = embedChangelogs;
function needsChangelogs(upgrade, fields = template_1.exposedConfigOptions.filter((o) => o !== 'commitBody')) {
    // commitBody is now compiled when commit is done
    for (const field of fields) {
        // fields set by `getChangeLogJSON`
        if ((0, template_1.containsTemplates)(upgrade[field], ['logJSON', 'releases'])) {
            return true;
        }
    }
    return false;
}
exports.needsChangelogs = needsChangelogs;
//# sourceMappingURL=index.js.map