UNPKG

renovate

Version:

Automated dependency updates. Flexible so you don't need to be.

44 lines (43 loc) 2.1 kB
import { regEx } from "../regex.js"; import { logger } from "../../logger/index.js"; import { getCache } from "../cache/repository/index.js"; import { getCommitMessages } from "./index.js"; //#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 score = detectSemanticCommitScore(commitMessages); logger.debug(`semanticCommits: score=${score}`); if (score > 0) { logger.debug(`semanticCommits: enabled`); cache.semanticCommits = "enabled"; } else { logger.debug(`semanticCommits: disabled`); cache.semanticCommits = "disabled"; } return cache.semanticCommits; } /** * Detect semantic commits by counting the number of commit messages that match the Angular convention and comparing it to the number of commit messages that do not match the convention. * The Angular convention is defined as: `<type>(<scope>): <description>`, where `<type>` is a word, `<scope>` is an optional word, and `<description>` is a string. * * @see Inspired by {@link https://github.com/conventional-changelog/conventional-commits-detector|conventional-commits-detector} and {@link https://www.conventionalcommits.org|conventional commits specification}. * @param commitMessages commit messages to check * @returns A number greater than zero if more semantic commits than non-semantic commits, less than zero if more non-semantic commits than semantic commits, or zero if equal number of semantic and non-semantic commits */ function detectSemanticCommitScore(commitMessages) { const angular = regEx(/^(\w*)(?:\((.*)\))?!?: (.*)$/); return commitMessages.reduce((count, message) => { if (angular.test(message)) return count + 1; return count - 1; }, 0); } //#endregion export { detectSemanticCommits }; //# sourceMappingURL=semantic.js.map