convention

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultSemverVersion              = "1.0.0"
	DefaultHeader                     = "Changelog"
	DefaultCommitUrlFormat            = "{{scheme}}://{{host}}/{{owner}}/{{repository}}/commit/{{hash}}"
	DefaultCompareUrlFormat           = "{{scheme}}://{{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}}"
	DefaultIssueUrlFormat             = "{{scheme}}://{{host}}/{{owner}}/{{repository}}/issues/{{id}}"
	DefaultUserUrlFormat              = "{{scheme}://{{host}}/{{user}}"
	DefaultReleaseCommitMessageFormat = "chore(release): {{currentTag}}"
)
View Source
const (
	FeatType     = "feat"
	FixType      = "fix"
	DocsType     = "docs"
	StyleType    = "style"
	RefactorType = "refactor"
	PerfType     = "perf"
	TestType     = "test"
	BuildType    = "build"
	CIType       = "ci"
	ChoreType    = "chore"
	RevertType   = "revert"
	MiscType     = "misc"
)
View Source
const (
	MarkdownBreakingChangesToken = "BREAKING CHANGE: "
)

Variables

View Source
var (
	ErrEmptyCommit = errors.New("empty commit")
)

Functions

func ParseSectionFromType

func ParseSectionFromType(logSpec ConventionalChangeLogSpec, commitType string) string

ParseSectionFromType

parse section from type
if not found, return type itself

func RaymondParseAst

func RaymondParseAst(input string) (*ast.Program, error)

RaymondParseAst parse by input

func RaymondRender

func RaymondRender(template string, payload interface{}) (s string, err error)

RaymondRender parses and executes a template, returning the results in string format. Trailing or leading spaces or new-lines are not getting truncated. It is able to read templates from remote paths, local files or directly from the string.

Types

type BreakingChanges

type BreakingChanges struct {
	Describe string
}

type Commit

type Commit struct {
	// Commit as is
	RawHeader string

	Type  string
	Scope string

	BreakingChanges BreakingChanges

	IssueInfo IssueInfo
}

Commit conventional commit

func ConvertGitCommits2ConventionCommits

func ConvertGitCommits2ConventionCommits(commits []git.Commit, spec ConventionalChangeLogSpec, gitHttpInfo GitRepositoryHttpInfo) ([]Commit, error)

func NewCommit

func NewCommit(c git.Commit) (Commit, error)

NewCommit return conventional commit from git commit

func NewCommitWithLogSpec

func NewCommitWithLogSpec(c git.Commit, spec ConventionalChangeLogSpec, gitHttpInfo GitRepositoryHttpInfo) (Commit, error)

NewCommitWithLogSpec

c git.Commit

spec ConventionalChangeLogSpec

gitHttpInfo git info by GitRepositoryHttpInfo

this method not add AddAuthorDate

return conventional commit from git commit

func NewCommitWithOptions

func NewCommitWithOptions(opts ...OptionFn) (result Commit, err error)

NewCommitWithOptions return conventional commit with custom option

func (c *Commit) AppendMarkdownCommitLink(commitUrlFormat string, shortHash, hash string, gitHttpInfo GitRepositoryHttpInfo) error

AppendMarkdownCommitLink will append [shortHash](RaymondRender(commitUrlFormat)) by {{scheme}}://{{Host}}/{{Owner}}/{{Repository}}/commit/{{Hash}}

func (*Commit) String

func (c *Commit) String() string

type CommitRenderTemplate

type CommitRenderTemplate struct {
	GitUrlRenderTemplate
	Hash string `handlebars:"hash"`
}

CommitRenderTemplate default template is DefaultCommitUrlFormat

type CompareRenderTemplate

type CompareRenderTemplate struct {
	GitUrlRenderTemplate
	PreviousTag string `handlebars:"previousTag"`
	CurrentTag  string `handlebars:"currentTag"`
}

CompareRenderTemplate default template is DefaultCompareUrlFormat

type ConventionalChangeLogSpec

