github.com/khulnasoft/codebase@v0.0.0-20231214144635-a707781cbb24/project/conf.go (about)

     1  // Package project provides utility for codebase execution based on project
     2  // config.
     3  package project
     4  
     5  import "gopkg.in/yaml.v3"
     6  
     7  // Config represents codebase config.
     8  type Config struct {
     9  	Runner map[string]*Runner
    10  }
    11  
    12  // Runner represents config for a runner.
    13  type Runner struct {
    14  	// Runner command. (e.g. `golint ./...`)
    15  	Cmd string
    16  	// tool name in review comment. (e.g. `golint`)
    17  	Name string
    18  	// errorformat name. (e.g. `checkstyle`)
    19  	Format string
    20  	// errorformat. (e.g. `%f:%l:%c:%m`, `%-G%.%#`)
    21  	Errorformat []string
    22  	// Report Level for this runner. ("info", "warning", "error")
    23  	Level string
    24  }
    25  
    26  // Parse parses codebase config in yaml format.
    27  func Parse(yml []byte) (*Config, error) {
    28  	out := &Config{}
    29  	if err := yaml.Unmarshal(yml, out); err != nil {
    30  		return nil, err
    31  	}
    32  	// Insert `Name` field if it's empty.
    33  	for name, runner := range out.Runner {
    34  		if runner.Name == "" {
    35  			runner.Name = name
    36  		}
    37  	}
    38  	return out, nil
    39  }