summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authora1012112796 <1012112796@qq.com>2020-11-03 07:10:22 +0800
committerGitHub <noreply@github.com>2020-11-02 18:10:22 -0500
commitb687707014b31d0f388d1dfb60c09b5dcd48fc4c (patch)
tree7117d987d3da271528540e6f39ad5d1dfbe3a45a /routers
parentbcb94ed5898ac1b2191ebd5e1ff9c5b53ff323f8 (diff)
downloadgitea-b687707014b31d0f388d1dfb60c09b5dcd48fc4c.tar.gz
gitea-b687707014b31d0f388d1dfb60c09b5dcd48fc4c.zip
Add the tag list page to the release page (#12096)
* Add the tag list page to the release page * Add the tags list view * Add the delete tag way on ui * Not delete tag and clear message when delete a release Signed-off-by: a1012112796 <1012112796@qq.com> * Apply suggestions from code review Co-authored-by: Cirno the Strongest <1447794+CirnoT@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> * fix ui * Add to header * ui * permission * ui * Update options/locale/locale_en-US.ini Co-authored-by: Lauris BH <lauris@nix.lv> * tweaks * monospace commit hashes * Add read permission check * fix permission * fix nit * Update web_src/less/_base.less Co-authored-by: silverwind <me@silverwind.io> * ui fixes * title tweaks * fix lint * fix test * fix test and some ui nits * Apply suggestions from code review Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Cirno the Strongest <1447794+CirnoT@users.noreply.github.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/release.go62
-rw-r--r--routers/routes/routes.go6
2 files changed, 61 insertions, 7 deletions
diff --git a/routers/repo/release.go b/routers/repo/release.go
index 73c42ec7c4..4d75c37c87 100644
--- a/routers/repo/release.go
+++ b/routers/repo/release.go
@@ -55,10 +55,26 @@ func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *models.Rel
// Releases render releases list page
func Releases(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Tr("repo.release.releases")
+ releasesOrTags(ctx, false)
+}
+
+// TagsList render tags list page
+func TagsList(ctx *context.Context) {
+ releasesOrTags(ctx, true)
+}
+
+func releasesOrTags(ctx *context.Context, isTagList bool) {
ctx.Data["PageIsReleaseList"] = true
ctx.Data["DefaultBranch"] = ctx.Repo.Repository.DefaultBranch
+ if isTagList {
+ ctx.Data["Title"] = ctx.Tr("repo.release.tags")
+ ctx.Data["PageIsTagList"] = true
+ } else {
+ ctx.Data["Title"] = ctx.Tr("repo.release.releases")
+ ctx.Data["PageIsTagList"] = false
+ }
+
writeAccess := ctx.Repo.CanWrite(models.UnitTypeReleases)
ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived
@@ -68,7 +84,7 @@ func Releases(ctx *context.Context) {
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
},
IncludeDrafts: writeAccess,
- IncludeTags: true,
+ IncludeTags: isTagList,
}
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)
@@ -83,8 +99,7 @@ func Releases(ctx *context.Context) {
return
}
- err = models.GetReleaseAttachments(releases...)
- if err != nil {
+ if err = models.GetReleaseAttachments(releases...); err != nil {
ctx.ServerError("GetReleaseAttachments", err)
return
}
@@ -118,6 +133,7 @@ func Releases(ctx *context.Context) {
}
ctx.Data["Releases"] = releases
+ ctx.Data["ReleasesNum"] = len(releases)
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
pager.SetDefaultParams(ctx)
@@ -194,6 +210,20 @@ func NewRelease(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
ctx.Data["PageIsReleaseList"] = true
ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
+ if tagName := ctx.Query("tag"); len(tagName) > 0 {
+ rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName)
+ if err != nil && !models.IsErrReleaseNotExist(err) {
+ ctx.ServerError("GetRelease", err)
+ return
+ }
+
+ if rel != nil {
+ ctx.Data["tag_name"] = rel.TagName
+ ctx.Data["tag_target"] = rel.Target
+ ctx.Data["title"] = rel.Title
+ ctx.Data["content"] = rel.Note
+ }
+ }
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
upload.AddUploadContext(ctx, "release")
ctx.HTML(200, tplReleaseNew)
@@ -354,10 +384,30 @@ func EditReleasePost(ctx *context.Context, form auth.EditReleaseForm) {
// DeleteRelease delete a release
func DeleteRelease(ctx *context.Context) {
- if err := releaseservice.DeleteReleaseByID(ctx.QueryInt64("id"), ctx.User, true); err != nil {
+ deleteReleaseOrTag(ctx, false)
+}
+
+// DeleteTag delete a tag
+func DeleteTag(ctx *context.Context) {
+ deleteReleaseOrTag(ctx, true)
+}
+
+func deleteReleaseOrTag(ctx *context.Context, isDelTag bool) {
+ if err := releaseservice.DeleteReleaseByID(ctx.QueryInt64("id"), ctx.User, isDelTag); err != nil {
ctx.Flash.Error("DeleteReleaseByID: " + err.Error())
} else {
- ctx.Flash.Success(ctx.Tr("repo.release.deletion_success"))
+ if isDelTag {
+ ctx.Flash.Success(ctx.Tr("repo.release.deletion_tag_success"))
+ } else {
+ ctx.Flash.Success(ctx.Tr("repo.release.deletion_success"))
+ }
+ }
+
+ if isDelTag {
+ ctx.JSON(200, map[string]interface{}{
+ "redirect": ctx.Repo.RepoLink + "/tags",
+ })
+ return
}
ctx.JSON(200, map[string]interface{}{
diff --git a/routers/routes/routes.go b/routers/routes/routes.go
index f123613b1f..eafdbe4e49 100644
--- a/routers/routes/routes.go
+++ b/routers/routes/routes.go
@@ -896,12 +896,14 @@ func RegisterRoutes(m *macaron.Macaron) {
// Releases
m.Group("/:username/:reponame", func() {
+ m.Get("/tags", repo.TagsList, repo.MustBeNotEmpty,
+ reqRepoCodeReader, context.RepoRefByType(context.RepoRefTag))
m.Group("/releases", func() {
m.Get("/", repo.Releases)
m.Get("/tag/*", repo.SingleRelease)
m.Get("/latest", repo.LatestRelease)
m.Get("/attachments/:uuid", repo.GetAttachment)
- }, repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefTag))
+ }, repo.MustBeNotEmpty, reqRepoReleaseReader, context.RepoRefByType(context.RepoRefTag))
m.Group("/releases", func() {
m.Get("/new", repo.NewRelease)
m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
@@ -909,6 +911,8 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/attachments", repo.UploadReleaseAttachment)
m.Post("/attachments/remove", repo.DeleteAttachment)
}, reqSignIn, repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoReleaseWriter, context.RepoRef())
+ m.Post("/tags/delete", repo.DeleteTag, reqSignIn,
+ repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, context.RepoRef())
m.Group("/releases", func() {
m.Get("/edit/*", repo.EditRelease)
m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)