import { logger } from "../../logger/index.js";
import { getCache } from "../cache/repository/index.js";
import { getCommitMessages } from "./index.js";
import conventionalCommitsDetector from "conventional-commits-detector";

//#region lib/util/git/semantic.ts
async function detectSemanticCommits() {
	logger.debug("detectSemanticCommits()");
	const cache = getCache();
	if (cache.semanticCommits) {
		logger.debug(`semanticCommits: returning "${cache.semanticCommits}" from cache`);
		return cache.semanticCommits;
	}
	const commitMessages = await getCommitMessages();
	logger.trace(`commitMessages=${JSON.stringify(commitMessages)}`);
	const type = conventionalCommitsDetector(commitMessages);
	logger.debug(`semanticCommits: detected "${type}"`);
	if (type === "angular") {
		logger.debug(`semanticCommits: enabled`);
		cache.semanticCommits = "enabled";
	} else {
		logger.debug(`semanticCommits: disabled`);
		cache.semanticCommits = "disabled";
	}
	return cache.semanticCommits;
}

//#endregion
export { detectSemanticCommits };
//# sourceMappingURL=semantic.js.map