'use strict';
import { execSyncCommand } from '../tools/exec.js';
import { environmentVariables, ciAutomergeVerboseArgument, defaultAutomergeNumberOfMrs } from '../constants/ci-constants.js';
import { folders, files, packagesPath } from '../../../base-repo/app-constants/project-paths.js';
import { createEarlyInfraError } from '../tools/create-early-infra-error.js';
import { cliLogSeparator } from '../../../fd-toolbox/logging/cli-logger.js';
import { getBooleanEnvSetting, getStringEnvSetting, getNumberEnvSetting } from '../../../fd-toolbox/infra/env-functions.js';
import { toolboxEnvSettingKeys } from '../../../fd-toolbox/infra/toolbox-env-setting-keys.js';
import { npxCommands } from '../constants/npm-commands.js';
import { configureUser, configureCiToken, submoduleUpdate } from '../tools/git.js';

var __defProp=Object['defineProperty'],__name=(_0x19d3ba,_0x1030b7)=>__defProp(_0x19d3ba,'name',{'value':_0x1030b7,'configurable':!![]});function ciAutoMerge(){const _0x127576=getNumberOfMrsToProcess(),_0x226be2=getBooleanEnvSetting(environmentVariables['ciAutomergeVerbose']),_0x4efd5e=_0x226be2?ciAutomergeVerboseArgument:'';configureUser(),configureCiToken(),cliLogSeparator(),submoduleUpdate(),cliLogSeparator();const _0x263812=getStringEnvSetting(toolboxEnvSettingKeys['fdGitlabProjectId']),_0x15abd6=getStringEnvSetting(environmentVariables['ciProjectId']),_0x23ab48=_0x263812??_0x15abd6;if(!_0x23ab48)throw createEarlyInfraError('Critical\x20error:\x20Project\x20ID\x20is\x20not\x20available.\x20Expected\x20'+toolboxEnvSettingKeys['fdGitlabProjectId']+'\x20or\x20'+environmentVariables['ciProjectId']+'\x20environment\x20variable.');process['env'][toolboxEnvSettingKeys['fdGitlabProjectId']]=_0x23ab48;const _0x2b0ea0=folders['git']+'/'+folders['commands']+'/'+files['autoMerge'],_0x4c35d4=''+packagesPath['packagesInternalCli']+_0x2b0ea0;execSyncCommand(npxCommands['npxTsx']+'\x20'+_0x4c35d4+'\x20'+_0x127576+'\x20'+_0x4efd5e);}__name(ciAutoMerge,'ciAutoMerge');function getNumberOfMrsToProcess(){const _0x2fbf78=getNumberEnvSetting(environmentVariables['ciAutomergeNumberOfMrs']);if(_0x2fbf78===void(0x1376*0x2+0x33b*0x7+0x3b*-0x10b)||_0x2fbf78<0xe4*0x26+-0x499*-0x3+0x2*-0x17d1)return defaultAutomergeNumberOfMrs;return _0x2fbf78;}__name(getNumberOfMrsToProcess,'getNumberOfMrsToProcess');

export { ciAutoMerge };
