diff options
author | Unknwon <joe2010xtmf@163.com> | 2014-12-10 16:37:54 -0500 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2014-12-10 16:37:54 -0500 |
commit | bc8721fb6c704255fd8be9edc9372e4d17adaee9 (patch) | |
tree | 1bc335b23b84432799440bb7572942410ce00b33 /routers/repo | |
parent | 01ba7717838c01c719cca34d3fe446c547c9ada4 (diff) | |
download | gitea-bc8721fb6c704255fd8be9edc9372e4d17adaee9.tar.gz gitea-bc8721fb6c704255fd8be9edc9372e4d17adaee9.zip |
Finish new UI for release page
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/release.go | 92 |
1 files changed, 54 insertions, 38 deletions
diff --git a/routers/repo/release.go b/routers/repo/release.go index cc9864fe7a..591810cc5f 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -19,7 +19,7 @@ const ( ) func Releases(ctx *middleware.Context) { - ctx.Data["Title"] = "Releases" + ctx.Data["Title"] = ctx.Tr("repo.release.releases") ctx.Data["IsRepoToolbarReleases"] = true ctx.Data["IsRepoReleaseNew"] = false @@ -35,35 +35,13 @@ func Releases(ctx *middleware.Context) { return } - // Get default branch. - refName := ctx.Repo.Repository.DefaultBranch - if !ctx.Repo.GitRepo.IsBranchExist(refName) { - brs, err := ctx.Repo.GitRepo.GetBranches() - if err != nil { - ctx.Handle(500, "GetBranches", err) - return - } - refName = brs[0] - } - commit, err := ctx.Repo.GitRepo.GetCommitOfBranch(refName) - if err != nil { - ctx.Handle(500, "GetCommitOfBranch", err) - return - } - - commitsCount, err := commit.CommitsCount() - if err != nil { - ctx.Handle(500, "CommitsCount", err) - return - } - // Temproray cache commits count of used branches to speed up. countCache := make(map[string]int) tags := make([]*models.Release, len(rawTags)) for i, rawTag := range rawTags { - for _, rel := range rels { - if rel.IsDraft && !ctx.Repo.IsOwner { + for j, rel := range rels { + if rel == nil || (rel.IsDraft && !ctx.Repo.IsOwner) { continue } if rel.TagName == rawTag { @@ -72,6 +50,7 @@ func Releases(ctx *middleware.Context) { ctx.Handle(500, "GetUserById", err) return } + // FIXME: duplicated code. // Get corresponding target if it's not the current branch. if ctx.Repo.BranchName != rel.Target { // Get count if not exists. @@ -89,11 +68,12 @@ func Releases(ctx *middleware.Context) { } rel.NumCommitsBehind = countCache[ctx.Repo.BranchName] - rel.NumCommits } else { - rel.NumCommitsBehind = commitsCount - rel.NumCommits + rel.NumCommitsBehind = ctx.Repo.CommitsCount - rel.NumCommits } rel.Note = base.RenderMarkdownString(rel.Note, ctx.Repo.RepoLink) tags[i] = rel + rels[j] = nil // Mark as used. break } } @@ -116,8 +96,43 @@ func Releases(ctx *middleware.Context) { ctx.Handle(500, "CommitsCount", err) return } - tags[i].NumCommitsBehind = commitsCount - tags[i].NumCommits + tags[i].NumCommitsBehind = ctx.Repo.CommitsCount - tags[i].NumCommits + } + } + + for _, rel := range rels { + if rel == nil { + continue + } + + rel.Publisher, err = models.GetUserById(rel.PublisherId) + if err != nil { + ctx.Handle(500, "GetUserById", err) + return + } + // FIXME: duplicated code. + // Get corresponding target if it's not the current branch. + if ctx.Repo.BranchName != rel.Target { + // Get count if not exists. + if _, ok := countCache[rel.Target]; !ok { + commit, err := ctx.Repo.GitRepo.GetCommitOfBranch(ctx.Repo.BranchName) + if err != nil { + ctx.Handle(500, "GetCommitOfBranch", err) + return + } + countCache[ctx.Repo.BranchName], err = commit.CommitsCount() + if err != nil { + ctx.Handle(500, "CommitsCount2", err) + return + } + } + rel.NumCommitsBehind = countCache[ctx.Repo.BranchName] - rel.NumCommits + } else { + rel.NumCommitsBehind = ctx.Repo.CommitsCount - rel.NumCommits } + + rel.Note = base.RenderMarkdownString(rel.Note, ctx.Repo.RepoLink) + tags = append(tags, rel) } models.SortReleases(tags) ctx.Data["Releases"] = tags @@ -130,7 +145,8 @@ func NewRelease(ctx *middleware.Context) { return } - ctx.Data["Title"] = "New Release" + ctx.Data["Title"] = ctx.Tr("repo.release.new_release") + ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch ctx.Data["IsRepoToolbarReleases"] = true ctx.Data["IsRepoReleaseNew"] = true ctx.HTML(200, RELEASE_NEW) @@ -142,7 +158,7 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) { return } - ctx.Data["Title"] = "New Release" + ctx.Data["Title"] = ctx.Tr("repo.release.new_release") ctx.Data["IsRepoToolbarReleases"] = true ctx.Data["IsRepoReleaseNew"] = true @@ -183,9 +199,9 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) { if err = models.CreateRelease(ctx.Repo.GitRepo, rel); err != nil { if err == models.ErrReleaseAlreadyExist { - ctx.RenderWithErr("Release with this tag name has already existed", "release/new", &form) + ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_already_exist"), RELEASE_NEW, &form) } else { - ctx.Handle(500, "release.ReleasesNewPost(IsReleaseExist)", err) + ctx.Handle(500, "CreateRelease", err) } return } @@ -204,15 +220,15 @@ func EditRelease(ctx *middleware.Context) { rel, err := models.GetRelease(ctx.Repo.Repository.Id, tagName) if err != nil { if err == models.ErrReleaseNotExist { - ctx.Handle(404, "release.ReleasesEdit(GetRelease)", err) + ctx.Handle(404, "GetRelease", err) } else { - ctx.Handle(500, "release.ReleasesEdit(GetRelease)", err) + ctx.Handle(500, "GetRelease", err) } return } ctx.Data["Release"] = rel - ctx.Data["Title"] = "Edit Release" + ctx.Data["Title"] = ctx.Tr("repo.release.edit_release") ctx.Data["IsRepoToolbarReleases"] = true ctx.HTML(200, RELEASE_EDIT) } @@ -227,9 +243,9 @@ func EditReleasePost(ctx *middleware.Context, form auth.EditReleaseForm) { rel, err := models.GetRelease(ctx.Repo.Repository.Id, tagName) if err != nil { if err == models.ErrReleaseNotExist { - ctx.Handle(404, "release.EditReleasePost(GetRelease)", err) + ctx.Handle(404, "GetRelease", err) } else { - ctx.Handle(500, "release.EditReleasePost(GetRelease)", err) + ctx.Handle(500, "GetRelease", err) } return } @@ -240,7 +256,7 @@ func EditReleasePost(ctx *middleware.Context, form auth.EditReleaseForm) { return } - ctx.Data["Title"] = "Edit Release" + ctx.Data["Title"] = ctx.Tr("repo.release.edit_release") ctx.Data["IsRepoToolbarReleases"] = true rel.Title = form.Title @@ -248,7 +264,7 @@ func EditReleasePost(ctx *middleware.Context, form auth.EditReleaseForm) { rel.IsDraft = len(form.Draft) > 0 rel.IsPrerelease = form.Prerelease if err = models.UpdateRelease(ctx.Repo.GitRepo, rel); err != nil { - ctx.Handle(500, "release.EditReleasePost(UpdateRelease)", err) + ctx.Handle(500, "UpdateRelease", err) return } ctx.Redirect(ctx.Repo.RepoLink + "/releases") |