|
|
@ -5,10 +5,8 @@ |
|
|
|
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" |
|
|
@ -67,35 +65,7 @@ func Releases(ctx *context.Context) { |
|
|
|
limit = 10 |
|
|
|
limit = 10 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rawTags, err := ctx.Repo.GitRepo.GetTagInfos(git.TagOption{}) |
|
|
|
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, page, limit) |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "GetTags", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(rawTags) == 0 { |
|
|
|
|
|
|
|
ctx.HTML(200, tplReleases) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(rawTags) <= (page-1)*limit { |
|
|
|
|
|
|
|
ctx.Handle(500, "Releases", errors.New("no more pages")) |
|
|
|
|
|
|
|
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.GetReleasesByRepoIDAndNames(ctx.Repo.Repository.ID, tagNames) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "GetReleasesByRepoIDAndNames", err) |
|
|
|
ctx.Handle(500, "GetReleasesByRepoIDAndNames", err) |
|
|
|
return |
|
|
|
return |
|
|
@ -107,61 +77,39 @@ func Releases(ctx *context.Context) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Temproray cache commits count of used branches to speed up.
|
|
|
|
// Temporary 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) |
|
|
|
cacheUsers := map[int64]*models.User{ctx.User.ID: ctx.User} |
|
|
|
var ok bool |
|
|
|
var ok bool |
|
|
|
releaseTags := make([]*models.Release, len(tags)) |
|
|
|
|
|
|
|
for i, rawTag := range tags { |
|
|
|
|
|
|
|
for _, r := range releases { |
|
|
|
|
|
|
|
if r.IsDraft && !ctx.Repo.IsOwner() { |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if r.TagName == rawTag.Name { |
|
|
|
|
|
|
|
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 { |
|
|
|
releasesToDisplay := make([]*models.Release, 0, len(releases)) |
|
|
|
ctx.Handle(500, "calReleaseNumCommitsBehind", err) |
|
|
|
for _, r := range releases { |
|
|
|
|
|
|
|
if r.IsDraft && !ctx.Repo.IsOwner() { |
|
|
|
|
|
|
|
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 |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()) |
|
|
|
|
|
|
|
releaseTags[i] = r |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
cacheUsers[r.PublisherID] = r.Publisher |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil { |
|
|
|
if releaseTags[i] == nil { |
|
|
|
ctx.Handle(500, "calReleaseNumCommitsBehind", err) |
|
|
|
releaseTags[i] = &models.Release{ |
|
|
|
return |
|
|
|
Title: rawTag.Name, |
|
|
|
|
|
|
|
TagName: rawTag.Name, |
|
|
|
|
|
|
|
Sha1: rawTag.Object.String(), |
|
|
|
|
|
|
|
Note: rawTag.Message, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
releaseTags[i].NumCommits, err = git.CommitsCount(ctx.Repo.GitRepo.Path, rawTag.Object.String()) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "CommitsCount", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
releaseTags[i].NumCommitsBehind = ctx.Repo.CommitsCount - releaseTags[i].NumCommits |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()) |
|
|
|
|
|
|
|
releasesToDisplay = append(releasesToDisplay, r) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pager := paginater.New(len(rawTags), limit, page, 5) |
|
|
|
pager := paginater.New(len(releases), limit, page, 5) |
|
|
|
ctx.Data["Page"] = pager |
|
|
|
ctx.Data["Page"] = pager |
|
|
|
ctx.Data["Releases"] = releaseTags |
|
|
|
ctx.Data["Releases"] = releasesToDisplay |
|
|
|
ctx.HTML(200, tplReleases) |
|
|
|
ctx.HTML(200, tplReleases) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|