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.

issue.go 3.2 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. "fmt"
  7. "github.com/codegangsta/martini"
  8. "github.com/gogits/gogs/models"
  9. "github.com/gogits/gogs/modules/auth"
  10. "github.com/gogits/gogs/modules/base"
  11. "github.com/gogits/gogs/modules/log"
  12. "github.com/gogits/gogs/modules/middleware"
  13. )
  14. func Issues(ctx *middleware.Context, params martini.Params) {
  15. ctx.Data["Title"] = "Issues"
  16. ctx.Data["IsRepoToolbarIssues"] = true
  17. milestoneId, _ := base.StrTo(params["milestone"]).Int()
  18. page, _ := base.StrTo(params["page"]).Int()
  19. var err error
  20. ctx.Data["Issues"], err = models.GetIssues(0, ctx.Repo.Repository.Id, 0,
  21. int64(milestoneId), page, params["state"] == "closed", false, params["labels"], params["sortType"])
  22. if err != nil {
  23. ctx.Handle(200, "issue.Issues: %v", err)
  24. return
  25. }
  26. if len(params["branchname"]) == 0 {
  27. params["branchname"] = "master"
  28. }
  29. ctx.Data["Branchname"] = params["branchname"]
  30. ctx.HTML(200, "repo/issues")
  31. }
  32. func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
  33. if !ctx.Repo.IsOwner {
  34. ctx.Handle(404, "issue.CreateIssue", nil)
  35. return
  36. }
  37. ctx.Data["Title"] = "Create issue"
  38. if ctx.Req.Method == "GET" {
  39. ctx.HTML(200, "issue/create")
  40. return
  41. }
  42. if ctx.HasError() {
  43. ctx.HTML(200, "issue/create")
  44. return
  45. }
  46. issue, err := models.CreateIssue(ctx.User.Id, form.RepoId, form.MilestoneId, form.AssigneeId,
  47. form.IssueName, form.Labels, form.Content, false)
  48. if err == nil {
  49. log.Trace("%s Issue created: %d", form.RepoId, issue.Id)
  50. ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index))
  51. return
  52. }
  53. ctx.Handle(200, "issue.CreateIssue", err)
  54. }
  55. func ViewIssue(ctx *middleware.Context, params martini.Params) {
  56. index, err := base.StrTo(params["index"]).Int()
  57. if err != nil {
  58. ctx.Handle(404, "issue.ViewIssue", err)
  59. return
  60. }
  61. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, int64(index))
  62. if err != nil {
  63. if err == models.ErrIssueNotExist {
  64. ctx.Handle(404, "issue.ViewIssue", err)
  65. } else {
  66. ctx.Handle(200, "issue.ViewIssue", err)
  67. }
  68. return
  69. }
  70. ctx.Data["Title"] = issue.Name
  71. ctx.Data["Issue"] = issue
  72. ctx.HTML(200, "issue/view")
  73. }
  74. func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
  75. if !ctx.Repo.IsOwner {
  76. ctx.Handle(404, "issue.UpdateIssue", nil)
  77. return
  78. }
  79. index, err := base.StrTo(params["index"]).Int()
  80. if err != nil {
  81. ctx.Handle(404, "issue.UpdateIssue", err)
  82. return
  83. }
  84. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, int64(index))
  85. if err != nil {
  86. if err == models.ErrIssueNotExist {
  87. ctx.Handle(404, "issue.UpdateIssue", err)
  88. } else {
  89. ctx.Handle(200, "issue.UpdateIssue", err)
  90. }
  91. return
  92. }
  93. issue.Name = form.IssueName
  94. issue.MilestoneId = form.MilestoneId
  95. issue.AssigneeId = form.AssigneeId
  96. issue.Labels = form.Labels
  97. issue.Content = form.Content
  98. if err = models.UpdateIssue(issue); err != nil {
  99. ctx.Handle(200, "issue.UpdateIssue", err)
  100. return
  101. }
  102. ctx.Data["Title"] = issue.Name
  103. ctx.Data["Issue"] = issue
  104. }