Browse Source

repo/release: add pagination (#2164)

pull/4150/head
Unknwon 8 years ago
parent
commit
07801cbf09
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 2
      cmd/web.go
  2. 2
      gogs.go
  3. 73
      routers/repo/release.go
  4. 2
      templates/.VERSION
  5. 8
      templates/repo/release/list.tmpl
  6. 2
      vendor/github.com/gogits/git-module/git.go
  7. 90
      vendor/github.com/gogits/git-module/repo_tag.go
  8. 6
      vendor/vendor.json

2
cmd/web.go

@ -95,7 +95,7 @@ func checkVersion() {
{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"}, {"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"},
{"gopkg.in/ini.v1", ini.Version, "1.8.4"}, {"gopkg.in/ini.v1", ini.Version, "1.8.4"},
{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"}, {"gopkg.in/macaron.v1", macaron.Version, "1.1.7"},
{"github.com/gogits/git-module", git.Version, "0.4.9"}, {"github.com/gogits/git-module", git.Version, "0.4.10"},
{"github.com/gogits/go-gogs-client", gogs.Version, "0.12.1"}, {"github.com/gogits/go-gogs-client", gogs.Version, "0.12.1"},
} }
for _, c := range checkers { for _, c := range checkers {

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.154.0217" const APP_VER = "0.9.155.0217"
func init() { func init() {
setting.AppVer = APP_VER setting.AppVer = APP_VER

73
routers/repo/release.go

@ -53,7 +53,7 @@ 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() tagsResult, err := ctx.Repo.GitRepo.GetTagsAfter(ctx.Query("after"), 10)
if err != nil { if err != nil {
ctx.Handle(500, fmt.Sprintf("GetTags '%s'", ctx.Repo.Repository.RepoPath()), err) ctx.Handle(500, fmt.Sprintf("GetTags '%s'", ctx.Repo.Repository.RepoPath()), err)
return return
@ -68,33 +68,39 @@ func Releases(ctx *context.Context) {
// 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)
tags := make([]*models.Release, len(rawTags)) drafts := make([]*models.Release, 0, 1)
for i, rawTag := range rawTags { tags := make([]*models.Release, len(tagsResult.Tags))
for i, rawTag := range tagsResult.Tags {
for j, r := range releases { for j, r := range releases {
if r == nil || (r.IsDraft && !ctx.Repo.IsOwner()) { if r == nil || (r.IsDraft && !ctx.Repo.IsOwner()) {
continue continue
} }
if r.TagName == rawTag { releases[j] = nil // Mark as used.
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
}
}
if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil { r.Publisher, err = models.GetUserByID(r.PublisherID)
ctx.Handle(500, "calReleaseNumCommitsBehind", err) 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()) 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())
if r.TagName == rawTag {
tags[i] = r tags[i] = r
releases[j] = nil // Mark as used.
break break
} }
if r.IsDraft {
drafts = append(drafts, r)
}
} }
if tags[i] == nil { if tags[i] == nil {
@ -119,31 +125,18 @@ func Releases(ctx *context.Context) {
} }
} }
for _, r := range releases {
if r == nil {
continue
}
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
}
}
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)
}
models.SortReleases(tags) models.SortReleases(tags)
if len(drafts) > 0 && tagsResult.HasLatest {
tags = append(drafts, tags...)
}
ctx.Data["Releases"] = tags ctx.Data["Releases"] = tags
ctx.Data["HasPrevious"] = !tagsResult.HasLatest
ctx.Data["ReachEnd"] = tagsResult.ReachEnd
ctx.Data["PreviousAfter"] = tagsResult.PreviousAfter
if len(tags) > 0 {
ctx.Data["NextAfter"] = tags[len(tags)-1].TagName
}
ctx.HTML(200, RELEASES) ctx.HTML(200, RELEASES)
} }

2
templates/.VERSION

@ -1 +1 @@
0.9.154.0217 0.9.155.0217

8
templates/repo/release/list.tmpl

@ -75,6 +75,14 @@
</li> </li>
{{end}} {{end}}
</ul> </ul>
<div class="center">
<a class="ui small button {{if not .HasPrevious}}disabled{{end}}" {{if .HasPrevious}}href="{{$.Link}}?after={{.PreviousAfter}}"{{end}}>
{{$.i18n.Tr "repo.issues.previous"}}
</a>
<a class="ui small button {{if .ReachEnd}}disabled{{end}}" {{if not .ReachEnd}}href="{{$.Link}}?after={{.NextAfter}}"{{end}}>
{{$.i18n.Tr "repo.issues.next"}}
</a>
</div>
</div> </div>
</div> </div>
{{template "base/footer" .}} {{template "base/footer" .}}

2
vendor/github.com/gogits/git-module/git.go generated vendored

@ -10,7 +10,7 @@ import (
"time" "time"
) )
const _VERSION = "0.4.9" const _VERSION = "0.4.10"
func Version() string { func Version() string {
return _VERSION return _VERSION

90
vendor/github.com/gogits/git-module/repo_tag.go generated vendored

@ -5,6 +5,7 @@
package git package git
import ( import (
"fmt"
"strings" "strings"
"github.com/mcuadros/go-version" "github.com/mcuadros/go-version"
@ -110,7 +111,7 @@ func (repo *Repository) GetTags() ([]string, error) {
version.Sort(tags) version.Sort(tags)
// Reverse order // Reverse order
for i := 0; i < len(tags) / 2; i++ { for i := 0; i < len(tags)/2; i++ {
j := len(tags) - i - 1 j := len(tags) - i - 1
tags[i], tags[j] = tags[j], tags[i] tags[i], tags[j] = tags[j], tags[i]
} }
@ -119,13 +120,90 @@ func (repo *Repository) GetTags() ([]string, error) {
return tags, nil return tags, nil
} }
type TagsResult struct {
// Indicates whether results include the latest tag.
HasLatest bool
// If results do not include the latest tag, a indicator 'after' to go back.
PreviousAfter string
// Indicates whether results include the oldest tag.
ReachEnd bool
// List of returned tags.
Tags []string
}
// GetTagsAfter returns list of tags 'after' (exlusive) given tag.
func (repo *Repository) GetTagsAfter(after string, limit int) (*TagsResult, error) {
allTags, err := repo.GetTags()
if err != nil {
return nil, fmt.Errorf("GetTags: %v", err)
}
if limit < 0 {
limit = 0
}
numAllTags := len(allTags)
if len(after) == 0 && limit == 0 {
return &TagsResult{
HasLatest: true,
ReachEnd: true,
Tags: allTags,
}, nil
} else if len(after) == 0 && limit > 0 {
endIdx := limit
if limit >= numAllTags {
endIdx = numAllTags
}
return &TagsResult{
HasLatest: true,
ReachEnd: limit >= numAllTags,
Tags: allTags[:endIdx],
}, nil
}
previousAfter := ""
hasMatch := false
tags := make([]string, 0, len(allTags))
for i := range allTags {
if hasMatch {
tags = allTags[i:]
break
}
if allTags[i] == after {
hasMatch = true
if limit > 0 && i-limit > 0 {
previousAfter = allTags[i-limit]
}
continue
}
}
if !hasMatch {
tags = allTags
}
// If all tags after match is equal to the limit, it reaches the oldest tag as well.
if limit == 0 || len(tags) <= limit {
return &TagsResult{
HasLatest: !hasMatch,
PreviousAfter: previousAfter,
ReachEnd: true,
Tags: tags,
}, nil
}
return &TagsResult{
HasLatest: !hasMatch,
PreviousAfter: previousAfter,
Tags: tags[:limit],
}, nil
}
// DeleteTag deletes a tag from the repository // DeleteTag deletes a tag from the repository
func (repo *Repository) DeleteTag(name string) error { func (repo *Repository) DeleteTag(name string) error {
cmd := NewCommand("tag", "-d") cmd := NewCommand("tag", "-d")
cmd.AddArguments(name) cmd.AddArguments(name)
_, err := cmd.RunInDir(repo.Path) _, err := cmd.RunInDir(repo.Path)
return err return err
} }

6
vendor/vendor.json vendored

@ -159,10 +159,10 @@
"revisionTime": "2016-08-10T03:50:02Z" "revisionTime": "2016-08-10T03:50:02Z"
}, },
{ {
"checksumSHA1": "RSr3IvGo5PFxAP3ybtDcEojTWPI=", "checksumSHA1": "5SLknh130FbmnSNWkf6LtVFqdMI=",
"path": "github.com/gogits/git-module", "path": "github.com/gogits/git-module",
"revision": "41f3ca26f6b202c82d022a1062f7b7ea6339924b", "revision": "7c2ab580a5b25e8b045139a44635258ceef64ace",
"revisionTime": "2017-02-16T16:46:07Z" "revisionTime": "2017-02-17T22:39:06Z"
}, },
{ {
"checksumSHA1": "xvG+RgJODQqlmdAkHUQK2TyLR88=", "checksumSHA1": "xvG+RgJODQqlmdAkHUQK2TyLR88=",

Loading…
Cancel
Save