From 0b30d73dae0becae80668ddccb9ce14b8c4ec7e7 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Tue, 14 Nov 2023 14:04:35 -0800 Subject: [PATCH] DepReport aggregated by name. Signed-off-by: Jeff Ortel --- api/analysis.go | 53 ++++++++++++++++++++------------------------ hack/add/analysis.sh | 12 ++++++++-- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/api/analysis.go b/api/analysis.go index aa1529d8a..517e8445e 100644 --- a/api/analysis.go +++ b/api/analysis.go @@ -4,6 +4,12 @@ import ( "bytes" "encoding/json" "errors" + "io" + "net/http" + "os" + "strconv" + "strings" + "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" qf "github.com/konveyor/tackle2-hub/api/filter" @@ -13,11 +19,6 @@ import ( "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/logger" - "io" - "net/http" - "os" - "strconv" - "strings" ) // @@ -1352,9 +1353,6 @@ func (h AnalysisHandler) Deps(ctx *gin.Context) { // @description filters: // @description - provider // @description - name -// @description - version -// @description - sha -// @description - indirect // @description - labels // @description - application.id // @description - application.name @@ -1364,8 +1362,7 @@ func (h AnalysisHandler) Deps(ctx *gin.Context) { // @description sort: // @description - provider // @description - name -// @description - version -// @description - sha +// @description - labels // @tags dependencies // @produce json // @success 200 {object} []api.TechDependency @@ -1381,9 +1378,6 @@ func (h AnalysisHandler) DepReports(ctx *gin.Context) { []qf.Assert{ {Field: "provider", Kind: qf.STRING}, {Field: "name", Kind: qf.STRING}, - {Field: "version", Kind: qf.STRING}, - {Field: "sha", Kind: qf.STRING}, - {Field: "indirect", Kind: qf.STRING}, {Field: "labels", Kind: qf.STRING, And: true}, {Field: "applications", Kind: qf.LITERAL}, {Field: "application.id", Kind: qf.LITERAL}, @@ -1406,16 +1400,15 @@ func (h AnalysisHandler) DepReports(ctx *gin.Context) { // Inner Query q := h.DB(ctx) q = q.Select( - "Provider", - "Name", - "Version", - "SHA", - "Labels", - "COUNT(distinct AnalysisID) Applications") - q = q.Model(&model.TechDependency{}) - q = q.Where("AnalysisID IN (?)", h.analysisIDs(ctx, filter)) - q = q.Where("ID IN (?)", h.depIDs(ctx, filter)) - q = q.Group("Name,SHA") + "d.Provider", + "d.Name", + "json_group_array(distinct j.value) Labels", + "COUNT(distinct d.AnalysisID) Applications") + q = q.Table("TechDependency d") + q = q.Joins(",json_each(Labels) j") + q = q.Where("d.AnalysisID IN (?)", h.analysisIDs(ctx, filter)) + q = q.Where("d.ID IN (?)", h.depIDs(ctx, filter)) + q = q.Group("d.Provider, d.Name") // Find db := h.DB(ctx) db = db.Select("*") @@ -1448,12 +1441,16 @@ func (h AnalysisHandler) DepReports(ctx *gin.Context) { r := DepReport{ Provider: m.Provider, Name: m.Name, - Version: m.Version, - SHA: m.SHA, Applications: m.Applications, } if m.Labels != nil { - _ = json.Unmarshal(m.Labels, &r.Labels) + var aggregated []string + _ = json.Unmarshal(m.Labels, &aggregated) + for _, s := range aggregated { + if s != "" { + r.Labels = append(r.Labels, s) + } + } } resources = append(resources, r) } @@ -2083,8 +2080,6 @@ type FileReport struct { type DepReport struct { Provider string `json:"provider"` Name string `json:"name"` - Version string `json:"version"` - SHA string `json:"sha"` Labels []string `json:"labels"` Applications int `json:"applications"` } @@ -2101,7 +2096,7 @@ type DepAppReport struct { Provider string `json:"provider"` Name string `json:"name"` Version string `json:"version"` - SHA string `json:"rule"` + SHA string `json:"sha"` Indirect bool `json:"indirect"` Labels []string `json:"labels"` } `json:"dependency"` diff --git a/hack/add/analysis.sh b/hack/add/analysis.sh index c1fa159f4..15bfb58c2 100755 --- a/hack/add/analysis.sh +++ b/hack/add/analysis.sh @@ -156,11 +156,19 @@ done file=${dPath} echo -n "--- name: github.com/jboss -version: 5.0 +version: 4.0 labels: -- konveyor.io/dep-source +- konveyor.io/language=java +- konveyor.io/otherA=dog " > ${file} echo -n "--- +name: github.com/jboss +version: 5.0 +labels: +- konveyor.io/language=java +- konveyor.io/otherA=cat +" >> ${file} +echo -n "--- name: github.com/hybernate indirect: "true" version: 4.6