aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorJohn Olheiser <john.olheiser@gmail.com>2020-04-18 09:47:15 -0500
committerGitHub <noreply@github.com>2020-04-18 11:47:15 -0300
commit4f597b1866954ff94999a52af1a41fed06f0143e (patch)
tree0f260a237d33e55b259bb5cf5671c67135799d79 /routers
parent1b86f174ce99b579df35c32e800551b1fd1df807 (diff)
downloadgitea-4f597b1866954ff94999a52af1a41fed06f0143e.tar.gz
gitea-4f597b1866954ff94999a52af1a41fed06f0143e.zip
Add single release page and latest redirect (#11102)
* Add single release and latest release routes Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update API and move latest search to models Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/release.go59
-rw-r--r--routers/routes/routes.go4
2 files changed, 62 insertions, 1 deletions
diff --git a/routers/repo/release.go b/routers/repo/release.go
index 5454195181..1eac3dce97 100644
--- a/routers/repo/release.go
+++ b/routers/repo/release.go
@@ -131,6 +131,65 @@ func Releases(ctx *context.Context) {
ctx.HTML(200, tplReleases)
}
+// SingleRelease renders a single release's page
+func SingleRelease(ctx *context.Context) {
+ ctx.Data["Title"] = ctx.Tr("repo.release.releases")
+ ctx.Data["PageIsReleaseList"] = true
+
+ writeAccess := ctx.Repo.CanWrite(models.UnitTypeReleases)
+ ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived
+
+ release, err := models.GetRelease(ctx.Repo.Repository.ID, ctx.Params("tag"))
+ if err != nil {
+ ctx.ServerError("GetReleasesByRepoID", err)
+ return
+ }
+
+ err = models.GetReleaseAttachments(release)
+ if err != nil {
+ ctx.ServerError("GetReleaseAttachments", err)
+ return
+ }
+
+ release.Publisher, err = models.GetUserByID(release.PublisherID)
+ if err != nil {
+ if models.IsErrUserNotExist(err) {
+ release.Publisher = models.NewGhostUser()
+ } else {
+ ctx.ServerError("GetUserByID", err)
+ return
+ }
+ }
+ if err := calReleaseNumCommitsBehind(ctx.Repo, release, make(map[string]int64)); err != nil {
+ ctx.ServerError("calReleaseNumCommitsBehind", err)
+ return
+ }
+ release.Note = markdown.RenderString(release.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
+
+ ctx.Data["Releases"] = []*models.Release{release}
+ ctx.HTML(200, tplReleases)
+}
+
+// LatestRelease redirects to the latest release
+func LatestRelease(ctx *context.Context) {
+ release, err := models.GetLatestReleaseByRepoID(ctx.Repo.Repository.ID)
+ if err != nil {
+ if models.IsErrReleaseNotExist(err) {
+ ctx.NotFound("LatestRelease", err)
+ return
+ }
+ ctx.ServerError("GetLatestReleaseByRepoID", err)
+ return
+ }
+
+ if err := release.LoadAttributes(); err != nil {
+ ctx.ServerError("LoadAttributes", err)
+ return
+ }
+
+ ctx.Redirect(release.HTMLURL())
+}
+
// NewRelease render creating release page
func NewRelease(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
diff --git a/routers/routes/routes.go b/routers/routes/routes.go
index e2514054bf..a7828885bf 100644
--- a/routers/routes/routes.go
+++ b/routers/routes/routes.go
@@ -805,7 +805,9 @@ func RegisterRoutes(m *macaron.Macaron) {
// Releases
m.Group("/:username/:reponame", func() {
m.Group("/releases", func() {
- m.Get("/", repo.MustBeNotEmpty, repo.Releases)
+ m.Get("/", repo.Releases)
+ m.Get("/tag/:tag", repo.SingleRelease)
+ m.Get("/latest", repo.LatestRelease)
}, repo.MustBeNotEmpty, context.RepoRef())
m.Group("/releases", func() {
m.Get("/new", repo.NewRelease)