parser

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2021 License: MIT Imports: 3 Imported by: 3

README

Parser

A go parser for Conventional Commits messages

PkgGoDev

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,
}
*/
Fork

This parser is a fork of cov-commit-parser by Matthew Bamber

TODO
  • Avoid regex
  • Benchmark
License

MIT License

Documentation

Overview

Package parser provides a simple parser for conventional commits

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsHeaderErr

func IsHeaderErr(err error) bool

IsHeaderErr checks if given error is header parse error

func IsNoBlankLineErr added in v0.4.0

func IsNoBlankLineErr(err error) bool

IsNoBlankLineErr checks if given error is no new line error

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

func (*Note) Value added in v0.6.0

func (n *Note) Value() string

type Parser added in v0.6.0

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

Parser represent a conventional commit message 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

func (*Parser) Parse added in v0.6.0

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

Parse attempts to parse a commit message to a conventional commit

Jump to

Keyboard shortcuts

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