You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

single.go 3.8 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/git"
  9. "github.com/gogits/gogs/models"
  10. "github.com/gogits/gogs/modules/base"
  11. "github.com/gogits/gogs/modules/middleware"
  12. )
  13. func Branches(ctx *middleware.Context, params martini.Params) {
  14. if !ctx.Repo.IsValid {
  15. return
  16. }
  17. ctx.Data["Username"] = params["username"]
  18. ctx.Data["Reponame"] = params["reponame"]
  19. brs, err := models.GetBranches(params["username"], params["reponame"])
  20. if err != nil {
  21. ctx.Handle(200, "repo.Branches", err)
  22. return
  23. }
  24. ctx.Data["Branches"] = brs
  25. ctx.Data["IsRepoToolbarBranches"] = true
  26. ctx.Render.HTML(200, "repo/branches", ctx.Data)
  27. }
  28. func Single(ctx *middleware.Context, params martini.Params) {
  29. if !ctx.Repo.IsValid {
  30. return
  31. }
  32. if params["branchname"] == "" {
  33. params["branchname"] = "master"
  34. }
  35. // Get tree path
  36. treename := params["_1"]
  37. // Directory and file list.
  38. files, err := models.GetReposFiles(params["username"], params["reponame"],
  39. params["branchname"], treename)
  40. if err != nil {
  41. ctx.Handle(200, "repo.Single", err)
  42. return
  43. }
  44. ctx.Data["Username"] = params["username"]
  45. ctx.Data["Reponame"] = params["reponame"]
  46. ctx.Data["Branchname"] = params["branchname"]
  47. // Branches.
  48. brs, err := models.GetBranches(params["username"], params["reponame"])
  49. if err != nil {
  50. ctx.Handle(200, "repo.Single", err)
  51. return
  52. }
  53. ctx.Data["Branches"] = brs
  54. var treenames []string
  55. Paths := make([]string, 0)
  56. if len(treename) > 0 {
  57. treenames = strings.Split(treename, "/")
  58. for i, _ := range treenames {
  59. Paths = append(Paths, strings.Join(treenames[0:i+1], "/"))
  60. }
  61. }
  62. // Get latest commit according username and repo name
  63. commit, err := models.GetLastestCommit(params["username"], params["reponame"])
  64. if err != nil {
  65. ctx.Handle(200, "repo.Single", err)
  66. return
  67. }
  68. ctx.Data["LatestCommit"] = commit
  69. var readmeFile *models.RepoFile
  70. for _, f := range files {
  71. if !f.IsFile() || len(f.Name) < 6 {
  72. continue
  73. } else if strings.ToLower(f.Name[:6]) == "readme" {
  74. readmeFile = f
  75. break
  76. }
  77. }
  78. if readmeFile != nil {
  79. ctx.Data["ReadmeExist"] = true
  80. // if file large than 1M not show it
  81. if readmeFile.Size > 1024*1024 || readmeFile.Filemode != git.FileModeBlob {
  82. ctx.Data["FileIsLarge"] = true
  83. } else if blob, err := readmeFile.LookupBlob(); err != nil {
  84. ctx.Data["ReadmeExist"] = false
  85. } else {
  86. // current repo branch link
  87. urlPrefix := "http://" + base.Domain + "/" + ctx.Repo.Owner.LowerName + "/" +
  88. ctx.Repo.Repository.Name + "/blob/" + params["branchname"]
  89. ctx.Data["ReadmeContent"] = string(base.RenderMarkdown(blob.Contents(), urlPrefix))
  90. }
  91. }
  92. ctx.Data["Paths"] = Paths
  93. ctx.Data["Treenames"] = treenames
  94. ctx.Data["IsRepoToolbarSource"] = true
  95. ctx.Data["Files"] = files
  96. ctx.Render.HTML(200, "repo/single", ctx.Data)
  97. }
  98. func Setting(ctx *middleware.Context, params martini.Params) {
  99. if !ctx.Repo.IsOwner {
  100. ctx.Render.Error(404)
  101. return
  102. }
  103. var title string
  104. if t, ok := ctx.Data["Title"].(string); ok {
  105. title = t
  106. }
  107. ctx.Data["Title"] = title + " - settings"
  108. ctx.Data["IsRepoToolbarSetting"] = true
  109. ctx.Render.HTML(200, "repo/setting", ctx.Data)
  110. }
  111. func Commits(ctx *middleware.Context, params martini.Params) {
  112. ctx.Data["IsRepoToolbarCommits"] = true
  113. commits, err := models.GetCommits(params["username"],
  114. params["reponame"], params["branchname"])
  115. if err != nil {
  116. ctx.Render.Error(404)
  117. return
  118. }
  119. ctx.Data["Commits"] = commits
  120. ctx.Render.HTML(200, "repo/commits", ctx.Data)
  121. }
  122. func Issues(ctx *middleware.Context) string {
  123. return "This is issues page"
  124. }
  125. func Pulls(ctx *middleware.Context) string {
  126. return "This is pulls page"
  127. }