Skip to content

Commit

Permalink
DepReport aggregated by name.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Nov 14, 2023
1 parent b6bd184 commit 0b30d73
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
53 changes: 24 additions & 29 deletions api/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -13,11 +19,6 @@ import (
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/logger"
"io"
"net/http"
"os"
"strconv"
"strings"
)

//
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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},
Expand All @@ -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("*")
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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"`
}
Expand All @@ -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"`
Expand Down
12 changes: 10 additions & 2 deletions hack/add/analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b30d73

Please sign in to comment.