From f82ccb36691c49fb1c2fb6b599fbf18bf800f679 Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Tue, 19 Mar 2024 16:44:44 +0200 Subject: app: add outdated feed for maintainer and category Resolves: https://github.com/gentoo/soko/issues/23 Signed-off-by: Arthur Zamarin --- pkg/app/handler/categories/show.go | 12 +++++++++ pkg/app/handler/maintainer/show.go | 17 +++++++++++++ .../handler/packages/components/changelog.templ | 2 +- pkg/app/handler/packages/components/outdated.templ | 9 ++++++- pkg/app/serve.go | 1 + pkg/app/utils/outdated.go | 29 ++++++++++++++++++++++ 6 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 pkg/app/utils/outdated.go diff --git a/pkg/app/handler/categories/show.go b/pkg/app/handler/categories/show.go index dcf3410..b48e37c 100644 --- a/pkg/app/handler/categories/show.go +++ b/pkg/app/handler/categories/show.go @@ -44,6 +44,18 @@ func Show(w http.ResponseWriter, r *http.Request) { pageName = "Outdated" query = query.Relation("Packages.Versions"). Relation("Packages.Outdated") + case "outdated.atom": + var outdated []models.OutdatedPackages + err := database.DBCon.Model(&outdated). + Where("SPLIT_PART(atom, '/', 1) = ?", categoryName). + Order("atom"). + Select() + if err != nil { + http.NotFound(w, r) + return + } + utils.OutdatedFeed(w, "https://packages.gentoo.org/categories/"+categoryName+"/outdated", "category "+categoryName, outdated) + return case "pull-requests": pageName = "Pull requests" err := database.DBCon.Model(&pullRequests). diff --git a/pkg/app/handler/maintainer/show.go b/pkg/app/handler/maintainer/show.go index ae9aa3e..981a5c6 100644 --- a/pkg/app/handler/maintainer/show.go +++ b/pkg/app/handler/maintainer/show.go @@ -138,6 +138,23 @@ func ShowOutdated(w http.ResponseWriter, r *http.Request) { ).Render(r.Context(), w) } +func ShowOutdatedFeed(w http.ResponseWriter, r *http.Request) { + maintainer, query, _, err := common(w, r) + if err != nil { + return + } + var outdated []models.OutdatedPackages + err = database.DBCon.Model(&outdated). + Where("atom IN (?)", query). + Order("atom"). + Select() + if err != nil { + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + utils.OutdatedFeed(w, "https://packages.gentoo.org/maintainer/"+maintainer.Email+"/outdated", maintainer.Name+" <"+maintainer.Email+">", outdated) +} + func ShowPullRequests(w http.ResponseWriter, r *http.Request) { maintainer, query, packagesCount, err := common(w, r) if err != nil { diff --git a/pkg/app/handler/packages/components/changelog.templ b/pkg/app/handler/packages/components/changelog.templ index a4854ae..9e86328 100644 --- a/pkg/app/handler/packages/components/changelog.templ +++ b/pkg/app/handler/packages/components/changelog.templ @@ -32,7 +32,7 @@ templ Changelog(atom string, commits []*models.Commit) { if atom != "" { href={ templ.URL("https://gitweb.gentoo.org/repo/gentoo.git/atom/" + atom + "?h=master") } } else { - href={ templ.URL("./changelog.atom") } + href="./changelog.atom" } target="_blank" > diff --git a/pkg/app/handler/packages/components/outdated.templ b/pkg/app/handler/packages/components/outdated.templ index 0888c5d..30a7ce1 100644 --- a/pkg/app/handler/packages/components/outdated.templ +++ b/pkg/app/handler/packages/components/outdated.templ @@ -9,7 +9,14 @@ templ Outdated(outdated []OutdatedItem) {
if len(outdated) > 0 { -

Outdated Packages

+ +

Outdated Packages

+ + + Atom feed + + +
    for _, pkg := range outdated {
  • diff --git a/pkg/app/serve.go b/pkg/app/serve.go index adf42be..d13cada 100644 --- a/pkg/app/serve.go +++ b/pkg/app/serve.go @@ -69,6 +69,7 @@ func Serve() { setRoute("GET /maintainer/{email}/changelog.atom", maintainer.ShowChangelogFeed) setRoute("GET /maintainer/{email}/info.json", maintainer.ShowInfoJson) setRoute("GET /maintainer/{email}/outdated", maintainer.ShowOutdated) + setRoute("GET /maintainer/{email}/outdated.atom", maintainer.ShowOutdatedFeed) setRoute("GET /maintainer/{email}/pull-requests", maintainer.ShowPullRequests) setRoute("GET /maintainer/{email}/security", maintainer.ShowSecurity) setRoute("GET /maintainer/{email}/stabilization", maintainer.ShowStabilization) diff --git a/pkg/app/utils/outdated.go b/pkg/app/utils/outdated.go new file mode 100644 index 0000000..317c82b --- /dev/null +++ b/pkg/app/utils/outdated.go @@ -0,0 +1,29 @@ +package utils + +import ( + "net/http" + "time" + + "github.com/gorilla/feeds" + + "soko/pkg/models" +) + +func OutdatedFeed(w http.ResponseWriter, link, title string, outdated []models.OutdatedPackages) { + feed := &feeds.Feed{ + Title: "Outdated Packages for " + title, + Author: &feeds.Author{Name: "Gentoo Packages Database"}, + Created: time.Now(), + Link: &feeds.Link{Href: link}, + } + + for _, entry := range outdated { + feed.Add(&feeds.Item{ + Id: entry.Atom, + Title: entry.Atom, + Description: "Version " + entry.NewestVersion + " is available, while the latest version in the Gentoo tree is " + entry.GentooVersion + ".", + Link: &feeds.Link{Href: "https://packages.gentoo.org/packages/" + entry.Atom, Type: "text/html", Rel: "alternate"}, + }) + } + feed.WriteAtom(w) +} -- cgit v1.2.3-65-gdbad