type ConventionalChangeLogSpec struct {

	// Types
	//
	Types []Types `json:"types,omitempty"`

	// TagPrefix
	//	default is v
	TagPrefix string `json:"tag-prefix,omitempty"`

	// HashLength
	//	default is 8
	HashLength uint `json:"hash-length,omitempty"`

	// IssuePrefixes
	// default is ["#"]
	IssuePrefixes []string `json:"issuePrefixes,omitempty"`

	// Header
	//	A string to be used as the main header of the CHANGELOG
	// default DefaultHeader
	Header string `json:"header,omitempty"`

	// CommitUrlFormat
	//	A URL representing a specific commit at a Hash
	// default DefaultCommitUrlFormat
	CommitUrlFormat string `json:"commitUrlFormat,omitempty"`

	// CompareUrlFormat
	//	A URL representing the comparison between two git shas
	// default DefaultCompareUrlFormat
	CompareUrlFormat string `json:"compareUrlFormat,omitempty"`

	// IssueUrlFormat
	//	A URL representing the issue format (allowing a different URL format to be swapped in for Gitlab, Bitbucket, etc)
	// default DefaultIssueUrlFormat
	IssueUrlFormat string `json:"issueUrlFormat,omitempty"`

	// UserUrlFormat
	//	A URL representing a user's profile URL on GitHub, Gitlab, etc. This URL is used for substituting @bcoe with https://github.com/bcoe in commit messages.
	// default DefaultUserUrlFormat
	UserUrlFormat string `json:"userUrlFormat,omitempty"`

	// ReleaseCommitMessageFormat
	//	A string to be used to format the auto-generated release commit message
	// default DefaultReleaseCommitMessageFormat
	ReleaseCommitMessageFormat string `json:"releaseCommitMessageFormat,omitempty"`

	// CoverHttpHost
	// this will cover all http host
	CoverHttpHost string `json:"cover-http-host,omitempty"`

	// CoverGitInfoScheme
	// this will cover git url info scheme, like https / http
	CoverGitInfoScheme string `json:"cover-git-info-scheme,omitempty"`

	// MonoRepoPkgPathList
	// monorepo package path list
	MonoRepoPkgPathList []string `json:"monorepo-pkg-path,omitempty"`
}

ConventionalChangeLogSpec struct scheme See: https://github.com/conventional-changelog/conventional-changelog-config-spec/blob/master/versions/2.2.0/schema.json

func DefaultConventionalChangeLogSpec

func DefaultConventionalChangeLogSpec() ConventionalChangeLogSpec

DefaultConventionalChangeLogSpec

See: https://www.conventionalcommits.org

func LoadConventionalChangeLogSpecByData

func LoadConventionalChangeLogSpecByData(logSpec []byte) (*ConventionalChangeLogSpec, error)

LoadConventionalChangeLogSpecByData

this function will load ConventionalChangeLogSpec from json data
if type sort is 0, will set default sort by convention.defaultType

scheme See: https://github.com/conventional-changelog/conventional-changelog-config-spec/blob/master/versions/2.2.0/schema.json

func LoadConventionalChangeLogSpecByPath added in v1.2.0

func LoadConventionalChangeLogSpecByPath(specFilePath string) (*ConventionalChangeLogSpec, error)

LoadConventionalChangeLogSpecByPath

load ConventionalChangeLogSpec by path

if path not exists, will return default spec

func SimplifyConventionalChangeLogSpec

func SimplifyConventionalChangeLogSpec() *ConventionalChangeLogSpec

SimplifyConventionalChangeLogSpec return simplify ConventionalChangeLogSpec

type GitRepositoryHttpInfo

type GitRepositoryHttpInfo struct {
	// Scheme is the protocol scheme of the remote host. https or http.
	// do not use git+ssh, it will be some error
	Scheme string

	// Host is the hostname:port of the remote host.
	Host string

	// Owner is the owner of the repository.
	Owner string

	// Repository is the name of the repository.
	Repository string
}

type GitUrlRenderTemplate

type GitUrlRenderTemplate struct {
	Scheme     string `handlebars:"scheme"`
	Host       string `handlebars:"host"`
	Owner      string `handlebars:"owner"`
	Repository string `handlebars:"repository"`
}

GitUrlRenderTemplate default template is DefaultUserUrlFormat

type IssueInfo

type IssueInfo struct {
	IssueReference    string
	IssuePrefix       string
	IssueReferencesId uint64
}

type IssueRenderTemplate

type IssueRenderTemplate struct {
	GitUrlRenderTemplate
	Id string `handlebars:"id"`
}

IssueRenderTemplate default template is DefaultIssueUrlFormat

type OptionFn

type OptionFn func(*Commit) error

func AddAuthorDate

func AddAuthorDate(gitCommit git.Commit) OptionFn

func GetBreakChangesAndIssue

func GetBreakChangesAndIssue(gitCommit git.Commit, spec ConventionalChangeLogSpec) OptionFn

func GetRawHeader

func GetRawHeader(gitCommit git.Commit) OptionFn

func GetTypeAndScope

func GetTypeAndScope(gitCommit git.Commit) OptionFn

type ReleaseCommitMessageRenderTemplate

type ReleaseCommitMessageRenderTemplate struct {
	CurrentTag string `handlebars:"currentTag"`
}

ReleaseCommitMessageRenderTemplate default template is DefaultReleaseCommitMessageFormat

type Types

type Types struct {

	// Type
	//
	Type string `json:"type"`

	// Section
	//
	Section string `json:"section,omitempty"`

	// Hidden
	//
	Hidden bool `json:"hidden"`

	// Sort
	Sort uint `json:"sort,omitempty"`
}

Types

struct of type

See: https://github.com/conventional-changelog/conventional-changelog-config-spec/blob/master/versions/2.2.0/schema.json

add Sort field

Jump to

Keyboard shortcuts

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