"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setPrCache = exports.getPrCache = void 0;
const logger_1 = require("../../../../logger");
const repository_1 = require("../../../../util/cache/repository");
function getPrCache(branchName) {
    logger_1.logger.debug(`getPrCache()`);
    const cache = (0, repository_1.getCache)();
    const branch = cache.branches?.find((branch) => branchName === branch.branchName);
    if (!branch?.prCache) {
        return null;
    }
    return branch.prCache;
}
exports.getPrCache = getPrCache;
// store the time a PR was last updated
function setPrCache(branchName, fingerprint, prModified) {
    logger_1.logger.debug(`setPrCache()`);
    const cache = (0, repository_1.getCache)();
    const branch = cache.branches?.find((branch) => branchName === branch.branchName);
    if (!branch) {
        logger_1.logger.debug(`setPrCache(): Branch cache not present`);
        return;
    }
    const lastEdited = branch.prCache?.lastEdited;
    branch.prCache = {
        fingerprint,
        // update time when creating new cache or when pr was modified
        lastEdited: lastEdited && !prModified ? lastEdited : new Date().toISOString(),
    };
}
exports.setPrCache = setPrCache;
//# sourceMappingURL=pr-cache.js.map