Skip to content

analyzeCommits

Analyses a list of commits to suggest a semantic version bump.

Each commit is parsed via parseConventionalCommit. The body is also scanned for BREAKING CHANGE: / BREAKING-CHANGE: markers. The bump rule is:

  • any breaking change → 'major'
  • otherwise any feat → 'minor'
  • otherwise any fix → 'patch'
  • otherwise (non-empty list of non-conventional commits) → 'patch'
  • empty list → 'patch' with reason “No commits to analyse”

Available since v2.0.0

import { analyzeCommits } from '@helpers4/commit';
// or, from the all-in-one package (same code, one install):
import { analyzeCommits } from 'helpers4/commit';
analyzeCommits(commits: readonly AnalyzableCommit[]): CommitAnalysis
ParameterTypeDescription
commitsreadonly AnalyzableCommit[]Iterable of commits to analyse. Only `subject` is required.

CommitAnalysis — Aggregated analysis with the suggested bump and reason.

Suggest a semver bump from a list of commits

Section titled “Suggest a semver bump from a list of commits”

Walks through commits and suggests major, minor, or patch based on Conventional Commits.

analyzeCommits([
  { subject: 'feat: add login' },
  { subject: 'fix: handle null' },
])
// => { suggestedBump: 'minor', hasFeatures: true, hasFixes: true, ... }

A ! marker or a BREAKING CHANGE: footer always promotes the suggestion to major.

analyzeCommits([{ subject: 'feat!: drop v1 API' }]).suggestedBump
// => 'major'

Minimal commit shape consumed by analyzeCommits. Only the subject line is mandatory; the body is scanned for a BREAKING CHANGE footer.

interface AnalyzableCommit {
  body?: string;
  subject: string;
}

Aggregated result of analyzeCommits.

interface CommitAnalysis {
  hasBreakingChanges: boolean;
  hasFeatures: boolean;
  hasFixes: boolean;
  reason: string;
  suggestedBump: CommitVersionBump;
}

Bumping suggestion produced by analyzeCommits.

type CommitVersionBump = 'major' | 'minor' | 'patch'

View source on GitHub