GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Why Go
  • Case Studies
  • Use Cases
  • Security
  • Learn
  • Effective Go
  • Go User Manual
  • Standard library
  • Release Notes
  • API
  • Packages
  • Recorded Talks
  • Meetups
  • Conferences

This view

  • Original page
  • New address

GeezerVison is showing pkg.go.dev — parser package - github.com/conventionalcommit/parser - Go Packages

Details

  • checked Valid go.mod file

    The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.

  • checked Redistributable license

    Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.

  • checked Tagged version

    Modules with tagged versions give importers more predictable builds.

  • unchecked Stable version

    When a project reaches major version v1 it is considered stable.

  • Learn more about best practices

Repository

github.com/conventionalcommit/parser

Links

  • Open Source Insights Logo Open Source Insights

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

  • cc by Rene Zbinden
  • go-lexer by Brandon Buck
  • cov-commit-parser by Matthew Bamber
License

MIT License

Documentation ¶

Overview ¶

Package parser provides a parser for conventional commits

Index ¶

  • type Commit
    • func (c *Commit) Body() string
    • func (c *Commit) Description() string
    • func (c *Commit) Footer() string
    • func (c *Commit) Header() string
    • func (c *Commit) IsBreakingChange() bool
    • func (c *Commit) Message() string
    • func (c *Commit) Notes() []Note
    • func (c *Commit) Scope() string
    • func (c *Commit) Type() string
  • type Note
    • func (n *Note) Token() string
    • func (n *Note) Value() string
  • type Parser
    • func New() *Parser
    • func (p *Parser) Parse(input string) (*Commit, error)

Examples ¶

  • Parser

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.

Source Files ¶

View all Source files
  • commit.go
  • lexer.go
  • lexer_state.go
  • parser.go
Click to show internal directories.
Click to hide internal directories.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.