|
|
@ -12,6 +12,7 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/models/db" |
|
|
|
"code.gitea.io/gitea/models/db" |
|
|
|
|
|
|
|
git_model "code.gitea.io/gitea/models/git" |
|
|
|
repo_model "code.gitea.io/gitea/models/repo" |
|
|
|
repo_model "code.gitea.io/gitea/models/repo" |
|
|
|
"code.gitea.io/gitea/models/unit" |
|
|
|
"code.gitea.io/gitea/models/unit" |
|
|
|
user_model "code.gitea.io/gitea/models/user" |
|
|
|
user_model "code.gitea.io/gitea/models/user" |
|
|
@ -67,41 +68,16 @@ func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *repo_model |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Releases render releases list page
|
|
|
|
type ReleaseInfo struct { |
|
|
|
func Releases(ctx *context.Context) { |
|
|
|
Release *repo_model.Release |
|
|
|
ctx.Data["PageIsReleaseList"] = true |
|
|
|
CommitStatus *git_model.CommitStatus |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.release.releases") |
|
|
|
CommitStatuses []*git_model.CommitStatus |
|
|
|
ctx.Data["IsViewBranch"] = false |
|
|
|
} |
|
|
|
ctx.Data["IsViewTag"] = true |
|
|
|
|
|
|
|
// Disable the showCreateNewBranch form in the dropdown on this page.
|
|
|
|
|
|
|
|
ctx.Data["CanCreateBranch"] = false |
|
|
|
|
|
|
|
ctx.Data["HideBranchesInDropdown"] = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
listOptions := db.ListOptions{ |
|
|
|
|
|
|
|
Page: ctx.FormInt("page"), |
|
|
|
|
|
|
|
PageSize: ctx.FormInt("limit"), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if listOptions.PageSize == 0 { |
|
|
|
|
|
|
|
listOptions.PageSize = setting.Repository.Release.DefaultPagingNum |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if listOptions.PageSize > setting.API.MaxResponseItems { |
|
|
|
|
|
|
|
listOptions.PageSize = setting.API.MaxResponseItems |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
writeAccess := ctx.Repo.CanWrite(unit.TypeReleases) |
|
|
|
|
|
|
|
ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opts := repo_model.FindReleasesOptions{ |
|
|
|
|
|
|
|
ListOptions: listOptions, |
|
|
|
|
|
|
|
// only show draft releases for users who can write, read-only users shouldn't see draft releases.
|
|
|
|
|
|
|
|
IncludeDrafts: writeAccess, |
|
|
|
|
|
|
|
RepoID: ctx.Repo.Repository.ID, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func getReleaseInfos(ctx *context.Context, opts *repo_model.FindReleasesOptions) ([]*ReleaseInfo, error) { |
|
|
|
releases, err := db.Find[repo_model.Release](ctx, opts) |
|
|
|
releases, err := db.Find[repo_model.Release](ctx, opts) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("GetReleasesByRepoID", err) |
|
|
|
return nil, err |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, release := range releases { |
|
|
|
for _, release := range releases { |
|
|
@ -109,8 +85,7 @@ func Releases(ctx *context.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = repo_model.GetReleaseAttachments(ctx, releases...); err != nil { |
|
|
|
if err = repo_model.GetReleaseAttachments(ctx, releases...); err != nil { |
|
|
|
ctx.ServerError("GetReleaseAttachments", err) |
|
|
|
return nil, err |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Temporary cache commits count of used branches to speed up.
|
|
|
|
// Temporary cache commits count of used branches to speed up.
|
|
|
@ -121,6 +96,9 @@ func Releases(ctx *context.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
var ok bool |
|
|
|
var ok bool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
canReadActions := ctx.Repo.CanRead(unit.TypeActions) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
releaseInfos := make([]*ReleaseInfo, 0, len(releases)) |
|
|
|
for _, r := range releases { |
|
|
|
for _, r := range releases { |
|
|
|
if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok { |
|
|
|
if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok { |
|
|
|
r.Publisher, err = user_model.GetUserByID(ctx, r.PublisherID) |
|
|
|
r.Publisher, err = user_model.GetUserByID(ctx, r.PublisherID) |
|
|
@ -128,8 +106,7 @@ func Releases(ctx *context.Context) { |
|
|
|
if user_model.IsErrUserNotExist(err) { |
|
|
|
if user_model.IsErrUserNotExist(err) { |
|
|
|
r.Publisher = user_model.NewGhostUser() |
|
|
|
r.Publisher = user_model.NewGhostUser() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ctx.ServerError("GetUserByID", err) |
|
|
|
return nil, err |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
cacheUsers[r.PublisherID] = r.Publisher |
|
|
|
cacheUsers[r.PublisherID] = r.Publisher |
|
|
@ -144,24 +121,74 @@ func Releases(ctx *context.Context) { |
|
|
|
Ctx: ctx, |
|
|
|
Ctx: ctx, |
|
|
|
}, r.Note) |
|
|
|
}, r.Note) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("RenderString", err) |
|
|
|
return nil, err |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if r.IsDraft { |
|
|
|
if !r.IsDraft { |
|
|
|
continue |
|
|
|
if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil { |
|
|
|
info := &ReleaseInfo{ |
|
|
|
ctx.ServerError("calReleaseNumCommitsBehind", err) |
|
|
|
Release: r, |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if canReadActions { |
|
|
|
|
|
|
|
statuses, _, err := git_model.GetLatestCommitStatus(ctx, r.Repo.ID, r.Sha1, db.ListOptions{ListAll: true}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info.CommitStatus = git_model.CalcCommitStatus(statuses) |
|
|
|
|
|
|
|
info.CommitStatuses = statuses |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
releaseInfos = append(releaseInfos, info) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return releaseInfos, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Releases render releases list page
|
|
|
|
|
|
|
|
func Releases(ctx *context.Context) { |
|
|
|
|
|
|
|
ctx.Data["PageIsReleaseList"] = true |
|
|
|
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.release.releases") |
|
|
|
|
|
|
|
ctx.Data["IsViewBranch"] = false |
|
|
|
|
|
|
|
ctx.Data["IsViewTag"] = true |
|
|
|
|
|
|
|
// Disable the showCreateNewBranch form in the dropdown on this page.
|
|
|
|
|
|
|
|
ctx.Data["CanCreateBranch"] = false |
|
|
|
|
|
|
|
ctx.Data["HideBranchesInDropdown"] = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
listOptions := db.ListOptions{ |
|
|
|
|
|
|
|
Page: ctx.FormInt("page"), |
|
|
|
|
|
|
|
PageSize: ctx.FormInt("limit"), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if listOptions.PageSize == 0 { |
|
|
|
|
|
|
|
listOptions.PageSize = setting.Repository.Release.DefaultPagingNum |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if listOptions.PageSize > setting.API.MaxResponseItems { |
|
|
|
|
|
|
|
listOptions.PageSize = setting.API.MaxResponseItems |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
writeAccess := ctx.Repo.CanWrite(unit.TypeReleases) |
|
|
|
|
|
|
|
ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
releases, err := getReleaseInfos(ctx, &repo_model.FindReleasesOptions{ |
|
|
|
|
|
|
|
ListOptions: listOptions, |
|
|
|
|
|
|
|
// only show draft releases for users who can write, read-only users shouldn't see draft releases.
|
|
|
|
|
|
|
|
IncludeDrafts: writeAccess, |
|
|
|
|
|
|
|
RepoID: ctx.Repo.Repository.ID, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("getReleaseInfos", err) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["Releases"] = releases |
|
|
|
ctx.Data["Releases"] = releases |
|
|
|
|
|
|
|
|
|
|
|
numReleases := ctx.Data["NumReleases"].(int64) |
|
|
|
numReleases := ctx.Data["NumReleases"].(int64) |
|
|
|
pager := context.NewPagination(int(numReleases), opts.PageSize, opts.Page, 5) |
|
|
|
pager := context.NewPagination(int(numReleases), listOptions.PageSize, listOptions.Page, 5) |
|
|
|
pager.SetDefaultParams(ctx) |
|
|
|
pager.SetDefaultParams(ctx) |
|
|
|
ctx.Data["Page"] = pager |
|
|
|
ctx.Data["Page"] = pager |
|
|
|
|
|
|
|
|
|
|
@ -249,15 +276,24 @@ func SingleRelease(ctx *context.Context) { |
|
|
|
writeAccess := ctx.Repo.CanWrite(unit.TypeReleases) |
|
|
|
writeAccess := ctx.Repo.CanWrite(unit.TypeReleases) |
|
|
|
ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived |
|
|
|
ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived |
|
|
|
|
|
|
|
|
|
|
|
release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, ctx.Params("*")) |
|
|
|
releases, err := getReleaseInfos(ctx, &repo_model.FindReleasesOptions{ |
|
|
|
|
|
|
|
ListOptions: db.ListOptions{Page: 1, PageSize: 1}, |
|
|
|
|
|
|
|
RepoID: ctx.Repo.Repository.ID, |
|
|
|
|
|
|
|
TagNames: []string{ctx.Params("*")}, |
|
|
|
|
|
|
|
// only show draft releases for users who can write, read-only users shouldn't see draft releases.
|
|
|
|
|
|
|
|
IncludeDrafts: writeAccess, |
|
|
|
|
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
if repo_model.IsErrReleaseNotExist(err) { |
|
|
|
ctx.ServerError("getReleaseInfos", err) |
|
|
|
ctx.NotFound("GetRelease", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
if len(releases) != 1 { |
|
|
|
ctx.ServerError("GetReleasesByRepoID", err) |
|
|
|
ctx.NotFound("SingleRelease", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
release := releases[0].Release |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["PageIsSingleTag"] = release.IsTag |
|
|
|
ctx.Data["PageIsSingleTag"] = release.IsTag |
|
|
|
if release.IsTag { |
|
|
|
if release.IsTag { |
|
|
|
ctx.Data["Title"] = release.TagName |
|
|
|
ctx.Data["Title"] = release.TagName |
|
|
@ -265,43 +301,7 @@ func SingleRelease(ctx *context.Context) { |
|
|
|
ctx.Data["Title"] = release.Title |
|
|
|
ctx.Data["Title"] = release.Title |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
release.Repo = ctx.Repo.Repository |
|
|
|
ctx.Data["Releases"] = releases |
|
|
|
|
|
|
|
|
|
|
|
err = repo_model.GetReleaseAttachments(ctx, release) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("GetReleaseAttachments", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
release.Publisher, err = user_model.GetUserByID(ctx, release.PublisherID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
if user_model.IsErrUserNotExist(err) { |
|
|
|
|
|
|
|
release.Publisher = user_model.NewGhostUser() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ctx.ServerError("GetUserByID", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if !release.IsDraft { |
|
|
|
|
|
|
|
if err := calReleaseNumCommitsBehind(ctx.Repo, release, make(map[string]int64)); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("calReleaseNumCommitsBehind", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
release.Note, err = markdown.RenderString(&markup.RenderContext{ |
|
|
|
|
|
|
|
Links: markup.Links{ |
|
|
|
|
|
|
|
Base: ctx.Repo.RepoLink, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Metas: ctx.Repo.Repository.ComposeMetas(ctx), |
|
|
|
|
|
|
|
GitRepo: ctx.Repo.GitRepo, |
|
|
|
|
|
|
|
Ctx: ctx, |
|
|
|
|
|
|
|
}, release.Note) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("RenderString", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["Releases"] = []*repo_model.Release{release} |
|
|
|
|
|
|
|
ctx.HTML(http.StatusOK, tplReleasesList) |
|
|
|
ctx.HTML(http.StatusOK, tplReleasesList) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|