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 3496d6c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
39 changes: 18 additions & 21 deletions api/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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("*")
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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"`
}
Expand All @@ -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"`
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 3496d6c

Please sign in to comment.