diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2024-03-19 11:52:39 +0200 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2024-03-19 16:43:03 +0200 |
commit | 170e62b4269781484ab8578eb266081310f813c2 (patch) | |
tree | da9cd097d76ab5e4b9220afdc1e860be8db55353 | |
parent | add GPL-2.0-only license (diff) | |
download | soko-170e62b4269781484ab8578eb266081310f813c2.tar.gz soko-170e62b4269781484ab8578eb266081310f813c2.tar.bz2 soko-170e62b4269781484ab8578eb266081310f813c2.zip |
app: add stabilization feed for maintainer and category
Resolves: https://github.com/gentoo/soko/issues/23
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | pkg/app/handler/categories/show.go | 14 | ||||
-rw-r--r-- | pkg/app/handler/maintainer/show.go | 20 | ||||
-rw-r--r-- | pkg/app/handler/packages/components/stabilization.templ | 4 | ||||
-rw-r--r-- | pkg/app/serve.go | 1 | ||||
-rw-r--r-- | pkg/app/utils/stabilization.go | 23 |
5 files changed, 62 insertions, 0 deletions
diff --git a/pkg/app/handler/categories/show.go b/pkg/app/handler/categories/show.go index 0f80b02..dcf3410 100644 --- a/pkg/app/handler/categories/show.go +++ b/pkg/app/handler/categories/show.go @@ -67,6 +67,20 @@ func Show(w http.ResponseWriter, r *http.Request) { } utils.StabilizationExport(w, pageUrl, category.Packages) return + case "stabilization.atom": + var results []*models.PkgCheckResult + err := database.DBCon.Model(&results). + Column("atom", "cpv", "message"). + Where("class = ?", "StableRequest"). + Where("SPLIT_PART(atom, '/', 1) = ?", categoryName). + OrderExpr("cpv"). + Select() + if err != nil { + http.NotFound(w, r) + return + } + utils.StabilizationFeed(w, "https://packages.gentoo.org/categories/"+categoryName+"/stabilization", "category "+categoryName, results) + return case "", "packages": query = query.Relation("Packages.Versions") default: diff --git a/pkg/app/handler/maintainer/show.go b/pkg/app/handler/maintainer/show.go index e41d8b2..ae9aa3e 100644 --- a/pkg/app/handler/maintainer/show.go +++ b/pkg/app/handler/maintainer/show.go @@ -257,6 +257,26 @@ func ShowStabilizationFile(w http.ResponseWriter, r *http.Request) { utils.StabilizationExport(w, pageName, gpackages) } +func ShowStabilizationFeed(w http.ResponseWriter, r *http.Request) { + maintainer, query, _, err := common(w, r) + if err != nil { + return + } + + var results []*models.PkgCheckResult + err = database.DBCon.Model(&results). + Column("atom", "cpv", "message"). + Where("class = ?", "StableRequest"). + Where("atom IN (?)", query). + OrderExpr("cpv"). + Select() + if err != nil { + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + utils.StabilizationFeed(w, "https://packages.gentoo.org/maintainer/"+maintainer.Email+"/stabilization", maintainer.Name+" <"+maintainer.Email+">", results) +} + func ShowPackages(w http.ResponseWriter, r *http.Request) { maintainer, query, packagesCount, err := common(w, r) if err != nil { diff --git a/pkg/app/handler/packages/components/stabilization.templ b/pkg/app/handler/packages/components/stabilization.templ index 858c785..ac22d74 100644 --- a/pkg/app/handler/packages/components/stabilization.templ +++ b/pkg/app/handler/packages/components/stabilization.templ @@ -8,6 +8,10 @@ templ Stabilizations(hasStabilizations bool, results []*models.PkgCheckResult) { <span class="d-flex justify-content-between"> <h3>Stable Requests</h3> <span> + <a href="./stabilization.atom"> + <span class="fa fa-fw fa-rss text-dark"></span> Atom feed + </a> + <button type="button" class="kk-btn-xs btn btn-outline-secondary" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <span class="fa fa-fw fa-download"></span> </button> diff --git a/pkg/app/serve.go b/pkg/app/serve.go index 1f5f25a..adf42be 100644 --- a/pkg/app/serve.go +++ b/pkg/app/serve.go @@ -75,6 +75,7 @@ func Serve() { setRoute("GET /maintainer/{email}/stabilization.json", maintainer.ShowStabilizationFile) setRoute("GET /maintainer/{email}/stabilization.list", maintainer.ShowStabilizationFile) setRoute("GET /maintainer/{email}/stabilization.xml", maintainer.ShowStabilizationFile) + setRoute("GET /maintainer/{email}/stabilization.atom", maintainer.ShowStabilizationFeed) setRoute("GET /packages/search", packages.Search) setRoute("GET /packages/suggest.json", packages.Suggest) diff --git a/pkg/app/utils/stabilization.go b/pkg/app/utils/stabilization.go index 4a2b4d6..4395294 100644 --- a/pkg/app/utils/stabilization.go +++ b/pkg/app/utils/stabilization.go @@ -6,6 +6,10 @@ import ( "net/http" "soko/pkg/models" "strings" + "time" + + "github.com/a-h/templ" + "github.com/gorilla/feeds" ) type stabilization struct { @@ -65,3 +69,22 @@ func StabilizationExport(w http.ResponseWriter, pageUrl string, gpackages []*mod w.Write([]byte(lines)) } } + +func StabilizationFeed(w http.ResponseWriter, link, title string, results []*models.PkgCheckResult) { + feed := &feeds.Feed{ + Title: "Stabilization candidates for " + title, + Author: &feeds.Author{Name: "Gentoo Packages Database"}, + Created: time.Now(), + Link: &feeds.Link{Href: link}, + } + + for _, pkgcheck := range results { + feed.Add(&feeds.Item{ + Title: pkgcheck.CPV, + Description: templ.EscapeString(pkgcheck.Message), + Link: &feeds.Link{Href: "https://packages.gentoo.org/packages/" + pkgcheck.Atom, Type: "text/html", Rel: "alternate"}, + Id: pkgcheck.CPV, + }) + } + feed.WriteAtom(w) +} |