-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontracts.go
More file actions
125 lines (115 loc) · 3.6 KB
/
Copy pathcontracts.go
File metadata and controls
125 lines (115 loc) · 3.6 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package sight
import reviewcontracts "github.com/GrayCodeAI/hawk-core-contracts/review"
// ToContractFinding converts a sight finding into the shared review contract.
func ToContractFinding(f Finding) reviewcontracts.Finding {
return reviewcontracts.Finding{
Concern: f.Concern,
Severity: f.Severity,
File: f.File,
Line: f.Line,
EndLine: f.EndLine,
Message: f.Message,
Fix: f.Fix,
Reasoning: f.Reasoning,
CWE: f.CWE,
Confidence: f.Confidence,
SASTSource: f.SASTSource,
}
}
// ToContractFindings converts sight findings into shared review contracts.
func ToContractFindings(findings []Finding) []reviewcontracts.Finding {
if len(findings) == 0 {
return nil
}
out := make([]reviewcontracts.Finding, len(findings))
for i, f := range findings {
out[i] = ToContractFinding(f)
}
return out
}
// FromContractFinding converts a shared review contract into a sight finding.
func FromContractFinding(f reviewcontracts.Finding) Finding {
return Finding{
Concern: f.Concern,
Severity: f.Severity,
File: f.File,
Line: f.Line,
EndLine: f.EndLine,
Message: f.Message,
Fix: f.Fix,
Reasoning: f.Reasoning,
CWE: f.CWE,
Confidence: f.Confidence,
SASTSource: f.SASTSource,
}
}
// ToContractInlineComment converts a sight inline comment into the shared review contract.
func ToContractInlineComment(c InlineComment) reviewcontracts.InlineComment {
return reviewcontracts.InlineComment{
Path: c.Path,
StartLine: c.StartLine,
EndLine: c.EndLine,
Body: c.Body,
Suggestion: c.Suggestion,
}
}
// ToContractInlineComments converts sight inline comments into shared review contracts.
func ToContractInlineComments(comments []InlineComment) []reviewcontracts.InlineComment {
if len(comments) == 0 {
return nil
}
out := make([]reviewcontracts.InlineComment, len(comments))
for i, c := range comments {
out[i] = ToContractInlineComment(c)
}
return out
}
func toContractConfidenceBreakdown(b *ConfidenceBreakdown) *reviewcontracts.ConfidenceBreakdown {
if b == nil {
return nil
}
return &reviewcontracts.ConfidenceBreakdown{
High: ToContractFindings(b.High),
Medium: ToContractFindings(b.Medium),
Low: ToContractFindings(b.Low),
}
}
func toContractStats(s Stats) reviewcontracts.Stats {
return reviewcontracts.Stats{
FilesReviewed: s.FilesReviewed,
HunksAnalyzed: s.HunksAnalyzed,
FindingsTotal: s.FindingsTotal,
BySeverity: s.BySeverity,
ByConcern: s.ByConcern,
TokensUsed: s.TokensUsed,
DurationPerConcern: s.DurationPerConcern,
AverageConfidence: s.AverageConfidence,
HighConfidenceCount: s.HighConfidenceCount,
LowConfidenceCount: s.LowConfidenceCount,
}
}
func toContractSASTFusion(sf *SASTFusionResult) *reviewcontracts.SASTFusionResult {
if sf == nil {
return nil
}
return &reviewcontracts.SASTFusionResult{
Confirmed: ToContractFindings(sf.Confirmed),
Dismissed: ToContractFindings(sf.Dismissed),
Unaddressed: ToContractFindings(sf.Unaddressed),
}
}
// ToContractResult converts a sight result into the shared review contract.
func ToContractResult(r *Result) *reviewcontracts.Result {
if r == nil {
return nil
}
return &reviewcontracts.Result{
Findings: ToContractFindings(r.Findings),
Comments: ToContractInlineComments(r.Comments),
Stats: toContractStats(r.Stats),
Report: r.Report,
FailOn: r.FailOn,
SASTFusion: toContractSASTFusion(r.SASTFusion),
ConfidenceBreakdown: toContractConfidenceBreakdown(r.ConfidenceBreakdown),
}
}