diff options
author | 2024-03-19 16:44:44 +0200 | |
---|---|---|
committer | 2024-03-19 16:44:44 +0200 | |
commit | f82ccb36691c49fb1c2fb6b599fbf18bf800f679 (patch) | |
tree | 012bc18fd9cc23969ec4d7a9b7975572e7863ea3 | |
parent | app: add stabilization feed for maintainer and category (diff) | |
download | soko-f82ccb36691c49fb1c2fb6b599fbf18bf800f679.tar.gz soko-f82ccb36691c49fb1c2fb6b599fbf18bf800f679.tar.bz2 soko-f82ccb36691c49fb1c2fb6b599fbf18bf800f679.zip |
app: add outdated 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 | 12 | ||||
-rw-r--r-- | pkg/app/handler/maintainer/show.go | 17 | ||||
-rw-r--r-- | pkg/app/handler/packages/components/changelog.templ | 2 | ||||
-rw-r--r-- | pkg/app/handler/packages/components/outdated.templ | 9 | ||||
-rw-r--r-- | pkg/app/serve.go | 1 | ||||
-rw-r--r-- | pkg/app/utils/outdated.go | 29 |
6 files changed, 68 insertions, 2 deletions
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) { <div class="row"> <div class="col-md-9"> if len(outdated) > 0 { - <h3 class="mb-4">Outdated Packages</h3> + <span class="d-flex justify-content-between"> + <h3 class="mb-4">Outdated Packages</h3> + <span> + <a href="./outdated.atom"> + <span class="fa fa-fw fa-rss text-dark"></span> Atom feed + </a> + </span> + </span> <ul class="list-group"> for _, pkg := range outdated { <li class="list-group-item"> 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) +} |