commit

package
v0.0.0-...-c25e923 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package commit provides commit-related policies.

Index

Constants

View Source
const (
	// TypeFeat is a commit of the type fix patches a bug in your codebase
	// (this correlates with PATCH in semantic versioning).
	TypeFeat = "feat"

	// TypeFix is a commit of the type feat introduces a new feature to the
	// codebase (this correlates with MINOR in semantic versioning).
	TypeFix = "fix"
)

Variables

View Source
var DCORegex = regexp.MustCompile(`^Signed-off-by: ([^<]+) <([^<>@]+@[^<>]+)>$`)

DCORegex is the regular expression used for Developer Certificate of Origin.

View Source
var FirstWordRegex = regexp.MustCompile(`^\s*([a-zA-Z0-9]+)`)

FirstWordRegex is theregular expression used to find the first word in a commit.

View Source
var HeaderRegex = regexp.MustCompile(`^(\w*)(\(([^)]+)\))?(!)?:\s{1}(.*)($|\n{2})`)

HeaderRegex is the regular expression used for Conventional Commits 1.0.0.

View Source
var MaxNumberOfCommitCharacters = 89

MaxNumberOfCommitCharacters is the default maximium number of characters allowed in a commit header.

View Source
var RequiredBodyThreshold = 10

RequiredBodyThreshold is the default minimum number of line changes required to trigger the body check.

Functions

This section is empty.

Types

type Body

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

Body enforces a maximum number of charcters on the commit header.

func (Body) Errors

func (h Body) Errors() []error

Errors returns any violations of the check.

func (Body) Message

func (h Body) Message() string

Message returns to check message.

func (Body) Name

func (h Body) Name() string

Name returns the name of the check.

type BodyChecks

type BodyChecks struct {
	// Required enforces that the current commit has a body.
	Required bool `mapstructure:"required"`
}

BodyChecks is the configuration for checks on the body of a commit.

type Commit

type Commit struct {
	// SpellCheck enforces correct spelling.
	SpellCheck *SpellCheck `mapstructure:"spellcheck"`
	// Conventional is the user specified settings for conventional commits.
	Conventional *Conventional `mapstructure:"conventional"`
	// Header is the user specified settings for the header of each commit.
	Header *HeaderChecks `mapstructure:"header"`
	// Header is the user specified settings for the body of each commit.
	Body *BodyChecks `mapstructure:"body"`
	// DCO enables the Developer Certificate of Origin check.
	DCO bool `mapstructure:"dco"`
	// GPG is the user specified settings for the GPG signature check.
	GPG *GPG `mapstructure:"gpg"`
	// GPGSignatureGitHubOrganization enforces that GPG signature should come from
	// one of the members of the GitHub org.
	GPGSignatureGitHubOrganization string `mapstructure:"gpgSignatureGitHubOrg"`
	// MaximumOfOneCommit enforces that the current commit is only one commit
	// ahead of a specified ref.
	MaximumOfOneCommit bool `mapstructure:"maximumOfOneCommit"`
	// contains filtered or unexported fields
}

Commit implements the policy.Policy interface and enforces commit messages to conform the Conventional Commit standard.

func (*Commit) Compliance

func (c *Commit) Compliance(options *policy.Options) (*policy.Report, error)

Compliance implements the policy.Policy.Compliance function.

func (Commit) ValidateBody

func (c Commit) ValidateBody() policy.Check

ValidateBody checks the header length.

func (Commit) ValidateConventionalCommit

func (c Commit) ValidateConventionalCommit() policy.Check

ValidateConventionalCommit returns the commit type.

func (Commit) ValidateDCO

func (c Commit) ValidateDCO() policy.Check

ValidateDCO checks the commit message for a Developer Certificate of Origin.

func (Commit) ValidateGPGIdentity

func (c Commit) ValidateGPGIdentity(g *git.Git) policy.Check

ValidateGPGIdentity checks the commit GPG signature for a known identity.

func (Commit) ValidateGPGSign

func (c Commit) ValidateGPGSign(g *git.Git) policy.Check

ValidateGPGSign checks the commit message for a GPG signature.

func (Commit) ValidateHeaderCase

func (c Commit) ValidateHeaderCase() policy.Check

ValidateHeaderCase checks the header length.

func (Commit) ValidateHeaderLastCharacter

func (c Commit) ValidateHeaderLastCharacter() policy.Check

ValidateHeaderLastCharacter checks the last character of the header.

func (Commit) ValidateHeaderLength

func (c Commit) ValidateHeaderLength() policy.Check

ValidateHeaderLength checks the header length.

func (Commit) ValidateImperative

func (c Commit) ValidateImperative() policy.Check

ValidateImperative checks the commit message for a GPG signature.

func (Commit) ValidateJiraCheck

func (c Commit) ValidateJiraCheck() policy.Check

ValidateJiraCheck validates if a Jira issue is mentioned in the header.

func (Commit) ValidateNumberOfCommits

func (c Commit) ValidateNumberOfCommits(g *git.Git, ref string) policy.Check

ValidateNumberOfCommits checks the header length.

func (Commit) ValidateSpelling

func (c Commit) ValidateSpelling() policy.Check

ValidateSpelling checks the spelling.

type Conventional

type Conventional struct {
	Types             []string `mapstructure:"types"`
	Scopes            []string `mapstructure:"scopes"`
	DescriptionLength int      `mapstructure:"descriptionLength"`
}

Conventional implements the policy.Policy interface and enforces commit messages to conform the Conventional Commit standard.

type ConventionalCommitCheck

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

ConventionalCommitCheck ensures that the commit message is a valid conventional commit.

func (ConventionalCommitCheck) Errors

func (c ConventionalCommitCheck) Errors() []error

Errors returns any violations of the check.

func (ConventionalCommitCheck) Message

func (c ConventionalCommitCheck) Message() string

Message returns to check message.

func (ConventionalCommitCheck) Name

Name returns the name of the check.

type DCOCheck

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

DCOCheck ensures that the commit message contains a Developer Certificate of Origin.

func (DCOCheck) Errors

func (d DCOCheck) Errors() []error

Errors returns any violations of the check.

func (DCOCheck) Message

func (d DCOCheck) Message() string

Message returns to check message.

func (DCOCheck) Name

func (d DCOCheck) Name() string

Name returns the name of the check.

type GPG

type GPG struct {
	// Required enforces that the current commit has a signature.
	Required bool `mapstructure:"required"`
	// Identity configures identity of the signature.
	Identity *struct {
		// GitHubOrganization enforces that commit should be signed with the key
		// of one of the organization public members.
		GitHubOrganization string `mapstructure:"gitHubOrganization"`
	} `mapstructure:"identity"`
}

GPG is the configuration for checks GPG signature on the commit.

type GPGCheck

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

GPGCheck ensures that the commit is cryptographically signed using GPG.

func (GPGCheck) Errors

func (g GPGCheck) Errors() []error

Errors returns any violations of the check.

func (GPGCheck) Message

func (g GPGCheck) Message() string

Message returns to check message.

func (GPGCheck) Name

func (g GPGCheck) Name() string

Name returns the name of the check.

type GPGIdentityCheck

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

GPGIdentityCheck ensures that the commit is cryptographically signed using known identity.

func (GPGIdentityCheck) Errors

func (g GPGIdentityCheck) Errors() []error

Errors returns any violations of the check.

func (GPGIdentityCheck) Message

func (g GPGIdentityCheck) Message() string

Message returns to check message.

func (GPGIdentityCheck) Name

func (g GPGIdentityCheck) Name() string

Name returns the name of the check.

type HeaderCaseCheck

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

HeaderCaseCheck enforces the case of the first word in the header.

func (HeaderCaseCheck) Errors

func (h HeaderCaseCheck) Errors() []error

Errors returns any violations of the check.

func (HeaderCaseCheck) Message

func (h HeaderCaseCheck) Message() string

Message returns to check message.

func (HeaderCaseCheck) Name

func (h HeaderCaseCheck) Name() string

Name returns the name of the check.

type HeaderChecks

type HeaderChecks struct {
	// Length is the maximum length of the commit subject.
	Length int `mapstructure:"length"`
	// Imperative enforces the use of imperative verbs as the first word of a
	// commit message.
	Imperative bool `mapstructure:"imperative"`
	// HeaderCase is the case that the first word of the header must have ("upper" or "lower").
	Case string `mapstructure:"case"`
	// HeaderInvalidLastCharacters is a string containing all invalid last characters for the header.
	InvalidLastCharacters string `mapstructure:"invalidLastCharacters"`
	// Jira checks if the header containers a Jira project key.
	Jira *JiraChecks `mapstructure:"jira"`
}

HeaderChecks is the configuration for checks on the header of a commit.

type HeaderLastCharacterCheck

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

HeaderLastCharacterCheck enforces that the last character of the header isn't in some set.

func (HeaderLastCharacterCheck) Errors

func (h HeaderLastCharacterCheck) Errors() []error

Errors returns any violations of the check.

func (HeaderLastCharacterCheck) Message

func (h HeaderLastCharacterCheck) Message() string

Message returns to check message.

func (HeaderLastCharacterCheck) Name

Name returns the name of the check.

type HeaderLengthCheck

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

HeaderLengthCheck enforces a maximum number of charcters on the commit header.

func (HeaderLengthCheck) Errors

func (h HeaderLengthCheck) Errors() []error

Errors returns any violations of the check.

func (HeaderLengthCheck) Message

func (h HeaderLengthCheck) Message() string

Message returns to check message.

func (HeaderLengthCheck) Name

func (h HeaderLengthCheck) Name() string

Name returns the name of the check.

type ImperativeCheck

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

ImperativeCheck enforces that the first word of a commit message header is and imperative verb.

func (ImperativeCheck) Errors

func (i ImperativeCheck) Errors() []error

Errors returns any violations of the check.

func (ImperativeCheck) Message

func (i ImperativeCheck) Message() string

Message returns to check message.

func (ImperativeCheck) Name

func (i ImperativeCheck) Name() string

Name returns the name of the check.

type JiraCheck

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

JiraCheck enforces that a Jira issue is mentioned in the header.

func (*JiraCheck) Errors

func (j *JiraCheck) Errors() []error

Errors returns any violations of the check.

func (*JiraCheck) Message

func (j *JiraCheck) Message() string

Message returns to check message.

func (*JiraCheck) Name

func (j *JiraCheck) Name() string

Name returns the name of the check.

type JiraChecks

type JiraChecks struct {
	Keys []string `mapstructure:"keys"`
}

JiraChecks is the configuration for checks for Jira issues.

type NumberOfCommits

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

NumberOfCommits enforces a maximum number of charcters on the commit header.

func (NumberOfCommits) Errors

func (h NumberOfCommits) Errors() []error

Errors returns any violations of the check.

func (NumberOfCommits) Message

func (h NumberOfCommits) Message() string

Message returns to check message.

func (NumberOfCommits) Name

func (h NumberOfCommits) Name() string

Name returns the name of the check.

type SpellCheck

type SpellCheck struct {
	Locale string `mapstructure:"locale"`
}

SpellCheck represents to spell check policy.

type SpellingCheck

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

SpellingCheck enforces correct spelling.

func (SpellingCheck) Errors

func (h SpellingCheck) Errors() []error

Errors returns any violations of the check.

func (SpellingCheck) Message

func (h SpellingCheck) Message() string

Message returns to check message.

func (SpellingCheck) Name

func (h SpellingCheck) Name() string

Name returns the name of the check.

Jump to

Keyboard shortcuts

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