parser

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 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{
  Header: parser.Header{
    Type: "feat",
    Scope: "scope",
    Description: "description",
    FullHeader: "feat(scope): description",
  },
  Body: "this is first line in body\n\nthis is second line in body",
  Footer: parser.Footer{
    Notes: []parser.FooterNote{
      parser.FooterNote{
        Token: "Ref",
        Value: "123",
      },
      parser.FooterNote{
        Token: "Date",
        Value: "01-01-2021",
      },
      parser.FooterNote{
        Token: "By",
        Value: "John Doe",
      },
    },
    FullFooter: "Ref #123\nDate: 01-01-2021\nBy: John Doe",
  },
  BreakingChange: false,
  FullCommit: "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",
}
*/
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 {
	Header Header
	Body   string
	Footer Footer

	BreakingChange bool

	FullCommit string
}

Commit represents a commit that adheres to the conventional commits specification

func Parse

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

Parse attempts to parse a commit message to a conventional commit

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`

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

}
Output:

&parser.Commit{Header:parser.Header{Type:"feat", Scope:"scope", Description:"description", FullHeader:"feat(scope): description"}, Body:"this is first line in body\n\nthis is second line in body", Footer:parser.Footer{Notes:[]parser.FooterNote{parser.FooterNote{Token:"Ref", Value:"123"}, parser.FooterNote{Token:"Date", Value:"01-01-2021"}, parser.FooterNote{Token:"By", Value:"John Doe"}}, FullFooter:"Ref #123\nDate: 01-01-2021\nBy: John Doe"}, BreakingChange:false, FullCommit:"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"}
type Footer struct {
	Notes []FooterNote

	FullFooter string
}

Footer represents Footer in commit message

type FooterNote

type FooterNote struct {
	Token string
	Value string
}

FooterNote represents one footer note in Footer

type Header struct {
	Type        string
	Scope       string
	Description string

	FullHeader string
}

Header represents Header in commit message

Jump to

Keyboard shortcuts

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