single.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "strings"
  7. "github.com/codegangsta/martini"
  8. "github.com/gogits/gogs/models"
  9. "github.com/gogits/gogs/modules/middleware"
  10. )
  11. func Branches(ctx *middleware.Context, params martini.Params) {
  12. if !ctx.Repo.IsValid {
  13. return
  14. }
  15. ctx.Data["Username"] = params["username"]
  16. ctx.Data["Reponame"] = params["reponame"]
  17. brs, err := models.GetBranches(params["username"], params["reponame"])
  18. if err != nil {
  19. ctx.Handle(200, "repo.Branches", err)
  20. return
  21. }
  22. ctx.Data["Branches"] = brs
  23. ctx.Data["IsRepoToolbarBranches"] = true
  24. ctx.Render.HTML(200, "repo/branches", ctx.Data)
  25. }
  26. func Single(ctx *middleware.Context, params martini.Params) {
  27. if !ctx.Repo.IsValid {
  28. return
  29. }
  30. if params["branchname"] == "" {
  31. params["branchname"] = "master"
  32. }
  33. treename := params["_1"]
  34. files, err := models.GetReposFiles(params["username"], params["reponame"],
  35. params["branchname"], treename)
  36. if err != nil {
  37. ctx.Handle(200, "repo.Single", err)
  38. return
  39. }
  40. ctx.Data["Username"] = params["username"]
  41. ctx.Data["Reponame"] = params["reponame"]
  42. ctx.Data["Branchname"] = params["branchname"]
  43. brs, err := models.GetBranches(params["username"], params["reponame"])
  44. if err != nil {
  45. ctx.Handle(200, "repo.Single", err)
  46. return
  47. }
  48. ctx.Data["Branches"] = brs
  49. var treenames []string
  50. Paths := make([]string, 0)
  51. if len(treename) > 0 {
  52. treenames = strings.Split(treename, "/")
  53. for i, _ := range treenames {
  54. Paths = append(Paths, strings.Join(treenames[0:i+1], "/"))
  55. }
  56. }
  57. commit, err := models.GetLastestCommit(params["username"], params["reponame"])
  58. if err != nil {
  59. ctx.Handle(200, "repo.Single", err)
  60. return
  61. }
  62. ctx.Data["LatestCommit"] = commit
  63. ctx.Data["Paths"] = Paths
  64. ctx.Data["Treenames"] = treenames
  65. ctx.Data["IsRepoToolbarSource"] = true
  66. ctx.Data["Files"] = files
  67. ctx.Render.HTML(200, "repo/single", ctx.Data)
  68. }
  69. func Setting(ctx *middleware.Context, params martini.Params) {
  70. if !ctx.Repo.IsOwner {
  71. ctx.Render.Error(404)
  72. return
  73. }
  74. var title string
  75. if t, ok := ctx.Data["Title"].(string); ok {
  76. title = t
  77. }
  78. ctx.Data["Title"] = title + " - settings"
  79. ctx.Data["IsRepoToolbarSetting"] = true
  80. ctx.Render.HTML(200, "repo/setting", ctx.Data)
  81. }
  82. func Commits(ctx *middleware.Context) string {
  83. return "This is commits page"
  84. }
  85. func Issues(ctx *middleware.Context) string {
  86. return "This is issues page"
  87. }
  88. func Pulls(ctx *middleware.Context) string {
  89. return "This is pulls page"
  90. }