Presubmit.Message (presubmit v0.2.2)

Copy Markdown View Source

A parsed commit message: subject, body, and trailers.

Trailers are Key: value lines in the final paragraph of the message, following git's own interpret-trailers conventions closely enough for Co-Authored-By, Signed-off-by, BREAKING CHANGE, and custom keys.

Summary

Functions

What git rebase --autosquash does with a commit, read from its subject: :fixup, :squash, or :amend for a subject that starts fixup!, squash! or amend! (the subjects git commit --fixup and --squash write), and nil for any other.

The body's lines, each with its 1-based line number in the message (the subject's first line is line 1).

Applies git's default message cleanup to text from a commit-msg hook or editor: comment lines are dropped, everything from a scissors line on is dropped, and surrounding whitespace is trimmed.

Parses a raw commit message.

Every value for the trailer key, compared case-insensitively.

Types

t()

@type t() :: %Presubmit.Message{
  body: String.t(),
  raw: String.t(),
  subject: String.t(),
  trailers: [trailer()]
}

trailer()

@type trailer() :: {String.t(), String.t()}

Functions

autosquash(message)

@spec autosquash(t()) :: :fixup | :squash | :amend | nil

What git rebase --autosquash does with a commit, read from its subject: :fixup, :squash, or :amend for a subject that starts fixup!, squash! or amend! (the subjects git commit --fixup and --squash write), and nil for any other.

The prefixes are git's own, trailing space included: git does not fold a fixup!x commit into anything, so neither is it an autosquash commit here.

body_lines(message)

@spec body_lines(t()) :: [{pos_integer(), String.t()}]

The body's lines, each with its 1-based line number in the message (the subject's first line is line 1).

The lines are the ones parse/1 puts in :body: the subject paragraph and the trailer block are left out, and so are the blank lines between paragraphs. Line numbers count the raw message as written, so a report can point at the line an editor shows.

clean(text)

@spec clean(String.t()) :: String.t()

Applies git's default message cleanup to text from a commit-msg hook or editor: comment lines are dropped, everything from a scissors line on is dropped, and surrounding whitespace is trimmed.

parse(raw)

@spec parse(String.t()) :: t()

Parses a raw commit message.

The subject is the first paragraph joined onto one line (git folds multi-line subjects the same way); the body is everything between the subject and the trailer block.

trailer_values(message, key)

@spec trailer_values(t(), String.t()) :: [String.t()]

Every value for the trailer key, compared case-insensitively.