+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions grit/cmd/flag/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ var (
AvailableOutputFormats = []OutputType{JSON, Tabular}

// Coverage Run formats.
Always = "always"
Never = "never"
Auto = "auto"
Always = "Always"
Never = "Never"
Auto = "Auto"

OutputFormat OutputType
)
Expand Down
11 changes: 6 additions & 5 deletions grit/cmd/plot/subcommands/churncomplexity.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
outputFile string
since string
until string
churnType git.ChurnType
)

var churnOpts = &git.ChurnOptions{
Expand Down Expand Up @@ -74,7 +75,7 @@ Open generated file '.html' in a browser to view the graph.`,

flag.LogIfVerbose("Got %d complexity files\n", len(complexityStats))

plotEntries := plot.PreparePlotData(complexityStats, churns)
plotEntries := plot.PreparePlotData(complexityStats, churns, churnType)

if err := plot.CreateScatterChart(plotEntries, plot.NewNoopMapper(), outputFile); err != nil {
return fmt.Errorf("error creating chart: %w", err)
Expand All @@ -93,12 +94,12 @@ func init() {
flags.BoolVarP(&flag.Verbose, flag.LongVerbose, flag.ShortVerbose, false, "Show detailed progress")
flags.StringVarP(&outputFile, "output", "o", "complexity_churn.html", "Output graph file name")

flags.StringVarP(&plot.Plot, "plot-type", "t", git.Commits,
fmt.Sprintf("Specify churn type: [%s, %s, %s, %s]", git.Changes, git.Additions, git.Deletions, git.Commits))
flags.StringVarP(&churnType, "churn-type", "t", git.Commits,
fmt.Sprintf("Specify churn type for plotting: [%s, %s]", git.Changes, git.Commits))

// Churn flags
flags.StringVarP(&since, flag.LongSince, flag.ShortSince, "", "Start date for churn analysis (YYYY-MM-DD)")
flags.StringVarP(&until, flag.LongUntil, flag.ShortUntil, "", "End date for churn analysis (YYYY-MM-DD)")
flags.StringVarP(&since, flag.LongSince, flag.ShortSince, "", "Start date for analysis in format 'YYYY-MM-DD'")
flags.StringVarP(&until, flag.LongUntil, flag.ShortUntil, "", "End date for analysis in format 'YYYY-MM-DD'")

// Complexity flags
flags.StringVarP(&complexityOpts.Engine, flag.LongEngine, flag.ShortEngine, complexity.Gocyclo,
Expand Down
4 changes: 2 additions & 2 deletions grit/cmd/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func init() {
flags.BoolVarP(&flag.Verbose, flag.LongVerbose, flag.ShortVerbose, false, "Show detailed progress")

// Churn flags
flags.StringVarP(&since, flag.LongSince, flag.ShortSince, "", "Start date for analysis (YYYY-MM-DD)")
flags.StringVarP(&until, flag.LongUntil, flag.ShortUntil, "", "End date for analysis (YYYY-MM-DD)")
flags.StringVarP(&since, flag.LongSince, flag.ShortSince, "", "Start date for analysis in format 'YYYY-MM-DD'")
flags.StringVarP(&until, flag.LongUntil, flag.ShortUntil, "", "End date for analysis in format 'YYYY-MM-DD'")

// Complexity flags
flags.StringVarP(&complexityOpts.Engine, flag.LongEngine, flag.ShortEngine, complexity.Gocyclo,
Expand Down
12 changes: 6 additions & 6 deletions grit/cmd/stat/subcommands/churn.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
)

var ChurnCmd = &cobra.Command{ //nolint:exhaustruct // no need to set all fields
Use: "churn <path>",
Use: "churn [flags] <repository>",
Short: "Finds files with the most changes in git repository",
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
Expand Down Expand Up @@ -59,15 +59,15 @@ var ChurnCmd = &cobra.Command{ //nolint:exhaustruct // no need to set all fields
func init() {
flags := ChurnCmd.PersistentFlags()

flags.StringVar(&churnOpts.SortBy, flag.LongSort, "commits",
fmt.Sprintf("Sort by: %s, %s, %s, %s", git.Changes, git.Additions, git.Deletions, git.Commits))
flags.StringVar(&churnOpts.SortBy, flag.LongSort, git.Commits,
fmt.Sprintf("Specify churn sort type: [%s, %s, %s, %s]", git.Changes, git.Additions, git.Deletions, git.Commits))
flags.IntVarP(&churnOpts.Top, flag.LongTop, flag.ShortTop, git.DefaultTop, "Number of top files to display")
flags.BoolVarP(&flag.Verbose, flag.LongVerbose, flag.ShortVerbose, false, "Show detailed progress")
flags.StringVar(&churnOpts.ExcludePath, flag.LongExclude, "", "Exclude files matching regex pattern")
flags.StringSliceVarP(&extensionList, flag.LongExtensions, flag.ShortExt, nil,
"Only include files with given extensions in comma-separated list. For example go,h,c")
flags.StringVarP(&since, flag.LongSince, flag.ShortSince, "", "Start date for analysis (YYYY-MM-DD)")
flags.StringVarP(&until, flag.LongUntil, flag.ShortUntil, "", "End date for analysis (YYYY-MM-DD)")
"Only include files with given extensions in comma-separated list, e.g. 'go,h,c'")
flags.StringVarP(&since, flag.LongSince, flag.ShortSince, "", "Start date for analysis in format 'YYYY-MM-DD'")
flags.StringVarP(&until, flag.LongUntil, flag.ShortUntil, "", "End date for analysis in format 'YYYY-MM-DD'")

ChurnCmd.Flag(flag.LongUntil).DefValue = flag.DefaultUntil
ChurnCmd.Flag(flag.LongSince).DefValue = flag.DefaultSince
Expand Down
4 changes: 2 additions & 2 deletions grit/cmd/stat/subcommands/complexity.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var complexityOpts = complexity.Options{
}

var ComplexityCmd = &cobra.Command{ //nolint:exhaustruct // no need to set all fields
Use: "complexity <path>",
Use: "complexity [flags] <path>",
Short: "Finds the most complex files",
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
Expand Down Expand Up @@ -46,7 +46,7 @@ func init() {
flags := ComplexityCmd.PersistentFlags()

flags.StringVarP(&complexityOpts.Engine, flag.LongEngine, flag.ShortEngine, complexity.Gocyclo,
"Complexity calculation engine to use: gocyclo or gocognit")
fmt.Sprintf("Specify complexity calculation engine: [%s, %s]", complexity.Gocyclo, complexity.Gocognit))
flags.IntVarP(&complexityOpts.Top, flag.LongTop, flag.ShortTop, git.DefaultTop, "Number of top files to display")
flags.BoolVarP(&flag.Verbose, flag.LongVerbose, flag.ShortVerbose, false, "Show detailed progress")
flags.StringVar(&complexityOpts.ExcludePath, flag.LongExclude, "", "Exclude files matching regex pattern")
Expand Down
12 changes: 7 additions & 5 deletions grit/cmd/stat/subcommands/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var coverageOpts = coverage.Options{
}

var CoverageCmd = &cobra.Command{ //nolint:exhaustruct // no need to set all fields
Use: "coverage <path>",
Use: "coverage [flags] <path>",
Short: "Finds files with the least unit-test coverage",
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
Expand All @@ -47,12 +47,14 @@ var CoverageCmd = &cobra.Command{ //nolint:exhaustruct // no need to set all fie
func init() {
flags := CoverageCmd.PersistentFlags()

flags.StringVar(&coverageOpts.SortBy, flag.LongSort, coverage.Worst, "Specify sort type")
flags.StringVar(&coverageOpts.SortBy, flag.LongSort, coverage.Worst,
fmt.Sprintf("Specify sort type: [%s, %s]", coverage.Worst, coverage.Best))
flags.StringVarP(&coverageOpts.RunCoverage, flag.LongRunCoverage, flag.ShortRunCoverage, flag.Auto,
`Specify tests run format:
'Auto' will run unit tests if coverage file is not found
'Always' will run unit tests on every invoke 'stat coverage'
'Never' will never run unit tests and always look for present coverage file`)
'Auto' will run unit tests if coverage file is not found
'Always' will run unit tests on every invoke 'coverage' command
'Never' will never run unit tests and always look for present test-coverage file
`)
flags.StringVarP(&coverageOpts.CoverageFilename, flag.LongFileCoverage, flag.ShortFileCoverage, "coverage.out",
"Name of code coverage file to read or create")
flags.BoolVarP(&flag.Verbose, flag.LongVerbose, flag.ShortVerbose, false, "Enable verbose output")
Expand Down
16 changes: 8 additions & 8 deletions pkg/git/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (
"golang.org/x/exp/maps"
)

