-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult.go
More file actions
97 lines (81 loc) · 2.5 KB
/
result.go
File metadata and controls
97 lines (81 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package codacytool
import (
"encoding/json"
"github.com/sirupsen/logrus"
)
// Result encompasses all possible results: Issues and File Errors.
type Result interface {
// ToJSON returns a JSON representation of the result.
ToJSON() ([]byte, error)
// GetFile returns the file for this result.
GetFile() string
}
// Issue is the output for each issue found by the tool.
type Issue struct {
PatternID string `json:"patternId"`
File string `json:"filename"`
Line int `json:"line"`
Message string `json:"message"`
Suggestion string `json:"suggestion,omitempty"`
SourceID string `json:"sourceId,omitempty"`
}
func (i Issue) ToJSON() ([]byte, error) {
return json.Marshal(i)
}
func (i Issue) GetFile() string {
return i.File
}
// FileError represents an error analysing a file.
// If this result is returned from an analysis, the referenced file is not considered to have been analysed.
type FileError struct {
File string `json:"filename"`
Message string `json:"message"`
}
func (i FileError) ToJSON() ([]byte, error) {
return json.Marshal(i)
}
func (i FileError) GetFile() string {
return i.File
}
// An "enum" representing the supported BOM formats.
type BomFormat string
const (
// [CycloneDX] specification in JSON format.
//
// [CycloneDX]: https://cyclonedx.org/
CycloneDXJSON = BomFormat("CycloneDXJSON")
)
// SBOM - Software Bill of Materials
//
// A SBOM declares the inventory of components used to build a software artifact, including any open source and
// proprietary software components.
type SBOM struct {
// The format of the SBOM. Currently only [CycloneDX] specification in JSON format is supported.
//
// [CycloneDX]: https://cyclonedx.org/
BomFormat BomFormat `json:"bomFormat"`
// The version of the SBOM format used to build this SBOM.
SpecVersion string `json:"specVersion"`
// The actual SBOM content. To be parsed by downstream consumers according to `bomFormat` and `specVersion`.
Sbom string `json:"sbom"`
}
func (s SBOM) ToJSON() ([]byte, error) {
return json.Marshal(s)
}
// GetFile always returns an empty value since SBOM is for the whole project, not a single file.
func (s SBOM) GetFile() string {
return ""
}
type Results []Result
func (r Results) ToJSON() []string {
var jsonResults []string
for _, result := range r {
jsonResult, err := result.ToJSON()
if err != nil {
logrus.Errorf("Failed to convert Result to JSON: %+v\n%s", result, err.Error())
} else {
jsonResults = append(jsonResults, string(jsonResult))
}
}
return jsonResults
}