From db66b8da7227f7fd3ff9a8d7ccece0c3e31ea3d0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 2 Apr 2014 12:43:31 -0400 Subject: [PATCH] Add release tmpl --- models/git.go | 19 +++++++++++++++++++ models/repo.go | 1 + modules/middleware/repo.go | 1 + routers/repo/issue.go | 2 +- routers/repo/release.go | 22 ++++++++++++++++++++++ templates/release/list.tmpl | 10 ++++++++++ templates/repo/toolbar.tmpl | 11 ++++------- web.go | 1 + 8 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 routers/repo/release.go create mode 100644 templates/release/list.tmpl 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" .}} +
+ {{range .Releases}} + {{.}} + {{end}} +
+{{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 @@
  • Commits
  • -
  • Issues
  • +
  • {{if .Repository.NumOpenIssues}}{{.Repository.NumOpenIssues}} {{end}}Issues
  • {{if .IsRepoToolbarIssues}} -
  • {{if .IsRepoToolbarIssuesList}} - - {{else}} - - {{end}}
  • +
  • {{if .IsRepoToolbarIssuesList}} + {{else}}{{end}}
  • {{end}} +
  • {{if .Repository.NumReleases}}{{.Repository.NumReleases}} {{end}}Releases
  • {{end}} diff --git a/web.go b/web.go index ececd6c2b3..5fc3350f1f 100644 --- a/web.go +++ b/web.go @@ -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))