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

85 lines
2.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  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. ctx.HTML(200, "repo/issues")
  27. }
  28. func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
  29. if !ctx.Repo.IsOwner {
  30. ctx.Handle(404, "issue.CreateIssue", nil)
  31. return
  32. }
  33. ctx.Data["Title"] = "Create issue"
  34. if ctx.Req.Method == "GET" {
  35. ctx.HTML(200, "issue/create")
  36. return
  37. }
  38. if ctx.HasError() {
  39. ctx.HTML(200, "issue/create")
  40. return
  41. }
  42. issue, err := models.CreateIssue(ctx.User.Id, form.RepoId, form.MilestoneId, form.AssigneeId,
  43. form.IssueName, form.Labels, form.Content, false)
  44. if err == nil {
  45. log.Trace("%s Issue created: %d", form.RepoId, issue.Id)
  46. ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index))
  47. return
  48. }
  49. ctx.Handle(200, "issue.CreateIssue", err)
  50. }
  51. func ViewIssue(ctx *middleware.Context, params martini.Params) {
  52. issueid, err := base.StrTo(params["issueid"]).Int()
  53. if err != nil {
  54. ctx.Handle(404, "issue.ViewIssue", err)
  55. return
  56. }
  57. issue, err := models.GetIssueById(int64(issueid))
  58. if err != nil {
  59. if err == models.ErrIssueNotExist {
  60. ctx.Handle(404, "issue.ViewIssue", err)
  61. } else {
  62. ctx.Handle(200, "issue.ViewIssue", err)
  63. }
  64. return
  65. }
  66. ctx.Data["Title"] = issue.Name
  67. ctx.Data["Issue"] = issue
  68. ctx.HTML(200, "issue/view")
  69. }