Skip to content

Commit

Permalink
Fix curation Github Summary (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
asafambar authored Jul 28, 2024
1 parent b89f58d commit 58b8ce6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
9 changes: 4 additions & 5 deletions commands/curation/curationaudit.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func convertBlocked(pkgStatus []*PackageStatus) formats.TwoLevelSummaryCount {
if _, ok := blocked[polAndCond]; !ok {
blocked[polAndCond] = formats.SummaryCount{}
}
uniqId := uniqPkgAppearanceId(pkg.ParentName, pkg.ParentVersion, pkg.PackageName, pkg.PackageVersion)
uniqId := getPackageId(pkg.PackageName, pkg.PackageVersion)
blocked[polAndCond][uniqId]++
}
}
Expand All @@ -280,10 +280,9 @@ func formatPolicyAndCond(policy, cond string) string {
return fmt.Sprintf("Policy: %s, Condition: %s", policy, cond)
}

// The unique identifier of a package includes both the package name with its version and the parent package with its version
func uniqPkgAppearanceId(parentName, parentVersion, packageName, packageVersion string) string {
return fmt.Sprintf("%s:%s-%s:%s",
parentName, parentVersion, packageName, packageVersion)
// The unique identifier of a package includes the package name with its version
func getPackageId(packageName, packageVersion string) string {
return fmt.Sprintf("%s:%s", packageName, packageVersion)
}

func (ca *CurationAuditCommand) doCurateAudit(results map[string]*CurationReport) error {
Expand Down
10 changes: 5 additions & 5 deletions commands/curation/curationaudit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ func Test_convertResultsToSummary(t *testing.T) {
CuratedPackages: &formats.CuratedPackages{
Blocked: formats.TwoLevelSummaryCount{
formatPolicyAndCond("policy1", "cond1"): formats.SummaryCount{
uniqPkgAppearanceId("parent-test1", "1.0.0", "test1", "1.0.0"): 1,
getPackageId("test1", "1.0.0"): 1,
},
},
Approved: 4,
Expand Down Expand Up @@ -960,12 +960,12 @@ func Test_convertResultsToSummary(t *testing.T) {
CuratedPackages: &formats.CuratedPackages{
Blocked: formats.TwoLevelSummaryCount{
formatPolicyAndCond("policy1", "cond1"): formats.SummaryCount{
uniqPkgAppearanceId("parent-test1", "1.0.0", "test1", "1.0.0"): 1,
getPackageId("test1", "1.0.0"): 1,
},
formatPolicyAndCond("policy2", "cond2"): formats.SummaryCount{
uniqPkgAppearanceId("parent-test1", "1.0.0", "test1", "1.0.0"): 1,
uniqPkgAppearanceId("parent-test2", "2.0.0", "test2", "2.0.0"): 1,
uniqPkgAppearanceId("parent-test3", "3.0.0", "test3", "3.0.0"): 1,
getPackageId("test1", "1.0.0"): 1,
getPackageId("test2", "2.0.0"): 1,
getPackageId("test3", "3.0.0"): 1,
},
},
Approved: 2,
Expand Down
2 changes: 1 addition & 1 deletion formats/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *ScanVulnerabilitiesSummary) GetTotalIssueCount() (total int) {
}

func (s *CuratedPackages) GetTotalPackages() int {
return s.Approved + s.Blocked.GetTotal()
return s.Approved + s.Blocked.GetCountOfKeys(false)
}

func (s *ScanVulnerabilitiesSummary) getTotalIssueCount(unique bool) (total int) {
Expand Down
4 changes: 2 additions & 2 deletions tests/testdata/other/jobSummary/multi_command_job.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
#### Curation
| Status | Id | Details |
|--------|----|---------|
|| /application1 | <pre>Total number of packages: <b>6</b><br>🟢 Total Number of Approved: <b>4</b><br>🔴 Total Number of Blocked: <b>2</b><br>├── Policy: cvss_score, Condition:cvss score higher than 4.0 (1)<br>└── Policy: Malicious, Condition: Malicious package (1)</pre> |
|| /application2 | <pre>Total number of packages: <b>6</b><br>🟢 Total Number of Approved: <b>4</b><br>🔴 Total Number of Blocked: <b>2</b><br>├── Policy: License, Condition: GPL (1)<br>└── Policy: Aged, Condition: Package is aged (1)</pre> |
|| /application1 | <pre>Total Number of Packages: <b>6</b><br>🟢 Total Number of Approved Packages: <b>4</b><br>🔴 Total Number of Blocked Packages: <b>2</b><br>├── Policy: cvss_score, Condition:cvss score higher than 4.0 (1)<br>└── Policy: Malicious, Condition: Malicious package (1)</pre> |
|| /application2 | <pre>Total Number of Packages: <b>6</b><br>🟢 Total Number of Approved Packages: <b>4</b><br>🔴 Total Number of Blocked Packages: <b>2</b><br>├── Policy: License, Condition: GPL (1)<br>└── Policy: Aged, Condition: Package is aged (1)</pre> |
6 changes: 3 additions & 3 deletions utils/securityJobSummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ func getBlockedCurationSummaryString(summary formats.ScanSummaryResult) (content
if !summary.HasBlockedCuration() {
return
}
content += fmt.Sprintf("Total number of packages: <b>%d</b>", summary.CuratedPackages.GetTotalPackages())
content += fmt.Sprintf("<br>🟢 Total Number of Approved: <b>%d</b>", summary.CuratedPackages.Approved)
content += fmt.Sprintf("<br>🔴 Total Number of Blocked: <b>%d</b>", summary.CuratedPackages.Blocked.GetTotal())
content += fmt.Sprintf("Total Number of Packages: <b>%d</b>", summary.CuratedPackages.GetTotalPackages())
content += fmt.Sprintf("<br>🟢 Total Number of Approved Packages: <b>%d</b>", summary.CuratedPackages.Approved)
content += fmt.Sprintf("<br>🔴 Total Number of Blocked Packages: <b>%d</b>", summary.CuratedPackages.Blocked.GetCountOfKeys(false))
if summary.CuratedPackages.Blocked.GetTotal() > 0 {
var blocked []struct {
BlockedName string
Expand Down

0 comments on commit 58b8ce6

Please sign in to comment.