|
|
@ -5,8 +5,10 @@
|
|
|
|
package repo
|
|
|
|
package repo
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/git"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/auth"
|
|
|
|
"code.gitea.io/gitea/modules/auth"
|
|
|
|
"code.gitea.io/gitea/modules/base"
|
|
|
|
"code.gitea.io/gitea/modules/base"
|
|
|
@ -54,34 +56,55 @@ func Releases(ctx *context.Context) {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
|
|
|
|
ctx.Data["PageIsReleaseList"] = true
|
|
|
|
ctx.Data["PageIsReleaseList"] = true
|
|
|
|
|
|
|
|
|
|
|
|
rawTags, err := ctx.Repo.GitRepo.GetTags()
|
|
|
|
page := ctx.QueryInt("page")
|
|
|
|
|
|
|
|
if page <= 1 {
|
|
|
|
|
|
|
|
page = 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
limit := ctx.QueryInt("limit")
|
|
|
|
|
|
|
|
if limit <= 0 {
|
|
|
|
|
|
|
|
limit = 10
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rawTags, err := ctx.Repo.GitRepo.GetTagInfos(git.TagOption{})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "GetTags", err)
|
|
|
|
ctx.Handle(500, "GetTags", err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
page := ctx.QueryInt("page")
|
|
|
|
if len(rawTags) <= (page-1)*limit {
|
|
|
|
if page <= 1 {
|
|
|
|
ctx.Handle(500, "Releases", errors.New("no more pages"))
|
|
|
|
page = 1
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tags []*git.Tag
|
|
|
|
|
|
|
|
if page*limit > len(rawTags) {
|
|
|
|
|
|
|
|
tags = rawTags[(page-1)*limit:]
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
tags = rawTags[(page-1)*limit : page*limit]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tagNames []string
|
|
|
|
|
|
|
|
for _, t := range tags {
|
|
|
|
|
|
|
|
tagNames = append(tagNames, t.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, page, 10)
|
|
|
|
|
|
|
|
|
|
|
|
releases, err := models.GetReleasesByRepoIDAndNames(ctx.Repo.Repository.ID, tagNames)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "GetReleasesByRepoID", err)
|
|
|
|
ctx.Handle(500, "GetReleasesByRepoIDAndNames", err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Temproray cache commits count of used branches to speed up.
|
|
|
|
// Temproray cache commits count of used branches to speed up.
|
|
|
|
countCache := make(map[string]int64)
|
|
|
|
countCache := make(map[string]int64)
|
|
|
|
|
|
|
|
|
|
|
|
var cacheUsers = make(map[int64]*models.User)
|
|
|
|
var cacheUsers = make(map[int64]*models.User)
|
|
|
|
var ok bool
|
|
|
|
var ok bool
|
|
|
|
tags := make([]*models.Release, len(rawTags))
|
|
|
|
releaseTags := make([]*models.Release, len(tags))
|
|
|
|
for i, rawTag := range rawTags {
|
|
|
|
for i, rawTag := range tags {
|
|
|
|
for j, r := range releases {
|
|
|
|
for _, r := range releases {
|
|
|
|
if r == nil || (r.IsDraft && !ctx.Repo.IsOwner()) {
|
|
|
|
if r.IsDraft && !ctx.Repo.IsOwner() {
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if r.TagName == rawTag {
|
|
|
|
if r.TagName == rawTag.Name {
|
|
|
|
if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok {
|
|
|
|
if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok {
|
|
|
|
r.Publisher, err = models.GetUserByID(r.PublisherID)
|
|
|
|
r.Publisher, err = models.GetUserByID(r.PublisherID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -101,64 +124,31 @@ func Releases(ctx *context.Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
|
|
|
|
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
|
|
|
|
tags[i] = r
|
|
|
|
releaseTags[i] = r
|
|
|
|
releases[j] = nil // Mark as used.
|
|
|
|
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if tags[i] == nil {
|
|
|
|
if releaseTags[i] == nil {
|
|
|
|
commit, err := ctx.Repo.GitRepo.GetTagCommit(rawTag)
|
|
|
|
releaseTags[i] = &models.Release{
|
|
|
|
if err != nil {
|
|
|
|
Title: rawTag.Name,
|
|
|
|
ctx.Handle(500, "GetTagCommit", err)
|
|
|
|
TagName: rawTag.Name,
|
|
|
|
return
|
|
|
|
Sha1: rawTag.Object.String(),
|
|
|
|
}
|
|
|
|
Note: rawTag.Message,
|
|
|
|
|
|
|
|
|
|
|
|
tags[i] = &models.Release{
|
|
|
|
|
|
|
|
Title: rawTag,
|
|
|
|
|
|
|
|
TagName: rawTag,
|
|
|
|
|
|
|
|
Sha1: commit.ID.String(),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tags[i].NumCommits, err = commit.CommitsCount()
|
|
|
|
releaseTags[i].NumCommits, err = git.CommitsCount(ctx.Repo.GitRepo.Path, rawTag.Object.String())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "CommitsCount", err)
|
|
|
|
ctx.Handle(500, "CommitsCount", err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tags[i].NumCommitsBehind = ctx.Repo.CommitsCount - tags[i].NumCommits
|
|
|
|
releaseTags[i].NumCommitsBehind = ctx.Repo.CommitsCount - releaseTags[i].NumCommits
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, r := range releases {
|
|
|
|
pager := paginater.New(ctx.Repo.Repository.NumTags, limit, page, 5)
|
|
|
|
if r == nil {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok {
|
|
|
|
|
|
|
|
r.Publisher, err = models.GetUserByID(r.PublisherID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
if models.IsErrUserNotExist(err) {
|
|
|
|
|
|
|
|
r.Publisher = models.NewGhostUser()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ctx.Handle(500, "GetUserByID", err)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cacheUsers[r.PublisherID] = r.Publisher
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil {
|
|
|
|
|
|
|
|
ctx.Handle(500, "calReleaseNumCommitsBehind", err)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
|
|
|
|
|
|
|
|
tags = append(tags, r)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
pager := paginater.New(ctx.Repo.Repository.NumTags, 10, page, 5)
|
|
|
|
|
|
|
|
ctx.Data["Page"] = pager
|
|
|
|
ctx.Data["Page"] = pager
|
|
|
|
models.SortReleases(tags)
|
|
|
|
ctx.Data["Releases"] = releaseTags
|
|
|
|
ctx.Data["Releases"] = tags
|
|
|
|
|
|
|
|
ctx.HTML(200, tplReleases)
|
|
|
|
ctx.HTML(200, tplReleases)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|