Help us shape the future of Go! Take the 2026 Go Developer Survey

parser

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: MIT Imports: 5 Imported by: 3

README

Parser

A go parser for Conventional Commits messages

PkgGoDevGitHub go.mod Go version

Usage
var msg = `feat(scope): description

this is first line in body

this is second line in body

Ref #123
Date: 01-01-2021
By: John Doe`

commit, err := Parse(msg)
if err != nil {
    fmt.Printf("Error: %s", err.Error())
}
fmt.Printf("%#v", commit)

/*
commitMsg = &parser.Commit{
    message:     "feat(scope): description\n\nthis is first line in body\n\nthis is second line in body\n\nRef #123\nDate: 01-01-2021\nBy: John Doe",
    header:      "feat(scope): description",
    body:        "this is first line in body\n\nthis is second line in body",
    footer:      "Ref #123\nDate: 01-01-2021\nBy: John Doe",
    commitType:  "feat",
    scope:       "scope",
    description: "description",
    notes:       {
        {token:"Ref", value:"123"},
        {token:"Date", value:"01-01-2021"},
        {token:"By", value:"John Doe"},
    },
    isBreakingChange: false,
}
*/
TODO
  • More Test Cases
  • Benchmark
Attribution

This parser is inspired and forked from

License

MIT License

Documentation

Overview

Package parser provides a parser for conventional commits

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	// contains filtered or unexported fields
}

Commit represents a commit that adheres to the conventional commits specification

func (*Commit) Body

func (c *Commit) Body() string

Body returns body of the commit

func (*Commit) Description added in v0.6.0

func (c *Commit) Description() string

Description returns description of the commit

func (*Commit) Footer

func (c *Commit) Footer() string

Footer returns footer of the commit

func (*Commit) Header

func (c *Commit) Header() string

Header returns header of the commit

func (*Commit) IsBreakingChange added in v0.6.0

func (c *Commit) IsBreakingChange() bool

IsBreakingChange returns true if commit is breaking change

func (*Commit) Message added in v0.6.0

func (c *Commit) Message() string

Message returns input commit message

func (*Commit) Notes added in v0.6.0

func (c *Commit) Notes() []Note

Notes returns footer notes of the commit

func (*Commit) Scope added in v0.6.0

func (c *Commit) Scope() string

Scope returns scope of the commit

func (*Commit) Type added in v0.6.0

func (c *Commit) Type() string

Type returns type of the commit

type Note added in v0.6.0

type Note struct {
	// contains filtered or unexported fields
}

Note represents one footer note

func (*Note) Token added in v0.6.0

func (n *Note) Token() string

Token returns the token of the Footer Note

func (*Note) Value added in v0.6.0

func (n *Note) Value() string

Value returns the value of the Footer Note

type Parser added in v0.6.0

type Parser struct{}

Parser represent a conventional commits parser

Example
package main

import (
	"fmt"

	"github.com/conventionalcommit/parser"
)

func main() {
	var msg = `feat(scope): description

this is first line in body

this is second line in body

Ref #123
Date: 01-01-2021
By: John Doe`

	p := parser.New()
	commit, err := p.Parse(msg)
	if err != nil {
		fmt.Printf("Error: %s", err.Error())
	}
	fmt.Printf("%#v", commit)

}
Output:
&parser.Commit{message:"feat(scope): description\n\nthis is first line in body\n\nthis is second line in body\n\nRef #123\nDate: 01-01-2021\nBy: John Doe", header:"feat(scope): description", body:"this is first line in body\n\nthis is second line in body", footer:"Ref #123\nDate: 01-01-2021\nBy: John Doe", commitType:"feat", scope:"scope", description:"description", notes:[]parser.Note{parser.Note{token:"Ref", value:"123"}, parser.Note{token:"Date", value:"01-01-2021"}, parser.Note{token:"By", value:"John Doe"}}, isBreakingChange:false}

func New added in v0.6.0

func New() *Parser

New returns a new Parser instance

func (*Parser) Parse added in v0.6.0

func (p *Parser) Parse(input string) (*Commit, error)

Parse parses the conventional commit. If it fails, an error is returned.

Jump to

Keyboard shortcuts

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