utils

package
v0.0.0-...-859117f Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttrStr

func AttrStr(label string, value string) string

func BaseOptsStr

func BaseOptsStr(baseOpts BaseOptions) string

func CalcDiffPercStr

func CalcDiffPercStr(curValue int, prevValue int) string

func CalcDiffStr

func CalcDiffStr(curValue int, prevValue int) string

func CalcPercStr

func CalcPercStr(value int, total int) string

func CommitInfoToCommitIds

func CommitInfoToCommitIds(cinfos []CommitInfo) []string

func DiffContents

func DiffContents(src string, dst string) []diffmatchpatch.Diff

FIXME remove later if not used

func ExecCheckPrereqs

func ExecCheckPrereqs() error

func ExecCommitIdInDateRange

func ExecCommitIdInDateRange(repoDir string, branch string, sinceDate string, untilDate string) ([]string, error)

func ExecDiffIsBinary

func ExecDiffIsBinary(repoDir string, commitId string, filePath string) (bool, error)

func ExecDiffTree

func ExecDiffTree(repoDir string, commitId1 string) ([]string, error)

func ExecListTree

func ExecListTree(repoDir string, commitId string) ([]string, error)

func ExecPreviousCommitIdForFile

func ExecPreviousCommitIdForFile(repoDir string, commitId string, filePath string) (string, error)

func ExecShell

func ExecShell(workingDir string, command string) (string, error)

ExecShell execute a shell command (like bash -c 'your command')

func ExecShellTimeout

func ExecShellTimeout(workingDir string, command string, timeout time.Duration, expectedExitCodes []int) (string, error)

ExecShellTimeout execute a shell command (like bash -c 'your command') with a timeout. After that time, the process will be cancelled

func ExecShellf

func ExecShellf(workingDir string, command string, args ...interface{}) (string, error)

ExecShellf execute a shell command (like bash -c 'your command') but with format replacements

func ExecTreeFileSize

func ExecTreeFileSize(repoDir string, commitId string, filePath string) (int, error)

func GetCmdOutput

func GetCmdOutput(cmd *cmd.Cmd) string

GetCmdOutput join stdout and stderr in a single string from Cmd

func JoinWithLimit

func JoinWithLimit(values []string, separator string, limit int) string

func ResolveTestOwnershipDuplicatesRepo

func ResolveTestOwnershipDuplicatesRepo() (string, error)

func ResolveTestOwnershipRepo

func ResolveTestOwnershipRepo() (string, error)

func ShowProgress

func ShowProgress(progressChan <-chan ProgressInfo)

Types

type BaseOptions

type BaseOptions struct {
	Branch          string `json:"branch"`
	FilesRegex      string `json:"files_regex"`
	FilesNotRegex   string `json:"files_not_regex"`
	AuthorsRegex    string `json:"authors_regex"`
	AuthorsNotRegex string `json:"authors_not_regex"`
	RepoDir         string `json:"repo_dir"`
	CacheFile       string `json:"cache_file"`
	CacheTTLSeconds int    `json:"cache_ttl_seconds"`
}

type BlameLine

type BlameLine struct {
	// AuthorName is the name of the last author that modified the line
	AuthorName string
	// AuthorMail is the mail of the last author that modified the line
	AuthorMail string
	// Date is when the original text of the line was introduced
	AuthorDate time.Time
	// Hash is the commit hash that introduced the original line
	CommitId     string
	LineContents string
}

func ExecGitBlame

func ExecGitBlame(repoPath string, filePath string, revision string) ([]BlameLine, error)

type CacheDB

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

func NewCacheDB

func NewCacheDB(dbFile string, tableName string, ttlSeconds int) (*CacheDB, error)

func (*CacheDB) Close

func (c *CacheDB) Close()

func (*CacheDB) GetValue

func (c *CacheDB) GetValue(cacheKey string) (*string, error)

func (*CacheDB) PutValue

func (c *CacheDB) PutValue(cacheKey string, cacheContents string) error

type CommitInfo

type CommitInfo struct {
	AuthorName string    `json:"author_name"`
	AuthorMail string    `json:"author_mail"`
	Date       time.Time `json:"date"`
	CommitId   string    `json:"commit_id"`
}

func ExecGetCommitsInCommitRange

func ExecGetCommitsInCommitRange(repoDir string, branch string, sinceCommit string, untilCommit string) ([]CommitInfo, error)

func ExecGetCommitsInDateRange

func ExecGetCommitsInDateRange(repoDir string, branch string, since string, until string) ([]CommitInfo, error)

func ExecGetLastestCommit

func ExecGetLastestCommit(repoDir string, branch string, sinceDate string, untilDate string) (*CommitInfo, error)

func ExecGitCommitInfo

func ExecGitCommitInfo(repoDir string, commitId string) (CommitInfo, error)

type DiffEntry

type DiffEntry struct {
	Operation DiffOp
	SrcLines  []LineText
	DstLines  []LineText
}

func ExecDiffFileRevisions

func ExecDiffFileRevisions(repoDir string, filePath string, srcCommitId string, dstCommitId string) ([]DiffEntry, error)

func ExecDiffFiles

func ExecDiffFiles(fileSrc string, fileDst string) ([]DiffEntry, error)

func ParseNormalDiffOutput

func ParseNormalDiffOutput(contents string) ([]DiffEntry, error)

type DiffOp

type DiffOp int
const (
	OperationAdd DiffOp = iota
	OperationDelete
	OperationChange
)

type DuplicateLineTracker

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

Attention: this utility will handle a lot of memory and a lot of calls Be careful about anything you are going to store and always think about optimization

func NewDuplicateLineTracker

func NewDuplicateLineTracker() *DuplicateLineTracker

func (*DuplicateLineTracker) AddLine

func (d *DuplicateLineTracker) AddLine(contents string, source LineSource) ([]LineSource, bool)

Add a new line to tracker. If line is too short, it's is ignored and nil is returned This is thread safe, but can slow down parallelism in current implementation If string has string "\\n" (not \n), it will be split into distinct lines during ignore analysis

func (*DuplicateLineTracker) GroupDuplicatedLines

func (d *DuplicateLineTracker) GroupDuplicatedLines() []LineGroup

type LineGroup

type LineGroup struct {
	Lines
	RelatedLinesGroup []LineGroup
	RelatedLinesCount int
	// contains filtered or unexported fields
}

type LineSource

type LineSource struct {
	Lines
	AuthorName string
	AuthorMail string
	CommitDate time.Time
	// contains filtered or unexported fields
}

type LineText

type LineText struct {
	Number int
	Text   string
}

type Lines

type Lines struct {
	FilePath   string
	LineNumber int
	LineCount  int
}

type ProgressInfo

type ProgressInfo struct {
	TotalTasks         int
	TotalTasksKnown    bool
	CompletedTasks     int
	CompletedTotalTime time.Duration
	Message            string
}

Jump to

Keyboard shortcuts

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