Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 DepReport aggregated by name. #558

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions api/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"io"
"net/http"
"os"
"sort"
"strconv"
"strings"
)
Expand Down Expand Up @@ -1364,8 +1365,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 +1406,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 +1447,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 @@ -1964,6 +1967,7 @@ func (r *TechDependency) With(m *model.TechDependency) {
//
// Model builds a model.
func (r *TechDependency) Model() (m *model.TechDependency) {
sort.Strings(r.Labels)
m = &model.TechDependency{}
m.Name = r.Name
m.Version = r.Version
Expand Down Expand Up @@ -2083,8 +2087,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 +2103,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
9 changes: 4 additions & 5 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT
// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
package docs

import "github.com/swaggo/swag"
Expand Down Expand Up @@ -139,7 +140,7 @@ const docTemplate = `{
},
"/analyses/dependencies": {
"get": {
"description": "Each report collates dependencies by name and SHA.\nfilters:\n- provider\n- name\n- version\n- sha\n- indirect\n- labels\n- application.id\n- application.name\n- businessService.id\n- businessService.name\n- tag.id\nsort:\n- provider\n- name\n- version\n- sha",
"description": "Each report collates dependencies by name and SHA.\nfilters:\n- provider\n- name\n- version\n- sha\n- indirect\n- labels\n- application.id\n- application.name\n- businessService.id\n- businessService.name\n- tag.id\nsort:\n- provider\n- name\n- labels",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -5849,7 +5850,7 @@ const docTemplate = `{
"provider": {
"type": "string"
},
"rule": {
"sha": {
"type": "string"
},
"version": {
Expand Down Expand Up @@ -7429,8 +7430,6 @@ var SwaggerInfo = &swag.Spec{
Description: "",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
Expand Down
2,777 changes: 1,427 additions & 1,350 deletions docs/index.html

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions docs/openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"dependencies"
],
"summary": "List dependency reports.",
"description": "Each report collates dependencies by name and SHA.\nfilters:\n- provider\n- name\n- version\n- sha\n- indirect\n- labels\n- application.id\n- application.name\n- businessService.id\n- businessService.name\n- tag.id\nsort:\n- provider\n- name\n- version\n- sha",
"description": "Each report collates dependencies by name and SHA.\nfilters:\n- provider\n- name\n- version\n- sha\n- indirect\n- labels\n- application.id\n- application.name\n- businessService.id\n- businessService.name\n- tag.id\nsort:\n- provider\n- name\n- labels",
"responses": {
"200": {
"description": "OK",
Expand Down Expand Up @@ -6240,7 +6240,7 @@
"provider": {
"type": "string"
},
"rule": {
"sha": {
"type": "string"
},
"version": {
Expand Down Expand Up @@ -6297,10 +6297,12 @@
}
},
"api.FactMap": {
"type": "object"
"type": "object",
"additionalProperties": true
},
"api.Fields": {
"type": "object"
"type": "object",
"additionalProperties": true
},
"api.File": {
"type": "object",
Expand Down Expand Up @@ -6388,7 +6390,8 @@
}
},
"api.Import": {
"type": "object"
"type": "object",
"additionalProperties": true
},
"api.ImportSummary": {
"type": "object",
Expand Down Expand Up @@ -7812,5 +7815,6 @@
}
}
}
}
},
"x-original-swagger-version": "2.0"
}
4 changes: 2 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
},
"/analyses/dependencies": {
"get": {
"description": "Each report collates dependencies by name and SHA.\nfilters:\n- provider\n- name\n- version\n- sha\n- indirect\n- labels\n- application.id\n- application.name\n- businessService.id\n- businessService.name\n- tag.id\nsort:\n- provider\n- name\n- version\n- sha",
"description": "Each report collates dependencies by name and SHA.\nfilters:\n- provider\n- name\n- version\n- sha\n- indirect\n- labels\n- application.id\n- application.name\n- businessService.id\n- businessService.name\n- tag.id\nsort:\n- provider\n- name\n- labels",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -5840,7 +5840,7 @@
"provider": {
"type": "string"
},
"rule": {
"sha": {
"type": "string"
},
"version": {
Expand Down
5 changes: 2 additions & 3 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ definitions:
type: string
provider:
type: string
rule:
sha:
type: string
version:
type: string
Expand Down Expand Up @@ -1431,8 +1431,7 @@ paths:
sort:
- provider
- name
- version
- sha
- labels
produces:
- application/json
responses:
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
Loading