File tree Expand file tree Collapse file tree 3 files changed +9
-7
lines changed
Expand file tree Collapse file tree 3 files changed +9
-7
lines changed Original file line number Diff line number Diff line change 22package patrol
33
44import (
5+ "cmp"
56 "errors"
67 "fmt"
78 "os"
@@ -11,12 +12,12 @@ import (
1112 "sheriff/internal/publish"
1213 "sheriff/internal/scanner"
1314 "sheriff/internal/slack"
14- "sort"
1515 "sync"
1616
1717 "github.com/elliotchance/pie/v2"
1818 "github.com/rs/zerolog/log"
1919 gogitlab "github.com/xanzy/go-gitlab"
20+ "golang.org/x/exp/slices"
2021)
2122
2223const tempScanDir = "tmp_scans"
@@ -145,8 +146,8 @@ func (s *sheriffService) scanAndGetReports(locations []config.ProjectLocation) (
145146 reports = append (reports , r )
146147 }
147148
148- sort . Slice (reports , func (i int , j int ) bool {
149- return len (reports [ i ] .Vulnerabilities ) > len (reports [ j ] .Vulnerabilities )
149+ slices . SortFunc (reports , func (a , b scanner. Report ) int {
150+ return cmp . Compare ( len (b .Vulnerabilities ), len (a .Vulnerabilities ) )
150151 })
151152
152153 return
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import (
1414)
1515
1616// severityScoreOrder represents the order of SeverityScoreKind by their score in descending order
17- // which is how we want to display it in the
17+ // which is how we want to display it in the Issue report
1818var severityScoreOrder = getSeverityScoreOrder (scanner .SeverityScoreThresholds )
1919
2020// now is a function that returns the current time
Original file line number Diff line number Diff line change 11package publish
22
33import (
4+ "cmp"
45 "errors"
56 "fmt"
67 "sheriff/internal/scanner"
78 "sheriff/internal/slack"
8- "sort "
9+ "slices "
910 "strings"
1011 "sync"
1112 "time"
@@ -259,8 +260,8 @@ func getSeverityScoreOrder(thresholds map[scanner.SeverityScoreKind]float64) []s
259260 for kind := range thresholds {
260261 kinds = append (kinds , kind )
261262 }
262- sort . Slice (kinds , func (i , j int ) bool {
263- return thresholds [kinds [ i ]] > thresholds [kinds [ j ]]
263+ slices . SortFunc (kinds , func (a , b scanner. SeverityScoreKind ) int {
264+ return cmp . Compare ( thresholds [b ], thresholds [a ])
264265 })
265266
266267 return kinds
You can’t perform that action at this time.
0 commit comments