version_bump/commit_parser
Parse a raw foundation Commit into a ConventionalCommit following the
Conventional Commits / Angular preset.
The parser is intentionally PURE: it derives everything it needs from the
commit’s subject (the header line) and body. It never touches git or the
network. Regular expressions follow the shapes used by
conventional-changelog-angular and @semantic-release/commit-analyzer.
Types
A raw git commit as read from git log.
pub type Commit {
Commit(
hash: String,
short_hash: String,
subject: String,
body: String,
author_name: String,
author_email: String,
committer_date: String,
)
}
Constructors
-
Commit( hash: String, short_hash: String, subject: String, body: String, author_name: String, author_email: String, committer_date: String, )
A note extracted from a commit body, e.g. a BREAKING CHANGE: footer.
pub type CommitNote {
CommitNote(title: String, text: String)
}
Constructors
-
CommitNote(title: String, text: String)
A commit parsed under a conventional-commits preset.
pub type ConventionalCommit {
ConventionalCommit(
commit: Commit,
type_: option.Option(String),
scope: option.Option(String),
subject: String,
breaking: Bool,
notes: List(CommitNote),
references: List(String),
merge: Bool,
revert: Bool,
)
}
Constructors
-
ConventionalCommit( commit: Commit, type_: option.Option(String), scope: option.Option(String), subject: String, breaking: Bool, notes: List(CommitNote), references: List(String), merge: Bool, revert: Bool, )
Values
pub fn parse(commit: Commit) -> ConventionalCommit
Parse a Commit into a ConventionalCommit.
The header (commit.subject) is matched against type(scope)!: subject.
When it doesn’t match, type_ and scope are None and the raw subject is
kept verbatim. Breaking changes are detected from a trailing ! in the
header and from BREAKING CHANGE: / BREAKING-CHANGE: footers in the body,
either of which produces a CommitNote. References such as #123 or
fixes #123 are collected, and merge / revert commits are flagged.