Skip to content

Commit

Permalink
🐛 Fix dep report filter depIDs(); add lables to dep apps report. (#437)
Browse files Browse the repository at this point in the history
When labels filter specified, the inner query was overwriting the outer
(main) query.
Few other fixes.
Adds labels to resource returned by /report/dependencies/applications.
Adds sample label to one of the deps in hack.

Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel committed Jul 7, 2023
1 parent df36681 commit ba0a8e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
48 changes: 27 additions & 21 deletions api/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,6 @@ func (h AnalysisHandler) DepReports(ctx *gin.Context) {
db := h.DB(ctx)
db = db.Select("*")
db = db.Table("(?)", q)
db = filter.Where(db)
db = sort.Sorted(db)
var list []M
var m M
Expand Down Expand Up @@ -1452,6 +1451,7 @@ func (h AnalysisHandler) DepAppReports(ctx *gin.Context) {
Version string
SHA string
Indirect bool
Labels model.JSON
}
// Filter
filter, err := qf.New(ctx,
Expand All @@ -1470,7 +1470,7 @@ func (h AnalysisHandler) DepAppReports(ctx *gin.Context) {
{Field: "dep.version", Kind: qf.LITERAL},
{Field: "dep.sha", Kind: qf.LITERAL},
{Field: "dep.indirect", Kind: qf.LITERAL},
{Field: "dep.labels", Kind: qf.LITERAL},
{Field: "dep.labels", Kind: qf.STRING, Relation: true},
{Field: "application.id", Kind: qf.LITERAL},
{Field: "application.name", Kind: qf.STRING},
{Field: "businessService.id", Kind: qf.LITERAL},
Expand Down Expand Up @@ -1500,7 +1500,8 @@ func (h AnalysisHandler) DepAppReports(ctx *gin.Context) {
"d.Name DepName",
"d.Version",
"d.SHA",
"d.Indirect")
"d.Indirect",
"d.Labels")
q = q.Table("TechDependency d")
q = q.Joins("LEFT JOIN Analysis a ON a.ID = d.AnalysisID")
q = q.Joins("LEFT JOIN Application app ON app.ID = a.ApplicationID")
Expand Down Expand Up @@ -1548,6 +1549,9 @@ func (h AnalysisHandler) DepAppReports(ctx *gin.Context) {
r.Dependency.Version = m.Version
r.Dependency.SHA = m.SHA
r.Dependency.Indirect = m.Indirect
if m.Labels != nil {
_ = json.Unmarshal(m.Labels, &r.Dependency.Labels)
}
resources = append(resources, r)
}

Expand Down Expand Up @@ -1661,21 +1665,22 @@ func (h *AnalysisHandler) depIDs(ctx *gin.Context, f qf.Filter) (q *gorm.DB) {
var qs []*gorm.DB
for _, f = range f.Expand() {
f = f.As("json_each.value")
q := h.DB(ctx)
q = q.Table("Issue")
q = q.Joins("m ,json_each(Labels)")
q = q.Select("m.ID")
q = f.Where(q)
qs = append(qs, q)
iq := h.DB(ctx)
iq = iq.Table("TechDependency")
iq = iq.Joins("m ,json_each(Labels)")
iq = iq.Select("m.ID")
iq = f.Where(iq)
qs = append(qs, iq)
}
q = model.Intersect(qs...)
q = q.Where("ID IN (?)", model.Intersect(qs...))
} else {
f = f.As("json_each.value")
q = h.DB(ctx)
q = q.Table("Issue")
q = q.Joins("m ,json_each(Labels)")
q = q.Select("m.ID")
q = f.Where(q)
iq := h.DB(ctx)
iq = iq.Table("TechDependency")
iq = iq.Joins("m ,json_each(Labels)")
iq = iq.Select("m.ID")
iq = f.Where(iq)
q = q.Where("ID IN (?)", iq)
}
}
return
Expand Down Expand Up @@ -1961,12 +1966,13 @@ type DepAppReport struct {
Description string `json:"description"`
BusinessService string `json:"businessService"`
Dependency struct {
ID uint `json:"id"`
Provider string `json:"provider"`
Name string `json:"name"`
Version string `json:"version"`
SHA string `json:"rule"`
Indirect bool `json:"indirect"`
ID uint `json:"id"`
Provider string `json:"provider"`
Name string `json:"name"`
Version string `json:"version"`
SHA string `json:"rule"`
Indirect bool `json:"indirect"`
Labels []string `json:"labels"`
} `json:"dependency"`
}

Expand Down
2 changes: 2 additions & 0 deletions hack/add/analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ file=${dPath}
echo -n "---
name: github.com/jboss
version: 5.0
labels:
- konveyor.io/dep-source
" > ${file}
echo -n "---
name: github.com/hybernate
Expand Down

0 comments on commit ba0a8e3

Please sign in to comment.