Skip to content

Commit b0d7a99

Browse files
Merge pull request #70 from easy-up/main
fix: crash bug when adding a bundle file with no tag
2 parents 010a2e4 + bc048e0 commit b0d7a99

16 files changed

+306
-74
lines changed

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [UNRELEASED]
99

10+
## [0.8.0] - 2024-10-23
11+
12+
* Fixed a bug where validation failures were not resulting in a non-zero exit code
13+
* Renamed the --file / -f CLI argument to --config / -f for consistency with other tools
14+
* improvements to validate output
15+
These "improvements" are short term hacks. There is a need for a fundamental
16+
overhaul of how output is generated to improve usability
17+
* Implemented code coverage support.
18+
* Updated the docs to reflect the removal of the --all flag
19+
20+
## [0.7.6] - 2024-09-08
21+
22+
### Fixed
23+
24+
- Crash when running `gatecheck bundle add` with no tags
25+
1026
## [0.7.5] - 2024-06-18
1127

1228
### Fixed

cmd/cli-config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var RuntimeConfig = metaConfig{
4545
BundleTag: configkit.MetaField{
4646
FieldName: "BundleTag",
4747
EnvKey: "GATECHECK_BUNDLE_TAG",
48-
DefaultValue: "",
48+
DefaultValue: []string{},
4949
FlagValueP: new([]string),
5050
EnvToValueFunc: func(s string) any {
5151
return strings.Split(s, ",")
@@ -165,7 +165,7 @@ var RuntimeConfig = metaConfig{
165165
CobraSetupFunc: func(f configkit.MetaField, cmd *cobra.Command) {
166166
valueP := f.FlagValueP.(*string)
167167
usage := f.Metadata[metadataFlagUsage]
168-
cmd.PersistentFlags().StringVarP(valueP, "file", "f", "", usage)
168+
cmd.PersistentFlags().StringVarP(valueP, "config", "f", "", usage)
169169
},
170170
Metadata: map[string]string{
171171
metadataFlagUsage: "a validation configuration file",

cmd/validate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var validateCmd = &cobra.Command{
6969
return nil
7070
}
7171

72-
return nil
72+
return err
7373
},
7474
}
7575

demos/bundle.tape

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Set Width 1800
1010

1111
Output dist/gatecheck-bundle.gif
1212

13-
Type "gatecheck ls --all grype-report.json | less"
13+
Type "gatecheck ls grype-report.json | less"
1414
Sleep 1
1515
Enter
1616
Sleep 5

demos/list.tape

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Set Width 1600
1010

1111
Output dist/gatecheck-list.gif
1212

13-
Type "grype ubuntu:latest -o json | gatecheck ls --all -i grype | less"
13+
Type "grype ubuntu:latest -o json | gatecheck ls -i grype | less"
1414
Sleep 1
1515
Enter
1616

demos/validate.tape

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Set Width 1700
1010

1111
Output dist/gatecheck-validate.gif
1212

13-
Type "gatecheck ls --all grype-report.json | less"
13+
Type "gatecheck ls grype-report.json | less"
1414
Sleep 1
1515
Enter
1616
Sleep 5
-327 KB
Binary file not shown.

docs/list-reports.md

-8
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,3 @@ gatecheck ls grype-scan-report.json
2222
```
2323

2424
![Screenshot Example List](assets/screenshot-grype-list.png)
25-
26-
Using the `--all` or `-a` flag will do a full listing, cross-referencing with FIRST EPSS API
27-
28-
```shell
29-
grype bkimminich/juice-shop:latest -o json | gatecheck ls --all -i grype
30-
```
31-
32-
![Screenshot Example List All](assets/screenshot-grype-list-all.png)

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
)
1515

1616
require (
17+
github.com/easy-up/go-coverage v0.0.0-20241018034313-3de592d59a78 // indirect
1718
github.com/fsnotify/fsnotify v1.7.0 // indirect
1819
github.com/hashicorp/hcl v1.0.0 // indirect
1920
github.com/inconshreveable/mousetrap v1.1.0 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
55
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
66
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
77
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
8+
github.com/easy-up/go-coverage v0.0.0-20241018034313-3de592d59a78 h1:e2x+TfIgebN3zfr8wGqAYI9lK4ql7Rut6OTEhBmJr5k=
9+
github.com/easy-up/go-coverage v0.0.0-20241018034313-3de592d59a78/go.mod h1:fsSINOc273zPnsBaKNjNffZXZpicAArpv/cTiFYgPys=
810
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
911
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
1012
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=

pkg/archive/bundle.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/json"
1111
"errors"
1212
"fmt"
13+
"github.com/olekukonko/tablewriter"
1314
"io"
1415
"log/slog"
1516
"os"
@@ -159,7 +160,10 @@ func (b *Bundle) Content() string {
159160
sort.Sort(matrix)
160161
buf := new(bytes.Buffer)
161162
header := []string{"Label", "Digest", "Tags", "Size"}
162-
matrix.Table(buf, header).Render()
163+
table := tablewriter.NewWriter(buf)
164+
table.SetHeader(header)
165+
matrix.Table(table)
166+
table.Render()
163167
return buf.String()
164168
}
165169

pkg/artifacts/lcov.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package artifacts
2+
3+
import (
4+
"errors"
5+
"github.com/easy-up/go-coverage"
6+
"log/slog"
7+
"strings"
8+
)
9+
10+
func example() (coverage.Report, error) {
11+
lcovParser := coverage.New(coverage.LCOV)
12+
report, err := lcovParser.Parse("./path/to/lcov.info")
13+
if err != nil {
14+
// Handle error
15+
return coverage.Report{}, err
16+
}
17+
// Use the parsed report
18+
return report, nil
19+
}
20+
21+
func IsCoverageReport(inputFilename string) bool {
22+
return strings.Contains(inputFilename, "lcov") ||
23+
strings.HasSuffix(inputFilename, ".info") ||
24+
strings.Contains(inputFilename, "clover") ||
25+
strings.Contains(inputFilename, "cobertura") ||
26+
strings.Contains(inputFilename, "coverage")
27+
}
28+
29+
func GetCoverageMode(inputFilename string) (coverage.CoverageMode, error) {
30+
var coverageFormat coverage.CoverageMode
31+
if strings.Contains(inputFilename, "lcov") || strings.HasSuffix(inputFilename, ".info") {
32+
coverageFormat = coverage.LCOV
33+
} else if strings.Contains(inputFilename, "clover") {
34+
coverageFormat = coverage.CLOVER
35+
} else if strings.HasSuffix(inputFilename, ".xml") {
36+
coverageFormat = coverage.COBERTURA
37+
} else {
38+
slog.Error("unsupported coverage file type, cannot be determined from filename", "filename", inputFilename)
39+
return "", errors.New("failed to list coverage content")
40+
}
41+
return coverageFormat, nil
42+
}

pkg/format/matrix.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package format
22

33
import (
4-
"io"
5-
64
"github.com/olekukonko/tablewriter"
75
)
86

@@ -28,11 +26,8 @@ func (m *SortableMatrix) Matrix() [][]string {
2826
return m.data
2927
}
3028

31-
func (m *SortableMatrix) Table(w io.Writer, header []string) *tablewriter.Table {
32-
table := tablewriter.NewWriter(w)
33-
table.SetHeader(header)
29+
func (m *SortableMatrix) Table(table *tablewriter.Table) {
3430
table.AppendBulk(m.data)
35-
return table
3631
}
3732

3833
func (m *SortableMatrix) Len() int {

pkg/gatecheck/config.go

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Config struct {
2828
Cyclonedx reportWithCVEs `json:"cyclonedx" toml:"cyclonedx" yaml:"cyclonedx"`
2929
Semgrep configSemgrepReport `json:"semgrep" toml:"semgrep" yaml:"semgrep"`
3030
Gitleaks configGitleaksReport `json:"gitleaks" toml:"gitleaks" yaml:"gitleaks"`
31+
Coverage configCoverageReport `json:"coverage" toml:"coverage" yaml:"coverage"`
3132
}
3233

3334
func (c *Config) String() string {
@@ -48,6 +49,12 @@ func (c *Config) String() string {
4849
return contentBuf.String()
4950
}
5051

52+
type configCoverageReport struct {
53+
LineThreshold float32 `json:"lineThreshold" toml:"lineThreshold" yaml:"lineThreshold"`
54+
FunctionThreshold float32 `json:"functionThreshold" toml:"functionThreshold" yaml:"functionThreshold"`
55+
BranchThreshold float32 `json:"branchThreshold" toml:"branchThreshold" yaml:"branchThreshold"`
56+
}
57+
5158
type configGitleaksReport struct {
5259
LimitEnabled bool `json:"limitEnabled" toml:"limitEnabled" yaml:"limitEnabled"`
5360
}
@@ -225,6 +232,11 @@ func NewDefaultConfig() *Config {
225232
Gitleaks: configGitleaksReport{
226233
LimitEnabled: false,
227234
},
235+
Coverage: configCoverageReport{
236+
LineThreshold: 0,
237+
FunctionThreshold: 0,
238+
BranchThreshold: 0,
239+
},
228240
}
229241
}
230242

0 commit comments

Comments
 (0)