aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2024-03-22 10:34:41 +0200
committerArthur Zamarin <arthurzam@gentoo.org>2024-03-22 10:37:01 +0200
commit5b9531f1bceb7668889f60d234e9b34c94425aca (patch)
treebe83b9e19cac871570b4a48cbf3482e672675b51
parentpull-requests: simplify component (diff)
downloadsoko-5b9531f1bceb7668889f60d234e9b34c94425aca.tar.gz
soko-5b9531f1bceb7668889f60d234e9b34c94425aca.tar.bz2
soko-5b9531f1bceb7668889f60d234e9b34c94425aca.zip
app/categories: add bugs & security tabs
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r--pkg/app/handler/categories/feeds.go4
-rw-r--r--pkg/app/handler/categories/show.go61
-rw-r--r--pkg/app/handler/categories/show.templ12
-rw-r--r--pkg/app/handler/maintainer/show.go6
-rw-r--r--pkg/app/handler/packages/components/bugs.templ6
-rw-r--r--pkg/app/handler/packages/components/stabilization.templ4
-rw-r--r--pkg/app/handler/packages/show.templ4
-rw-r--r--pkg/app/serve.go2
-rw-r--r--pkg/app/utils/bugs.go (renamed from pkg/app/handler/maintainer/utils.go)4
9 files changed, 85 insertions, 18 deletions
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/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 + ": <ADD SUMMARY HERE>")
}
-templ SecurityBugs(atom string, hasSecurityBugs bool, bugs []*models.Bug) {
+templ SecurityBugs(atom string, bugs []*models.Bug) {
<div class="row">
<div class="col-md-9">
- if hasSecurityBugs {
+ if len(bugs) > 0 {
@bugsList("Security Bug Reports", "Vulnerabilities", bugs, "mb-4", "security")
} else {
<div class="row pt-5">
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) {
<div class="row">
<div class="col-md-9">
<span class="d-flex justify-content-between">
@@ -22,7 +22,7 @@ templ Stabilizations(hasStabilizations bool, results []*models.PkgCheckResult) {
</span>
</span>
</span>
- if hasStabilizations {
+ if len(results) > 0 {
<ul class="timeline">
for _, res := range results {
<li>
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/handler/maintainer/utils.go b/pkg/app/utils/bugs.go
index 23532fb..d840541 100644
--- a/pkg/app/handler/maintainer/utils.go
+++ b/pkg/app/utils/bugs.go
@@ -1,10 +1,10 @@
-package maintainer
+package utils
import (
"soko/pkg/models"
)
-func countBugsCategories(bugs []*models.Bug) (generalCount, stabilizationCount, keywordingCount int) {
+func CountBugsCategories(bugs []*models.Bug) (generalCount, stabilizationCount, keywordingCount int) {
for _, bug := range bugs {
switch bug.Component {
case "Current packages":