single.go 2.4 KB

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