Documentation
¶
Overview ¶
Package conventionalcommit implements helpers around conventional commits.
Index ¶
Examples ¶
Constants ¶
View Source
const ( // CaptureGroupKeyType is the capture group used in regex to capture [Commit.Type]. CaptureGroupKeyType string = "committype" // CaptureGroupKeyScope is the capture group used in regex to capture [Commit.Scope]. CaptureGroupKeyScope string = "commitscope" // CaptureGroupKeyBreakingBang is the capture group used in regex to capture [Commit.BreakingBang]. CaptureGroupKeyBreakingBang string = "breakingbang" // CaptureGroupKeyMessage is the capture group used in regex to capture [Commit.Message]. CaptureGroupKeyMessage string = "commitmessage" )
Variables ¶
View Source
var ( // ErrMalformedCommit reports that a commit message is malformed. ErrMalformedCommit = errors.New("commit message is malformed") // ErrCommitRegexDoesNotCompile reports that conventional commit regex does not compile. ErrCommitRegexDoesNotCompile = errors.New("regex does not compile") )
View Source
var ConventionalCommitRegex = regexp.MustCompile(`^(?P<` + CaptureGroupKeyType + `>[a-zA-Z]+)(?:\((?P<` + CaptureGroupKeyScope + `>[[:alnum:]._-]+)\))?(?P<` + CaptureGroupKeyBreakingBang + `>!)?: (?P<` + CaptureGroupKeyMessage + `>[[:alnum:]][[:space:][:print:]]*)$`)
ConventionalCommitRegex represents the regexp to capture groups of a conventional commit.
Functions ¶
func MinorTypes ¶
func MinorTypes() []string
MinorTypes returns the list of types that trigger a minor version bump.
func NoBumpTypes ¶
func NoBumpTypes() []string
NoBumpTypes returns the list of types that do not trigger a version bump.
func PatchTypes ¶
func PatchTypes() []string
PatchTypes returns the list of types that trigger a patch version bump.
Types ¶
type Commit ¶
type Commit struct {
Type string // Type represents the commit's type
Scope string // Scope represents the commit's scope
BreakingBang bool // BreakingBang represents the commit's breaking bang (!)
Message string // BreakingBang represents the commit's message
}
Commit represents a conventional commit.
func Parse ¶
Parse returns a Commit based on commit message msg.
Example ¶
package main
import (
"fmt"
"log/slog"
"codeberg.org/kema/kmicro/pkg/conventionalcommit"
)
func main() {
c, err := conventionalcommit.Parse("feat(hello)!: world")
if err != nil {
slog.Error("parsing conventional commit", slog.String("error.message", err.Error()))
return
}
fmt.Printf("%s - %s - %t - %s\n", c.Type, c.Scope, c.BreakingBang, c.Message)
}
Output: feat - hello - true - world
Click to show internal directories.
Click to hide internal directories.