// SortType represents the type of sorting to be performed on the results of git log.
type SortType = string
// ChurnType represents the type of sorting to be performed on the results of git log.
type ChurnType = string

var (
Changes SortType = "changes"
Additions SortType = "additions"
Deletions SortType = "deletions"
Commits SortType = "commits"
Changes ChurnType = "changes"
Additions ChurnType = "additions"
Deletions ChurnType = "deletions"
Commits ChurnType = "commits"
)

const (
Expand Down Expand Up @@ -56,7 +56,7 @@ func (d *Date) Set(value string) error {
}

type ChurnOptions struct {
SortBy SortType
SortBy ChurnType
Top int
Path string
ExcludePath string
Expand Down Expand Up @@ -260,7 +260,7 @@ func shouldSkipFile(file string, opts *ChurnOptions) bool {
return false
}

func SortAndLimit(result []*ChurnChunk, sortBy SortType, limit int) []*ChurnChunk {
func SortAndLimit(result []*ChurnChunk, sortBy ChurnType, limit int) []*ChurnChunk {
less := func() func(i, j int) bool {
switch sortBy {
case Changes:
Expand Down
2 changes: 1 addition & 1 deletion pkg/git/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var testData = []*ChurnChunk{
func TestSortAndLimitTypes(t *testing.T) {
tests := []struct {
name string
sortBy SortType
sortBy ChurnType
expected []string
}{
{
Expand Down
17 changes: 4 additions & 13 deletions pkg/plot/scatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func CreateScatterChart( //nolint:funlen // TODO(v.baranov): Refactor

// Skip file if it is not found in chunk or files, first goes over all churns
// Matches based on filename.
func PreparePlotData(files []*complexity.FileStat, churns []*git.ChurnChunk) []ScatterEntry {
func PreparePlotData(files []*complexity.FileStat, churns []*git.ChurnChunk, churnType git.ChurnType) []ScatterEntry {
result := make([]ScatterEntry, 0)

// Create map for quick churn lookup
Expand All @@ -180,10 +180,10 @@ func PreparePlotData(files []*complexity.FileStat, churns []*git.ChurnChunk) []S
ScatterData: ScatterData{Complexity: fileComplexity.AvgComplexity, Churn: 0},
}

switch Plot {
case Commits:
switch churnType {
case git.Commits:
entry.Churn = churn.Commits
case Changes:
case git.Changes:
entry.Churn = churn.Churn
default:
panic("Unknown plot type")
Expand All @@ -194,12 +194,3 @@ func PreparePlotData(files []*complexity.FileStat, churns []*git.ChurnChunk) []S

return result
}

type ScatterOXType = string

const (
Commits ScatterOXType = "commits"
Changes ScatterOXType = "changes"
)

var Plot = Commits
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载