Skip to content

Commit

Permalink
Merge pull request #237 from k1LoW/store-timeout
Browse files Browse the repository at this point in the history
Support `timeout:` and set default timeout
  • Loading branch information
k1LoW authored Jul 18, 2023
2 parents 2a28203 + 7fe033d commit cdd09b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var rootCmd = &cobra.Command{
return printMetrics(cmd)
}

ctx := context.Background()
addPaths := []string{}
cmd.PrintErrf("%s version %s\n", version.Name, version.Version)

Expand All @@ -78,6 +77,9 @@ var rootCmd = &cobra.Command{
cmd.PrintErrf("%s are not found\n", strings.Join(config.DefaultConfigFilePaths, " and "))
}

ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
defer cancel()

if reportPath != "" {
c.Coverage.Paths = []string{reportPath}
c.CodeToTestRatio = nil
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

const defaultBadgesDatastore = "local://reports"
const defaultReportsDatastore = "local://reports"
const defaultTimeout = "30sec"
const largeEnoughTime = float64(99 * time.Hour)

const (
Expand All @@ -46,6 +47,7 @@ type Config struct {
Summary *ConfigSummary `yaml:"summary,omitempty"`
Body *ConfigBody `yaml:"body,omitempty"`
Diff *ConfigDiff `yaml:"diff,omitempty"`
Timeout time.Duration `yaml:"timeout,omitempty"`
GitRoot string `yaml:"-"`
// working directory
wd string
Expand Down
9 changes: 9 additions & 0 deletions config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"regexp"

"github.com/goccy/go-yaml"
"github.com/k1LoW/duration"
)

var commentRe = regexp.MustCompile(`(?m)^comment:`)
Expand All @@ -23,6 +24,7 @@ func (c *Config) UnmarshalYAML(data []byte) error {
Summary *ConfigSummary `yaml:"summary,omitempty"`
Body *ConfigBody `yaml:"body,omitempty"`
Diff *ConfigDiff `yaml:"diff,omitempty"`
Timeout string `yaml:"timeout,omitempty"`
}{}
err := yaml.Unmarshal(data, &s)
if err != nil {
Expand All @@ -37,6 +39,13 @@ func (c *Config) UnmarshalYAML(data []byte) error {
c.Summary = s.Summary
c.Body = s.Body
c.Diff = s.Diff
if s.Timeout == "" {
s.Timeout = defaultTimeout
}
c.Timeout, err = duration.Parse(s.Timeout)
if err != nil {
return err
}

switch v := s.Comment.(type) {
case nil:
Expand Down

0 comments on commit cdd09b5

Please sign in to comment.