/
helpers.go
54 lines (43 loc) · 1.17 KB
/
helpers.go
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
package bitbucket
import (
"crypto/sha256"
"fmt"
"strings"
"github.com/khulnasoft/codebase/proto/rdf"
"google.golang.org/protobuf/proto"
)
func hash(b []byte) string {
h := sha256.New()
_, _ = h.Write(b)
return fmt.Sprintf("%x", h.Sum(nil))
}
// Note that it might be good to create external ReportID from the diagnostic
// content along with *original line* (by using git blame for example) to
// generate unique ReportID, but it hashes the Diagnostic message for simplicity.
func externalIDFromDiagnostic(d *rdf.Diagnostic) string {
b, err := proto.Marshal(d)
if err != nil {
b = []byte(d.OriginalOutput)
}
return hash(b)
}
func reportID(ids ...string) string {
return strings.ReplaceAll(strings.ToLower(strings.Join(ids, "-")), " ", "_")
}
func reportTitle(tool, reporter string) string {
return fmt.Sprintf("[%s] %s report", tool, reporter)
}
func convertSeverity(severity rdf.Severity) string {
switch severity {
case rdf.Severity_INFO:
return annotationSeverityLow
case rdf.Severity_WARNING:
return annotationSeverityMedium
case rdf.Severity_ERROR:
return annotationSeverityHigh
case rdf.Severity_UNKNOWN_SEVERITY:
return ""
default:
return ""
}
}