footer

package
v0.0.0-...-51f9457 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package footer implements parsing logic for git footer and its predecessor (legacy `<KEY>=<arbitrary value>` style).

The git footer parsing functionality is a slimmed downed version of git_footers.py in depot_tools. See: https://chromium.googlesource.com/chromium/tools/depot_tools/+/master/git_footers.py

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeKey

func NormalizeKey(footerKey string) string

NormalizeKey normalizes a git footer key string. It removes leading and trailing spaces and converts each segment (separated by `-`) to title case.

func ParseLegacyMetadata

func ParseLegacyMetadata(message string) strpair.Map

ParseLegacyMetadata extracts legacy style `<KEY>=<value>` metadata from the given message. Unlike git footer, this works across *all* lines instead of the last paragraph only. Returns a multimap as a key may map to multiple values. The metadata defined in a latter line takes precedence and shows up at the front of the value slice.

func ParseLine

func ParseLine(line string) (string, string)

ParseLine tries to extract a git footer from a commit message line. Returns a normalized key and value (with surrounding space trimmed) if the line represents a valid footer. Returns empty strings otherwise.

func ParseLines

func ParseLines(lines []string) strpair.Map

ParseLines extracts all footers from the given lines. Returns a multimap as a footer key may map to multiple values. The footer in a latter line takes precedence and shows up at the front of the value slice. Ideally, this function should be called with the `footerLines` part of the return values of `SplitLines`.

func ParseMessage

func ParseMessage(message string) strpair.Map

ParseMessage extracts all footers from the footer lines of given message. A shorthand for `SplitLines` + `ParseLines`.

func SplitLines

func SplitLines(message string) (nonFooterLines, footerLines []string)

SplitLines splits a commit message to non-footer and footer lines.

Footer lines are all lines in the last paragraph of the message if it:

  • contains at least one valid footer (it may contains lines that are not valid footers in the middle).
  • is not the only paragraph in the message.

One exception is that if the last paragraph starts with text then followed by valid footers, footer lines will only contain all lines after the first valid footer, all the lines above will be included in non-footer lines and a new line will be appended to separate them from footer lines.

The leading and trailing whitespaces (including new lines) of the given message will be trimmed before splitting.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL