git

package
v0.0.0-...-614ca16 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BranchTypeMaster  = BranchType("master")
	BranchTypeDevelop = BranchType("develop")
	BranchTypeRelease = BranchType("release")
	BranchTypeFeature = BranchType("feature")
	BranchPartSlug    = BranchPart("Slug")
	BranchPartVersion = BranchPart("Version")
	BranchPartNumber  = BranchPart("Number")
	BranchPartName    = BranchPart("Name")
)
View Source
const (
	StateLookingForCommitNumber = iota
	StateLookingForAuthor
	StateLookingForDate
	StateLookingForTitle
	StateLookingForBody
)
View Source
const MalformedCommitFlag = "malformed"

Variables

View Source
var RegexGetCommitId = regexp.MustCompile(` .{40}`)
View Source
var RegexGetCommitType = regexp.MustCompile(`(` + allCommitTypeString + `)`)
View Source
var RegexGetDate = regexp.MustCompile(`Date: `)
View Source
var RegexGetIssue = regexp.MustCompile(`[0-9]+$`)
View Source
var RegexMatchAlternativeTitle = regexp.MustCompile(`^\* .*`)
View Source
var RegexMatchAuthor = regexp.MustCompile(`Author: ([^<]+)\s+<([^>]+)>`)
View Source
var RegexMatchCommitID = regexp.MustCompile(`commit .{40}`)

TODO: imporve Regex with $ and ^ to be robust

View Source
var RegexMatchDate = regexp.MustCompile(`Date: .*`)
View Source
var RegexMatchFormattedTitle = regexp.MustCompile(`(` + allCommitTypeString + `)(\([^)]+\))?:(.*)`)
View Source
var RegexMatchIssue = regexp.MustCompile(`\s+(resolves )?(@|#)?[0-9]+$|^[0-9]+$`)

Functions

func BuildOutput

func BuildOutput(changes GitChange, options GitChangeLogOptions) string

func BuildUnknownOutput

func BuildUnknownOutput(builder *strings.Builder, changes GitChange)

func CleanFrontAsterisk

func CleanFrontAsterisk(title string) string

func CloneRepo

func CloneRepo(ref issues.RepoRef, protocol string, dir string) error

func CommitHasBreakingChange

func CommitHasBreakingChange(body string) bool

func GetChangeLogOutputMessage

func GetChangeLogOutputMessage(bump semver.Bump, c GitChanges, options GitChangeLogOptions) string

func GetCurrentOrgAndRepo

func GetCurrentOrgAndRepo() issues.RepoRef

func GetCurrentRepoPath

func GetCurrentRepoPath() (string, error)
func GetIssueLink(dir string, issue string) string

func GetOrgAndRepoFromPath

func GetOrgAndRepoFromPath(path string) (string, string)

func GetRepoPath

func GetRepoPath(path string) (string, error)

func GetRepoRefFromPath

func GetRepoRefFromPath(path string) issues.RepoRef

func LongBodyFormatter

func LongBodyFormatter(body string) string

func NewGithubClient

func NewGithubClient(token string) *github.Client

GetGithubClient gets a github client. If token == "" the client will not be authenticated.

func Slug

func Slug(in string) string

func Split

func Split(r rune) bool

Helper function to split IssueRef

Types

type BranchName

type BranchName string

func (BranchName) GetBranchType

func (b BranchName) GetBranchType(spec BranchSpec) (BranchType, error)

func (BranchName) String

func (b BranchName) String() string

type BranchPart

type BranchPart string

type BranchParts

type BranchParts map[BranchPart]string

func (BranchParts) Map

func (b BranchParts) Map() map[string]string

type BranchSpec

type BranchSpec struct {
	Master  string `yaml:"master"`
	Develop string `yaml:"develop"`
	/*
		  Release is the template for feature branches.
		  The template parameter is:
		  {
			"Version":int,
			"Name":string,
		  }
	*/
	Release string `yaml:"release"`
	/*
		  Feature is the template for feature branches.
		  The template parameter is:
		  {
			"ID":int,
			"Slug":string,
		  }
	*/
	Feature     string `yaml:"feature"`
	IsDefaulted bool   `yaml:"-"`
}

func (BranchSpec) GetBranchTemplate

func (b BranchSpec) GetBranchTemplate(typ BranchType) string

func (BranchSpec) GetBranchType

func (b BranchSpec) GetBranchType(branch BranchName) (BranchType, error)

func (BranchSpec) GetIssueNumber

func (b BranchSpec) GetIssueNumber(branch BranchName) (string, error)

func (BranchSpec) GetReleaseNameAndVersion

func (b BranchSpec) GetReleaseNameAndVersion(branch BranchName) (name, version string, err error)

func (BranchSpec) IsDevelop

func (b BranchSpec) IsDevelop(branch BranchName) bool

func (BranchSpec) IsFeature

func (b BranchSpec) IsFeature(branch BranchName) bool

func (BranchSpec) IsMaster

func (b BranchSpec) IsMaster(branch BranchName) bool

func (BranchSpec) IsRelease

func (b BranchSpec) IsRelease(branch BranchName) bool

func (BranchSpec) MarshalYAML

func (f BranchSpec) MarshalYAML() (interface{}, error)

func (BranchSpec) RenderFeature

func (b BranchSpec) RenderFeature(name string, number interface{}) (string, error)

func (BranchSpec) RenderRelease

func (b BranchSpec) RenderRelease(parameters BranchParts) (string, error)

func (*BranchSpec) UnmarshalYAML

func (f *BranchSpec) UnmarshalYAML(unmarshal func(interface{}) error) error

func (BranchSpec) WithDefaults

func (b BranchSpec) WithDefaults() BranchSpec

func (BranchSpec) WithDefaultsFrom

func (b BranchSpec) WithDefaultsFrom(d BranchSpec) BranchSpec

type BranchType

type BranchType string

type Config

type Config struct {
	GithubToken string `yaml:"-"`
}

type Deployer

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

func NewDeployer

func NewDeployer(repoRef issues.RepoRef, client *github.Client, issueService issues.IssueService) (*Deployer, error)

func (Deployer) CreateDeploy

func (d Deployer) CreateDeploy(ref, environment string) (int64, error)

func (Deployer) GetMostRecentSuccessfulDeployment

func (d Deployer) GetMostRecentSuccessfulDeployment() (*github.Deployment, error)

func (Deployer) UpdateDeploy

func (d Deployer) UpdateDeploy(deployID int64, state string, message string) error

type GitAcceptPRCommand

type GitAcceptPRCommand struct {
	PRNumber      int
	RepoDirectory string
	// if true, will skip merging the base branch back into the pr branch before merging into the target.
	DoNotMergeBaseIntoBranch bool
	Client                   *github.Client
	IssueService             issues.IssueService
}

func (GitAcceptPRCommand) Execute

func (c GitAcceptPRCommand) Execute() error

type GitChange

type GitChange struct {
	Valid          bool
	Title          string
	Body           string
	Date           string
	Issue          *issues.IssueRef
	CommitID       string
	CommitType     string
	Committer      string
	IssueLink      string
	BreakingChange bool
}

func (GitChange) Format

func (g GitChange) Format(f fmt.State, c rune)

type GitChangeLog

type GitChangeLog struct {
	VersionBump   semver.Bump
	Changes       GitChanges
	OutputMessage string
}

type GitChangeLogOptions

type GitChangeLogOptions struct {
	Description bool
	UnknownType bool
}

type GitChangeStory

type GitChangeStory struct {
	StoryRef   issues.IssueRef
	StoryLink  string
	StoryTitle string
	StoryBody  string
	Changes    GitChanges
	Link       string
}

type GitChanges

type GitChanges []GitChange

func (GitChanges) FilterByBump

func (g GitChanges) FilterByBump(bumps ...semver.Bump) GitChanges

func (GitChanges) GetSeparatedChanges

func (g GitChanges) GetSeparatedChanges() map[semver.Bump]GitChanges

func (GitChanges) GetVersionBump

func (g GitChanges) GetVersionBump() semver.Bump

func (GitChanges) MapToStories

func (g GitChanges) MapToStories(svc issues.IssueService) ([]*GitChangeStory, error)

type GitPullRequestCommand

type GitPullRequestCommand struct {
	Reviewers     []string
	Title         string
	Body          string
	Base          string
	FromBranch    string
	LocalRepoPath string
	Client        *github.Client
}

func (GitPullRequestCommand) Execute

func (c GitPullRequestCommand) Execute() (issueNmb, prNumber int, err error)

type GitWrapper

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

func NewGitWrapper

func NewGitWrapper(pathHint string) (GitWrapper, error)

func (GitWrapper) AddAndCommit

