Skip to content

Commit

Permalink
Merge pull request #279 from k1LoW/metrics-if
Browse files Browse the repository at this point in the history
Support `if:` section for three metrics
  • Loading branch information
k1LoW authored Sep 30, 2023
2 parents 3b418fd + ece2c7d commit bc1f797
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,15 @@ coverage:
path: docs/coverage.svg
```

### `coverage.if:`

Conditions for measuring code coverage.

``` yaml
coverage:
if: is_default_branch
```

### `codeToTestRatio:`

Configuration for code to test ratio.
Expand Down Expand Up @@ -430,6 +439,15 @@ codeToTestRatio:
path: docs/ratio.svg
```

### `codeToTestRatio.if:`

Conditions for measuring code to test ratio.

``` yaml
codeToTestRatio:
if: is_default_branch
```

### `testExecutionTime:`

Configuration for test execution time.
Expand Down Expand Up @@ -490,6 +508,15 @@ testExecutionTime:
path: docs/time.svg
```

### `testExecutionTime.if:`

Conditions for measuring test execution time.

``` yaml
testExecutionTime:
if: is_pull_request
```

### `push:`

Configuration for `git push` files self.
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Coverage struct {
Paths []string `yaml:"paths,omitempty"`
Badge CoverageBadge `yaml:"badge,omitempty"`
Acceptable string `yaml:"acceptable,omitempty"`
If string `yaml:"if,omitempty"`
}

type CoverageBadge struct {
Expand All @@ -72,6 +73,7 @@ type CodeToTestRatio struct {
Test []string `yaml:"test"`
Badge CodeToTestRatioBadge `yaml:"badge,omitempty"`
Acceptable string `yaml:"acceptable,omitempty"`
If string `yaml:"if,omitempty"`
}

type CodeToTestRatioBadge struct {
Expand All @@ -82,6 +84,7 @@ type TestExecutionTime struct {
Badge TestExecutionTimeBadge `yaml:"badge,omitempty"`
Acceptable string `yaml:"acceptable,omitempty"`
Steps []string `yaml:"steps,omitempty"`
If string `yaml:"if,omitempty"`
}

type TestExecutionTimeBadge struct {
Expand Down
21 changes: 21 additions & 0 deletions config/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ func (c *Config) CoverageConfigReady() error {
if len(c.Coverage.Paths) == 0 {
return errors.New("coverage.paths: is not set")
}
ok, err := c.CheckIf(c.Coverage.If)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("the condition in the `if` section is not met (%s)", c.Coverage.If)
}
return nil
}

Expand All @@ -26,6 +33,13 @@ func (c *Config) CodeToTestRatioConfigReady() error {
if len(c.CodeToTestRatio.Test) == 0 {
return errors.New("codeToTestRatio.test: is not set")
}
ok, err := c.CheckIf(c.CodeToTestRatio.If)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("the condition in the `if` section is not met (%s)", c.CodeToTestRatio.If)
}
return nil
}

Expand All @@ -36,6 +50,13 @@ func (c *Config) TestExecutionTimeConfigReady() error {
if err := c.CoverageConfigReady(); err != nil && len(c.TestExecutionTime.Steps) == 0 {
return err
}
ok, err := c.CheckIf(c.TestExecutionTime.If)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("the condition in the `if` section is not met (%s)", c.TestExecutionTime.If)
}
return nil
}

Expand Down

0 comments on commit bc1f797

Please sign in to comment.