import { GlobalConfig } from "../../../../config/global.js";
import { logger } from "../../../../logger/index.js";
import { compile } from "../../../../util/template/index.js";
import { scm } from "../../../../modules/platform/scm.js";
import { getOnboardingConfigContents } from "./config.js";
import { getDefaultConfigFileName } from "../common.js";
import { OnboardingCommitMessageFactory } from "./commit-message.js";

//#region lib/workers/repository/onboarding/branch/create.ts
async function createOnboardingBranch(config) {
	logger.debug("createOnboardingBranch()");
	const configFile = getDefaultConfigFileName(config);
	const contents = await getOnboardingConfigContents(config, configFile);
	logger.debug("Creating onboarding branch");
	let commitMessage = new OnboardingCommitMessageFactory(config, configFile).create().toString();
	if (config.commitBody) {
		commitMessage = `${commitMessage}\n\n${compile(config.commitBody, { gitAuthor: config.gitAuthor })}`;
		logger.trace(`commitMessage: ${commitMessage}`);
	}
	// istanbul ignore if
	if (GlobalConfig.get("dryRun")) {
		logger.info("DRY-RUN: Would commit files to onboarding branch");
		return null;
	}
	return scm.commitAndPush({
		baseBranch: config.baseBranch,
		branchName: config.onboardingBranch,
		files: [{
			type: "addition",
			path: configFile,
			contents
		}],
		message: commitMessage,
		platformCommit: config.platformCommit,
		force: true,
		labels: config.labels
	});
}

//#endregion
export { createOnboardingBranch };
//# sourceMappingURL=create.js.map