diff options
author | Unknown <joe2010xtmf@163.com> | 2014-04-02 12:43:31 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-04-02 12:43:31 -0400 |
commit | db66b8da7227f7fd3ff9a8d7ccece0c3e31ea3d0 (patch) | |
tree | a48dc02ac1cb79ab18cb2837dccae10a503358f1 | |
parent | 97b133bbee77740bded5b4f2e7ad9896d6804cf7 (diff) | |
download | gitea-db66b8da7227f7fd3ff9a8d7ccece0c3e31ea3d0.tar.gz gitea-db66b8da7227f7fd3ff9a8d7ccece0c3e31ea3d0.zip |
Add release tmpl
-rw-r--r-- | models/git.go | 19 | ||||
-rw-r--r-- | models/repo.go | 1 | ||||
-rw-r--r-- | modules/middleware/repo.go | 1 | ||||
-rw-r--r-- | routers/repo/issue.go | 2 | ||||
-rw-r--r-- | routers/repo/release.go | 22 | ||||
-rw-r--r-- | templates/release/list.tmpl | 10 | ||||
-rw-r--r-- | templates/repo/toolbar.tmpl | 11 | ||||
-rw-r--r-- | web.go | 1 |
8 files changed, 59 insertions, 8 deletions
diff --git a/models/git.go b/models/git.go index d3bad6e0ce..46345d0ffc 100644 --- a/models/git.go +++ b/models/git.go @@ -56,6 +56,25 @@ func GetBranches(userName, repoName string) ([]string, error) { return brs, nil } +// GetTags returns all tags of given repository. +func GetTags(userName, repoName string) ([]string, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) + if err != nil { + return nil, err + } + + refs, err := repo.AllTags() + if err != nil { + return nil, err + } + + tags := make([]string, len(refs)) + for i, ref := range refs { + tags[i] = ref.Name + } + return tags, nil +} + func IsBranchExist(userName, repoName, branchName string) bool { repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { diff --git a/models/repo.go b/models/repo.go index 8dd7da23f1..e3270b1838 100644 --- a/models/repo.go +++ b/models/repo.go @@ -74,6 +74,7 @@ type Repository struct { NumStars int NumForks int NumIssues int + NumReleases int `xorm:"NOT NULL"` NumClosedIssues int NumOpenIssues int `xorm:"-"` IsPrivate bool diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index f446d6a85b..2139742c70 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -79,6 +79,7 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler { ctx.Handle(404, "RepoAssignment", err) return } + repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues ctx.Repo.Repository = repo ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 41b2c7e9b1..be92542641 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -74,7 +74,7 @@ func Issues(ctx *middleware.Context) { ctx.Data["Issues"] = showIssues ctx.Data["IssueCount"] = ctx.Repo.Repository.NumIssues - ctx.Data["OpenCount"] = ctx.Repo.Repository.NumIssues - ctx.Repo.Repository.NumClosedIssues + ctx.Data["OpenCount"] = ctx.Repo.Repository.NumOpenIssues ctx.Data["ClosedCount"] = ctx.Repo.Repository.NumClosedIssues ctx.Data["IssueCreatedCount"] = createdByCount ctx.Data["IsShowClosed"] = ctx.Query("state") == "closed" diff --git a/routers/repo/release.go b/routers/repo/release.go new file mode 100644 index 0000000000..8e8b93c9ea --- /dev/null +++ b/routers/repo/release.go @@ -0,0 +1,22 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package repo + +import ( + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/middleware" +) + +func Releases(ctx *middleware.Context) { + ctx.Data["Title"] = "Releases" + ctx.Data["IsRepoToolbarReleases"] = true + tags, err := models.GetTags(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + if err != nil { + ctx.Handle(404, "repo.Releases(GetTags)", err) + return + } + ctx.Data["Releases"] = tags + ctx.HTML(200, "release/list") +} diff --git a/templates/release/list.tmpl b/templates/release/list.tmpl new file mode 100644 index 0000000000..7d582e3ff8 --- /dev/null +++ b/templates/release/list.tmpl @@ -0,0 +1,10 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +<div id="body" class="container"> + {{range .Releases}} + {{.}} + {{end}} +</div> +{{template "base/footer" .}}
\ No newline at end of file diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index 6b48ecf506..08167ef82b 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -8,18 +8,15 @@ <li class="{{if .IsRepoToolbarCommits}}active{{end}}"><a href="{{.RepoLink}}/commits/{{if .BranchName}}{{.BranchName}}{{else}}master{{end}}">Commits</a></li> <!-- <li class="{{if .IsRepoToolbarBranches}}active{{end}}"><a href="{{.RepoLink}}/branches">Branches</a></li> --> <!-- <li class="{{if .IsRepoToolbarPulls}}active{{end}}"><a href="{{.RepoLink}}/pulls">Pull Requests</a></li> --> - <li class="{{if .IsRepoToolbarIssues}}active{{end}}"><a href="{{.RepoLink}}/issues">Issues <!--<span class="badge">42</span>--></a></li> + <li class="{{if .IsRepoToolbarIssues}}active{{end}}"><a href="{{.RepoLink}}/issues">{{if .Repository.NumOpenIssues}}<span class="badge">{{.Repository.NumOpenIssues}}</span> {{end}}Issues <!--<span class="badge">42</span>--></a></li> {{if .IsRepoToolbarIssues}} - <li class="tmp">{{if .IsRepoToolbarIssuesList}}<a href="{{.RepoLink}}/issues/new"> - <button class="btn btn-primary btn-sm">New Issue</button> - </a>{{else}}<a href="{{.RepoLink}}/issues"> - <button class="btn btn-primary btn-sm">Issues List</button> - </a>{{end}}</li> + <li class="tmp">{{if .IsRepoToolbarIssuesList}}<a href="{{.RepoLink}}/issues/new"><button class="btn btn-primary btn-sm">New Issue</button> + </a>{{else}}<a href="{{.RepoLink}}/issues"><button class="btn btn-primary btn-sm">Issues List</button></a>{{end}}</li> {{end}} + <li class="{{if .IsRepoToolbarReleases}}active{{end}}"><a href="{{.RepoLink}}/releases">{{if .Repository.NumReleases}}<span class="badge">{{.Repository.NumReleases}}</span> {{end}}Releases</a></li> <!-- <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">More <b class="caret"></b></a> <ul class="dropdown-menu"> - <li><a href="{{.RepoLink}}/release">Release</a></li> <li><a href="{{.RepoLink}}/wiki">Wiki</a></li> </ul> </li> -->{{end}} @@ -147,6 +147,7 @@ func runWeb(*cli.Context) { m.Group("/:username/:reponame", func(r martini.Router) { r.Get("/issues", repo.Issues) r.Get("/issues/:index", repo.ViewIssue) + r.Get("/releases", repo.Releases) r.Get("/pulls", repo.Pulls) r.Get("/branches", repo.Branches) }, ignSignIn, middleware.RepoAssignment(true)) |