single.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/slene/blackfriday"
  9. "github.com/gogits/gogs/models"
  10. "github.com/gogits/gogs/modules/middleware"
  11. )
  12. func Branches(ctx *middleware.Context, params martini.Params) {
  13. if !ctx.Repo.IsValid {
  14. return
  15. }
  16. ctx.Data["Username"] = params["username"]
  17. ctx.Data["Reponame"] = params["reponame"]
  18. brs, err := models.GetBranches(params["username"], params["reponame"])
  19. if err != nil {
  20. ctx.Handle(200, "repo.Branches", err)
  21. return
  22. }
  23. ctx.Data["Branches"] = brs
  24. ctx.Data["IsRepoToolbarBranches"] = true
  25. ctx.Render.HTML(200, "repo/branches", ctx.Data)
  26. }
  27. func Single(ctx *middleware.Context, params martini.Params) {
  28. if !ctx.Repo.IsValid {
  29. return
  30. }
  31. if params["branchname"] == "" {
  32. params["branchname"] = "master"
  33. }
  34. // Directory and file list.
  35. treename := params["_1"]
  36. files, err := models.GetReposFiles(params["username"], params["reponame"],
  37. params["branchname"], treename)
  38. if err != nil {
  39. ctx.Handle(200, "repo.Single", err)
  40. return
  41. }
  42. ctx.Data["Username"] = params["username"]
  43. ctx.Data["Reponame"] = params["reponame"]
  44. ctx.Data["Branchname"] = params["branchname"]
  45. // Branches.
  46. brs, err := models.GetBranches(params["username"], params["reponame"])
  47. if err != nil {
  48. ctx.Handle(200, "repo.Single", err)
  49. return
  50. }
  51. ctx.Data["Branches"] = brs
  52. var treenames []string
  53. Paths := make([]string, 0)
  54. if len(treename) > 0 {
  55. treenames = strings.Split(treename, "/")
  56. for i, _ := range treenames {
  57. Paths = append(Paths, strings.Join(treenames[0:i+1], "/"))
  58. }
  59. }
  60. // Latest commit.
  61. commit, err := models.GetLastestCommit(params["username"], params["reponame"])
  62. if err != nil {
  63. ctx.Handle(200, "repo.Single", err)
  64. return
  65. }
  66. ctx.Data["LatestCommit"] = commit
  67. // README.
  68. // for _, f := range files {
  69. // if f.Name == "README.md" {
  70. // ctx.Data["ReadmeName"] = "README.md"
  71. // ctx.Data["ReadmeContent"] =
  72. // break
  73. // }
  74. // }
  75. ctx.Data["Paths"] = Paths
  76. ctx.Data["Treenames"] = treenames
  77. ctx.Data["IsRepoToolbarSource"] = true
  78. ctx.Data["Files"] = files
  79. ctx.Render.HTML(200, "repo/single", ctx.Data)
  80. }
  81. func Setting(ctx *middleware.Context, params martini.Params) {
  82. if !ctx.Repo.IsOwner {
  83. ctx.Render.Error(404)
  84. return
  85. }
  86. var title string
  87. if t, ok := ctx.Data["Title"].(string); ok {
  88. title = t
  89. }
  90. ctx.Data["Title"] = title + " - settings"
  91. ctx.Data["IsRepoToolbarSetting"] = true
  92. ctx.Render.HTML(200, "repo/setting", ctx.Data)
  93. }
  94. func Commits(ctx *middleware.Context) string {
  95. return "This is commits page"
  96. }
  97. func Issues(ctx *middleware.Context) string {
  98. return "This is issues page"
  99. }
  100. func Pulls(ctx *middleware.Context) string {
  101. return "This is pulls page"
  102. }