func (g GitWrapper) AddAndCommit(message string, files ...string) error

func (GitWrapper) Branch

func (g GitWrapper) Branch() string

func (GitWrapper) Branches

func (g GitWrapper) Branches() []string

func (GitWrapper) ChangeLog

func (g GitWrapper) ChangeLog(notInBranch, inBranch string, svc issues.IssueService, options GitChangeLogOptions) (GitChangeLog, error)

func (GitWrapper) CheckOutBranch

func (g GitWrapper) CheckOutBranch(branch string) error

func (GitWrapper) CheckOutOrCreateBranch

func (g GitWrapper) CheckOutOrCreateBranch(branch string) error

func (GitWrapper) CreateBranch

func (g GitWrapper) CreateBranch(branch string) error

func (GitWrapper) Dir

func (g GitWrapper) Dir() string

func (GitWrapper) Exec

func (g GitWrapper) Exec(args ...string) (string, error)

func (GitWrapper) ExecLines

func (g GitWrapper) ExecLines(args ...string) ([]string, error)

func (GitWrapper) ExecVerbose

func (g GitWrapper) ExecVerbose(args ...string) (string, error)

func (GitWrapper) Fetch

func (g GitWrapper) Fetch(flags ...string) error

func (GitWrapper) GetCurrentCommit

func (g GitWrapper) GetCurrentCommit() string

func (GitWrapper) IsDirty

func (g GitWrapper) IsDirty() bool

func (GitWrapper) IsMerged

func (g GitWrapper) IsMerged(fromBranch, toBranch string) bool

func (GitWrapper) Log

func (g GitWrapper) Log(args ...string) ([]string, error)

func (GitWrapper) Pull

func (g GitWrapper) Pull() error

func (GitWrapper) PullRebase

func (g GitWrapper) PullRebase() error

func (GitWrapper) Push

func (g GitWrapper) Push() error

func (GitWrapper) Tag

func (g GitWrapper) Tag() string

func (GitWrapper) Worktree

func (g GitWrapper) Worktree(branch BranchName) (Worktree, error)

type IssueRef

type IssueRef issues.IssueRef

type Issue issues.Issue

type IssueService

type IssueService struct {
	Config
	// contains filtered or unexported fields
}

func NewIssueService

func NewIssueService(config Config, log *logrus.Entry) (IssueService, error)

func (IssueService) AddDependency

func (s IssueService) AddDependency(from, to issues.IssueRef, parentIssueNum string) error

func (IssueService) ChangeLabels

func (s IssueService) ChangeLabels(ref issues.IssueRef, add []string, remove []string) error

func (IssueService) Create

func (s IssueService) Create(issue issues.Issue) (string, error)

func (IssueService) GetChildRefs

func (s IssueService) GetChildRefs(issue issues.IssueRef) ([]issues.IssueRef, error)

func (IssueService) GetClosedIssue

func (s IssueService) GetClosedIssue(org, repoName string) ([]int, error)

func (IssueService) GetIssue

func (s IssueService) GetIssue(ref issues.IssueRef) (issues.Issue, error)

func (IssueService) GetIssueState

func (s IssueService) GetIssueState(issue issues.IssueRef) (string, error)

func (IssueService) GetParentRefs

func (s IssueService) GetParentRefs(issue issues.IssueRef) ([]issues.IssueRef, error)

func (IssueService) GetRepoIdbyName

func (s IssueService) GetRepoIdbyName(org, repoName string) (int, error)

func (IssueService) RemoveDependency

func (s IssueService) RemoveDependency(from, to issues.IssueRef) error

func (IssueService) SetProgress

func (s IssueService) SetProgress(issue issues.IssueRef, column string) error

func (IssueService) SplitIssueRef

func (s IssueService) SplitIssueRef(issue issues.IssueRef) (string, string, int, error)

type Worktree

type Worktree struct {
	GitWrapper
	WorktreeConfig
	// contains filtered or unexported fields
}

func NewWorktree

func NewWorktree(g GitWrapper, branch BranchName) (Worktree, error)

func (Worktree) Dispose

func (w Worktree) Dispose()

func (Worktree) ResolvePath

func (w Worktree) ResolvePath(path string) string

type WorktreeConfig

type WorktreeConfig struct {
	WorktreeDir    string
	WorktreeBranch string
	OriginalDir    string
	OriginalBranch string
}

Jump to

Keyboard shortcuts

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