"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.prInfo = exports.buildStates = exports.prStates = exports.mergeBodyTransformer = exports.repoInfoTransformer = void 0;
const pr_body_1 = require("../pr-body");
function repoInfoTransformer(repoInfoBody) {
    return {
        isFork: !!repoInfoBody.parent,
        owner: repoInfoBody.owner.username,
        mainbranch: repoInfoBody.mainbranch.name,
        mergeMethod: 'merge',
        has_issues: repoInfoBody.has_issues,
        uuid: repoInfoBody.uuid,
    };
}
exports.repoInfoTransformer = repoInfoTransformer;
const bitbucketMergeStrategies = new Map([
    ['squash', 'squash'],
    ['merge-commit', 'merge_commit'],
    ['fast-forward', 'fast_forward'],
]);
function mergeBodyTransformer(mergeStrategy) {
    const body = {
        close_source_branch: true,
    };
    // The `auto` strategy will use the strategy configured inside Bitbucket.
    if (mergeStrategy && mergeStrategy !== 'auto') {
        body.merge_strategy = bitbucketMergeStrategies.get(mergeStrategy);
    }
    return body;
}
exports.mergeBodyTransformer = mergeBodyTransformer;
exports.prStates = {
    open: ['OPEN'],
    notOpen: ['MERGED', 'DECLINED', 'SUPERSEDED'],
    merged: ['MERGED'],
    closed: ['DECLINED', 'SUPERSEDED'],
    all: ['OPEN', 'MERGED', 'DECLINED', 'SUPERSEDED'],
};
exports.buildStates = {
    green: 'SUCCESSFUL',
    red: 'FAILED',
    yellow: 'INPROGRESS',
};
function prInfo(pr) {
    return {
        number: pr.id,
        bodyStruct: (0, pr_body_1.getPrBodyStruct)(pr.summary?.raw),
        sourceBranch: pr.source?.branch?.name,
        targetBranch: pr.destination?.branch?.name,
        title: pr.title,
        state: exports.prStates.closed?.includes(pr.state)
            ? /* istanbul ignore next */ 'closed'
            : pr.state?.toLowerCase(),
        createdAt: pr.created_on,
    };
}
exports.prInfo = prInfo;
//# sourceMappingURL=utils.js.map