From 3496d6cd70b4ce2a82e5bc1cd640237dd90ca1fb Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Tue, 14 Nov 2023 14:12:50 -0800 Subject: [PATCH] DepReport aggregated by name. Signed-off-by: Jeff Ortel --- api/analysis.go | 39 ++++++++++++++++++--------------------- hack/add/analysis.sh | 12 ++++++++++-- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/api/analysis.go b/api/analysis.go index aa1529d8a..1aaa2a57e 100644 --- a/api/analysis.go +++ b/api/analysis.go @@ -1352,9 +1352,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 +1361,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 @@ -1406,16 +1402,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 +1443,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 +2082,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 +2098,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