"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createConfigMigrationBranch = void 0;
const global_1 = require("../../../../config/global");
const logger_1 = require("../../../../logger");
const commit_1 = require("../../../../modules/platform/commit");
const git_1 = require("../../../../util/git");
const common_1 = require("../common");
const commit_message_1 = require("./commit-message");
const migrated_data_1 = require("./migrated-data");
async function createConfigMigrationBranch(config, migratedConfigData) {
    logger_1.logger.debug('createConfigMigrationBranch()');
    const configFileName = migratedConfigData.filename;
    logger_1.logger.debug('Creating config migration branch');
    const commitMessageFactory = new commit_message_1.ConfigMigrationCommitMessageFactory(config, configFileName);
    const commitMessage = commitMessageFactory.getCommitMessage();
    // istanbul ignore if
    if (global_1.GlobalConfig.get('dryRun')) {
        logger_1.logger.info('DRY-RUN: Would commit files to config migration branch');
        return Promise.resolve(null);
    }
    await (0, git_1.checkoutBranch)(config.defaultBranch);
    const contents = await migrated_data_1.MigratedDataFactory.applyPrettierFormatting(migratedConfigData);
    return (0, commit_1.commitAndPush)({
        baseBranch: config.defaultBranch,
        branchName: (0, common_1.getMigrationBranchName)(config),
        files: [
            {
                type: 'addition',
                path: configFileName,
                contents,
            },
        ],
        message: commitMessage.toString(),
        platformCommit: !!config.platformCommit,
    });
}
exports.createConfigMigrationBranch = createConfigMigrationBranch;
//# sourceMappingURL=create.js.map