github.com/massongit/reviewdog@v0.0.0-20240331071725-4a16675475a8/service/bitbucket/helpers.go (about) 1 package bitbucket 2 3 import ( 4 "crypto/sha256" 5 "fmt" 6 "strings" 7 8 "github.com/reviewdog/reviewdog/proto/rdf" 9 "google.golang.org/protobuf/proto" 10 ) 11 12 func hash(b []byte) string { 13 h := sha256.New() 14 _, _ = h.Write(b) 15 return fmt.Sprintf("%x", h.Sum(nil)) 16 } 17 18 // Note that it might be good to create external ReportID from the diagnostic 19 // content along with *original line* (by using git blame for example) to 20 // generate unique ReportID, but it hashes the Diagnostic message for simplicity. 21 func externalIDFromDiagnostic(d *rdf.Diagnostic) string { 22 b, err := proto.Marshal(d) 23 if err != nil { 24 b = []byte(d.OriginalOutput) 25 } 26 return hash(b) 27 } 28 29 func reportID(ids ...string) string { 30 return strings.ReplaceAll(strings.ToLower(strings.Join(ids, "-")), " ", "_") 31 } 32 33 func reportTitle(tool, reporter string) string { 34 return fmt.Sprintf("[%s] %s report", tool, reporter) 35 } 36 37 func convertSeverity(severity rdf.Severity) string { 38 switch severity { 39 case rdf.Severity_INFO: 40 return annotationSeverityLow 41 42 case rdf.Severity_WARNING: 43 return annotationSeverityMedium 44 45 case rdf.Severity_ERROR: 46 return annotationSeverityHigh 47 48 case rdf.Severity_UNKNOWN_SEVERITY: 49 return "" 50 51 default: 52 return "" 53 } 54 }