conventionalcommit

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

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.

func ValidTypes

func ValidTypes() []string

ValidTypes returns the list of types that are valid.

Types

type BumpType

type BumpType int

BumpType represents the version bump type.

const (
	// BumpTypeNone is the bump type when no bump is done.
	BumpTypeNone BumpType = iota
	// BumpTypeMajor is the bump type for major version.
	BumpTypeMajor
	// BumpTypeMinor is the bump type for minor version.
	BumpTypeMinor
	// BumpTypePatch is the bump type for patch version.
	BumpTypePatch
)

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

func Parse(msg string) (Commit, error)

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

Jump to

Keyboard shortcuts

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