"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runBranchSummary = exports.runRenovateRepoStats = void 0;
const logger_1 = require("../../../logger");
const types_1 = require("../../../types");
const repository_1 = require("../../../util/cache/repository");
function runRenovateRepoStats(config, prList) {
    const prStats = { total: 0, open: 0, closed: 0, merged: 0 };
    for (const pr of prList) {
        if (pr.title === 'Configure Renovate' ||
            pr.title === config.onboardingPrTitle) {
            continue;
        }
        prStats.total += 1;
        switch (pr.state) {
            case types_1.PrState.Merged:
                prStats.merged += 1;
                break;
            case types_1.PrState.Closed:
                prStats.closed += 1;
                break;
            case types_1.PrState.Open:
                prStats.open += 1;
                break;
            default:
                break;
        }
    }
    logger_1.logger.debug({ stats: prStats }, `Renovate repository PR statistics`);
}
exports.runRenovateRepoStats = runRenovateRepoStats;
function branchCacheToMetadata({ branchName, sha: branchSha, baseBranch, parentSha: baseBranchSha, automerge, isModified, }) {
    return {
        branchName,
        branchSha,
        baseBranch,
        baseBranchSha,
        automerge,
        isModified,
    };
}
function runBranchSummary() {
    const { scan, branches } = (0, repository_1.getCache)();
    const baseMetadata = [];
    for (const [branchName, cached] of Object.entries(scan ?? {})) {
        baseMetadata.push({ branchName, sha: cached.sha });
    }
    const branchMetadata = [];
    const inactiveBranches = [];
    for (const branch of branches ?? []) {
        if (branch.sha) {
            branchMetadata.push(branchCacheToMetadata(branch));
        }
        else {
            inactiveBranches.push(branch.branchName);
        }
    }
    const res = {
        cacheModified: (0, repository_1.isCacheModified)(),
        baseBranches: baseMetadata,
        branches: branchMetadata,
        inactiveBranches,
    };
    logger_1.logger.debug(res, 'Branch summary');
}
exports.runBranchSummary = runBranchSummary;
//# sourceMappingURL=repository-statistics.js.map