From 5b9531f1bceb7668889f60d234e9b34c94425aca Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Fri, 22 Mar 2024 10:34:41 +0200 Subject: app/categories: add bugs & security tabs Signed-off-by: Arthur Zamarin --- pkg/app/handler/categories/feeds.go | 4 +- pkg/app/handler/categories/show.go | 61 ++++++++++++++++++++-- pkg/app/handler/categories/show.templ | 12 +++++ pkg/app/handler/maintainer/show.go | 6 +-- pkg/app/handler/maintainer/utils.go | 21 -------- pkg/app/handler/packages/components/bugs.templ | 6 +-- .../packages/components/stabilization.templ | 4 +- pkg/app/handler/packages/show.templ | 4 +- pkg/app/serve.go | 2 + pkg/app/utils/bugs.go | 21 ++++++++ 10 files changed, 104 insertions(+), 37 deletions(-) delete mode 100644 pkg/app/handler/maintainer/utils.go create mode 100644 pkg/app/utils/bugs.go diff --git a/pkg/app/handler/categories/feeds.go b/pkg/app/handler/categories/feeds.go index 2afdf13..0ccfdeb 100644 --- a/pkg/app/handler/categories/feeds.go +++ b/pkg/app/handler/categories/feeds.go @@ -11,7 +11,7 @@ func OutdatedFeed(w http.ResponseWriter, r *http.Request) { categoryName := r.PathValue("category") var outdated []models.OutdatedPackages err := database.DBCon.Model(&outdated). - Where("SPLIT_PART(atom, '/', 1) = ?", categoryName). + Where("atom LIKE ?", categoryName+"/%"). Order("atom"). Select() if err != nil { @@ -27,7 +27,7 @@ func StabilizationFeed(w http.ResponseWriter, r *http.Request) { err := database.DBCon.Model(&results). Column("atom", "cpv", "message"). Where("class = ?", "StableRequest"). - Where("SPLIT_PART(atom, '/', 1) = ?", categoryName). + Where("atom LIKE ?", categoryName+"/%"). OrderExpr("cpv"). Select() if err != nil { diff --git a/pkg/app/handler/categories/show.go b/pkg/app/handler/categories/show.go index c116119..5e9151b 100644 --- a/pkg/app/handler/categories/show.go +++ b/pkg/app/handler/categories/show.go @@ -75,7 +75,7 @@ func ShowOutdated(w http.ResponseWriter, r *http.Request) { Limit(1) err = database.DBCon.Model((*models.OutdatedPackages)(nil)). Column("atom").ColumnExpr("(?) AS description", descriptionQuery). - Where("SPLIT_PART(atom, '/', 1) = ?", categoryName). + Where("atom LIKE ?", categoryName+"/%"). Order("atom"). Select(&outdated) if err != nil { @@ -107,6 +107,59 @@ func ShowPullRequests(w http.ResponseWriter, r *http.Request) { components.PullRequests(pullRequests)) } +func ShowBugs(w http.ResponseWriter, r *http.Request) { + categoryName, category, err := common(w, r) + if err != nil { + return + } + var bugs []*models.Bug + err = database.DBCon.Model(&bugs). + DistinctOn("id::INT"). + Column("id", "summary", "component", "assignee"). + OrderExpr("id::INT"). + Where("id IN (?)", + database.DBCon.Model((*models.PackageToBug)(nil)). + Column("bug_id"). + Where("package_atom LIKE ?", categoryName+"/%")). + WhereOr("id IN (?)", + database.DBCon.Model((*models.VersionToBug)(nil)). + Column("bug_id"). + Join("JOIN versions").JoinOn("version_id = versions.id"). + Where("versions.atom LIKE ?", categoryName+"/%")). + Select() + if err != nil { + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + generalCount, stabilizationCount, keywordingCount := utils.CountBugsCategories(bugs) + renderShowPage(w, r, "Bugs", &category, + components.Bugs("", generalCount, stabilizationCount, keywordingCount, bugs)) +} + +func ShowSecurity(w http.ResponseWriter, r *http.Request) { + categoryName, category, err := common(w, r) + if err != nil { + return + } + var bugs []*models.Bug + err = database.DBCon.Model(&bugs). + DistinctOn("id::INT"). + Column("id", "summary", "component", "assignee"). + OrderExpr("id::INT"). + Where("component = ?", "Vulnerabilities"). + Where("id IN (?)", + database.DBCon.Model((*models.PackageToBug)(nil)). + Column("bug_id"). + Where("package_atom LIKE ?", categoryName+"/%")). + Select() + if err != nil { + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + renderShowPage(w, r, "Security", &category, + components.SecurityBugs("", bugs)) +} + func ShowStabilizations(w http.ResponseWriter, r *http.Request) { categoryName, category, err := common(w, r) if err != nil { @@ -117,7 +170,7 @@ func ShowStabilizations(w http.ResponseWriter, r *http.Request) { err = database.DBCon.Model(&results). Column("atom", "cpv", "message"). Where("class = ?", "StableRequest"). - Where("SPLIT_PART(atom, '/', 1) = ?", categoryName). + Where("atom LIKE ?", categoryName+"/%"). OrderExpr("cpv"). Select() if err != nil { @@ -125,7 +178,7 @@ func ShowStabilizations(w http.ResponseWriter, r *http.Request) { return } renderShowPage(w, r, "Stabilization", &category, - components.Stabilizations(category.PackagesInformation.StableRequests > 0, results)) + components.Stabilizations(results)) } func ShowStabilizationFile(w http.ResponseWriter, r *http.Request) { @@ -134,7 +187,7 @@ func ShowStabilizationFile(w http.ResponseWriter, r *http.Request) { err := database.DBCon.Model(&results). Column("category", "package", "version", "message"). Where("class = ?", "StableRequest"). - Where("SPLIT_PART(atom, '/', 1) = ?", categoryName). + Where("atom LIKE ?", categoryName+"/%"). OrderExpr("cpv"). Select() if err != nil { diff --git a/pkg/app/handler/categories/show.templ b/pkg/app/handler/categories/show.templ index 0cfade3..cf80fb6 100644 --- a/pkg/app/handler/categories/show.templ +++ b/pkg/app/handler/categories/show.templ @@ -96,5 +96,17 @@ func renderShowPage(w http.ResponseWriter, r *http.Request, currentTab string, c Icon: "octicon octicon-git-pull-request opticon-resource-icon ml-1", BadgeValue: strconv.Itoa(category.PackagesInformation.PullRequests), }, + { + Name: "Bugs", + Link: templ.URL("/categories/" + category.Name + "/bugs"), + Icon: "fa fa-bug", + BadgeValue: strconv.Itoa(category.PackagesInformation.Bugs), + }, + { + Name: "Security", + Link: templ.URL("/categories/" + category.Name + "/security"), + Icon: "fa fa-shield", + BadgeValue: strconv.Itoa(category.PackagesInformation.SecurityBugs), + }, }, currentTab, show(component)).Render(r.Context(), w) } diff --git a/pkg/app/handler/maintainer/show.go b/pkg/app/handler/maintainer/show.go index 3f30b38..3975348 100644 --- a/pkg/app/handler/maintainer/show.go +++ b/pkg/app/handler/maintainer/show.go @@ -193,7 +193,7 @@ func ShowStabilization(w http.ResponseWriter, r *http.Request) { return } layout.Layout(maintainer.Name, "maintainers", - show(packagesCount, &maintainer, "Stabilization", components.Stabilizations(len(results) > 0, results)), + show(packagesCount, &maintainer, "Stabilization", components.Stabilizations(results)), ).Render(r.Context(), w) } @@ -222,7 +222,7 @@ func ShowBugs(w http.ResponseWriter, r *http.Request) { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } - generalCount, stabilizationCount, keywordingCount := countBugsCategories(bugs) + generalCount, stabilizationCount, keywordingCount := utils.CountBugsCategories(bugs) layout.Layout(maintainer.Name, "maintainers", show(packagesCount, &maintainer, "Bugs", components.Bugs("", generalCount, stabilizationCount, keywordingCount, bugs)), ).Render(r.Context(), w) @@ -250,7 +250,7 @@ func ShowSecurity(w http.ResponseWriter, r *http.Request) { return } layout.Layout(maintainer.Name, "maintainers", - show(packagesCount, &maintainer, "Security", components.SecurityBugs("", len(bugs) > 0, bugs)), + show(packagesCount, &maintainer, "Security", components.SecurityBugs("", bugs)), ).Render(r.Context(), w) } diff --git a/pkg/app/handler/maintainer/utils.go b/pkg/app/handler/maintainer/utils.go deleted file mode 100644 index 23532fb..0000000 --- a/pkg/app/handler/maintainer/utils.go +++ /dev/null @@ -1,21 +0,0 @@ -package maintainer - -import ( - "soko/pkg/models" -) - -func countBugsCategories(bugs []*models.Bug) (generalCount, stabilizationCount, keywordingCount int) { - for _, bug := range bugs { - switch bug.Component { - case "Current packages": - generalCount++ - case "Stabilization": - stabilizationCount++ - case "Keywording": - keywordingCount++ - default: - continue - } - } - return -} diff --git a/pkg/app/handler/packages/components/bugs.templ b/pkg/app/handler/packages/components/bugs.templ index 7c5a9e1..ee49df2 100644 --- a/pkg/app/handler/packages/components/bugs.templ +++ b/pkg/app/handler/packages/components/bugs.templ @@ -114,15 +114,15 @@ templ Bugs(atom string, generalCount, stabilizationCount, keywordingCount int, b func securityBugAtomLink(atom string) templ.SafeURL { if atom == "" { - return templ.URL("https://bugs.gentoo.org/") + return templ.URL("https://bugs.gentoo.org/enter_bug.cgi?product=Gentoo Security&component=Vulnerabilities") } return templ.URL("https://bugs.gentoo.org/enter_bug.cgi?product=Gentoo Security&component=Vulnerabilities&short_desc=" + atom + ": ") } -templ SecurityBugs(atom string, hasSecurityBugs bool, bugs []*models.Bug) { +templ SecurityBugs(atom string, bugs []*models.Bug) {
- if hasSecurityBugs { + if len(bugs) > 0 { @bugsList("Security Bug Reports", "Vulnerabilities", bugs, "mb-4", "security") } else {
diff --git a/pkg/app/handler/packages/components/stabilization.templ b/pkg/app/handler/packages/components/stabilization.templ index ac22d74..1bdd1c2 100644 --- a/pkg/app/handler/packages/components/stabilization.templ +++ b/pkg/app/handler/packages/components/stabilization.templ @@ -2,7 +2,7 @@ package components import "soko/pkg/models" -templ Stabilizations(hasStabilizations bool, results []*models.PkgCheckResult) { +templ Stabilizations(results []*models.PkgCheckResult) {
@@ -22,7 +22,7 @@ templ Stabilizations(hasStabilizations bool, results []*models.PkgCheckResult) { - if hasStabilizations { + if len(results) > 0 {
    for _, res := range results {
  • diff --git a/pkg/app/handler/packages/show.templ b/pkg/app/handler/packages/show.templ index 515e57a..fa3b33f 100644 --- a/pkg/app/handler/packages/show.templ +++ b/pkg/app/handler/packages/show.templ @@ -122,14 +122,14 @@ func collectAllBugs(pkg *models.Package) (atom string, generalCount, stabilizati return } -func collectSecurityBugs(pkg *models.Package) (string, bool, []*models.Bug) { +func collectSecurityBugs(pkg *models.Package) (string, []*models.Bug) { bugs := make([]*models.Bug, 0, len(pkg.Bugs)) for _, bug := range pkg.Bugs { if bug.Component == "Vulnerabilities" { bugs = append(bugs, bug) } } - return pkg.Atom, len(bugs) > 0, bugs + return pkg.Atom, bugs } templ show(pkg *models.Package, currentSubTab string, userPreferences models.UserPreferences) { diff --git a/pkg/app/serve.go b/pkg/app/serve.go index 6a6bf9a..61eccb1 100644 --- a/pkg/app/serve.go +++ b/pkg/app/serve.go @@ -33,9 +33,11 @@ func Serve() { setRoute("GET /categories", categories.Index) setRoute("GET /categories.json", categories.JSONCategories) setRoute("GET /categories/{category}", categories.ShowPackages) + setRoute("GET /categories/{category}/bugs", categories.ShowBugs) setRoute("GET /categories/{category}/outdated", categories.ShowOutdated) setRoute("GET /categories/{category}/outdated.atom", categories.OutdatedFeed) setRoute("GET /categories/{category}/pull-requests", categories.ShowPullRequests) + setRoute("GET /categories/{category}/security", categories.ShowSecurity) setRoute("GET /categories/{category}/stabilization", categories.ShowStabilizations) setRoute("GET /categories/{category}/stabilization.atom", categories.StabilizationFeed) setRoute("GET /categories/{category}/stabilization.json", categories.ShowStabilizationFile) diff --git a/pkg/app/utils/bugs.go b/pkg/app/utils/bugs.go new file mode 100644 index 0000000..d840541 --- /dev/null +++ b/pkg/app/utils/bugs.go @@ -0,0 +1,21 @@ +package utils + +import ( + "soko/pkg/models" +) + +func CountBugsCategories(bugs []*models.Bug) (generalCount, stabilizationCount, keywordingCount int) { + for _, bug := range bugs { + switch bug.Component { + case "Current packages": + generalCount++ + case "Stabilization": + stabilizationCount++ + case "Keywording": + keywordingCount++ + default: + continue + } + } + return +} -- cgit v1.2.3-65-gdbad